[Ffmpeg-devel] [PATCH] Make use of GCC's __PIC__ definition when available

Måns Rullgård mru
Sat Jul 1 16:36:34 CEST 2006


Diego 'Flameeyes' Petten? <flameeyes at gentoo.org> writes:

> The attached patch is the patch version of something that we already do in a 
> different way in Gentoo with ffmpeg and other software that uses ffmpeg, 
> cleaned up to be suitable for a general use.
>
> Basically, instead of relying on -DPIC to know when PIC code is built, it 
> relies when possible on the __PIC__ definition by the compiler (GCC defines 
> it when building PIC code).
> The reason for this is that there are cases in which GCC compiles PIC code 
> even if -fPIC is not used directly, for instance when building PIE (position 
> independent executables) often uses for hardened systems.
>
> Basically in configure it's checked if -fPIC enable the __PIC__
> symbol, if it does not, it's injected via CFLAGS exactly as before;
> if it is, just -fPIC is used to build PIC libraries, the code is
> then changed to check for __PIC__ instead of the definition of PIC
> (it can be done, every compiler defining __PIC__ defines it to 1,
> and the commandline defines it to 1 too the way I made it).
>
> Functional changes: none, a part that now ffmpeg builds correct code for 
> hardened systems.

> diff --git a/configure b/configure
> index db94c14..fbeddbd 100755
> --- a/configure
> +++ b/configure
> @@ -452,7 +452,7 @@ case $targetos in
>  BeOS)
>  prefix="/boot/home/config"
>  # helps building libavcodec
> -CFLAGS="$CFLAGS -DPIC -fomit-frame-pointer"
> +CFLAGS="$CFLAGS -D__PIC__=1 -fomit-frame-pointer"

This looks wrong.  What's that -DPIC doing there at all?

> +# Check if the compiler already defines __PIC__ when building PIC code
> +check_cc -fPIC <<EOF
> +    #ifndef __PIC__
> +    #  error "__PIC__ was not defined"
> +    #endif
> +EOF
> +if test $? != 0; then
> +    PIC_FLAGS="-fPIC -D__PIC__=1"
> +else
> +    PIC_FLAGS="-fPIC"
> +fi

You should include a dummy variable or function definition in case the
compiler doesn't like empty input files.

> -#ifndef PIC
> +#if ! __PIC__

This generates a warning if __PIC__ is undefined, although I think it
is allowed by C99.

-- 
M?ns Rullg?rd
mru at inprovide.com




More information about the ffmpeg-devel mailing list