[FFmpeg-devel] Question about -fPIC usage for some files

Michael Niedermayer michaelni
Fri Feb 8 22:26:39 CET 2008

On Fri, Feb 08, 2008 at 01:03:56PM -0800, Trent Piepho wrote:
> On Fri, 8 Feb 2008, Thorsten Jordan wrote:
> > > Why does it fail with pic for you?
> > the same problem that was discussed several times on this list, gcc
> > fails to generate the code because it runs out of registers (ebx is used
> > with -fPIC):
> Since version 3 something, gcc can use other registers besides ebx, and
> might not use ebx at all if the function doesn't do anything that requires
> access to the pic pointer.  If a function accesses no globals, does not
> take the address of a fuction, or call a function in another shared
> library, it shouldn't need to load the pic register.
> The real problem isn't ebx, it's accessing globals.  In non-PIC code, a
> memory reference to a global takes zero registers.  In PIC code, it takes
> one register.  In some cases multiple global references can share the same
> register(s), so gcc doesn't always need one per global.  But this could
> still easily add a half dozen extra registers to an asm block.

Lets look at the actual code that fails:
 :"+&r"(i), "=m"(autoc[j]), "=m"(autoc[j+1]), "=m"(autoc[j+2])
 :"r"(data1+len), "r"(data1+len-j), "m"(*ff_pd_1)

needs 1 register

"=m"(autoc[j]), "=m"(autoc[j+1]), "=m"(autoc[j+2])
needs 1 register (%%eax) 8(%%eax) 16(%%eax) for example

needs 1 register

needs 1 register

is a global, and in PIC mode as you say might need 1 register, lets
give it one

now count 1+1+1+1+1 = 5
5 is less than 8

and that is full PIC mode with all the unneeded indirection over the GOT
why does it fail with gcc?

and now lets give the "=m"(autoc[j]), "=m"(autoc[j+1]), "=m"(autoc[j+2])
3 registers instead of one (which is too much for gcc)

1+3+1+1+1 = 7
7 is less than 8

Why does it fail?
This is not a compiler being presented with a situation too complex to solve
This is a compiler failing to fit a grain of sand in a bus.

Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080208/8ebd86c4/attachment.pgp>

More information about the ffmpeg-devel mailing list