Global variables and shared libraries

Carlos O'Donell carlos@systemhalted.org
Wed Nov 28 15:02:00 GMT 2012


On Wed, Nov 28, 2012 at 9:57 AM, Godmar Back <godmar@gmail.com> wrote:
> You're compiling your code without -fPIC. Consequently, the variable
> 'foo' is treated as a global variable, which is addressed using 32-bit
> relative to %rip.  It must thus be in the lower address range as per
> the x86_64 'small' model (so that's it no more than 4GB away from the
> %rip). That's why it's added to the bss section of the executable, and
> that's why a R_X86_64_COPY relocation entry appears in the libfoo.so
> file.
>
> See info gcc and look for -mcmodel=small

For those who wish to read more about COPY relocations...

"Copy Relocations"
http://docs.oracle.com/cd/E19082-01/819-0690/chapter4-84604/index.html



More information about the Libc-help mailing list