This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Finding the source code for ___tls_get_addr_internal()
Hi,
I'm using a GNU/Linux on an Intel 32bit x86.
I think that I might be digging too deep. There shouldn't be any
problem with the gs segment or whatever it points to.
The application is a C program that dynamically loads (using dlopen())
C++ libraries.
Do I need to set -ftls-model=global-dynamic when compiling the various
C++ libraries so TLS works correctly?
(gdb) disas __cxa_get_globals
Dump of assembler code for function __cxa_get_globals:
0xf6f536d0 <__cxa_get_globals+0>: push %ebp
0xf6f536d1 <__cxa_get_globals+1>: mov %esp,%ebp
0xf6f536d3 <__cxa_get_globals+3>: push %ebx
0xf6f536d4 <__cxa_get_globals+4>: call 0xf6ee8f07 <pthread_join+247>
0xf6f536d9 <__cxa_get_globals+9>: add $0x3591b,%ebx
0xf6f536df <__cxa_get_globals+15>: lea -0x56c(,%ebx,1),%eax
0xf6f536e6 <__cxa_get_globals+22>: call 0xf6ee7730 <___tls_get_addr@plt>
0xf6f536eb <__cxa_get_globals+27>: pop %ebx
0xf6f536ec <__cxa_get_globals+28>: pop %ebp
0xf6f536ed <__cxa_get_globals+29>: ret
Now in order to get eax's value before the call to ___tls_get_attr() I do:
0xf6f536d9 + 0x3591b = 0xf6f88ff4
0xf6f88ff4 - 0x56c = 0xf6f88a88
Can this value help me locate which tls value is accessed here? Can I
find it with readelf or objdump?
Thanks,
Saul
On Wed, Jan 16, 2013 at 5:59 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Wed, Jan 16, 2013 at 12:08 PM, Saul Tamari <stamari@gmail.com> wrote:
>>
>> Is ___tls_get_addr_internal() compiled from C source code or is it
>> generated directly in assembly code?
>> Where can I find the C source code that was used to generate
>> ___tls_get_addr_internal ?
>
> __tls_get_addr is provided by your C library. I don't think you
> mentioned what system you are using, but if it is a GNU/Linux system
> then __tls_get_addr defined by glibc. I'm not sure quite where
> __tls_get_addr_internal comes in. __tls_get_addr is defined in
> elf/dl-tls.c in the glibc sources. You seem to be using 32-bit x86;
> the interesting 32-bit x86 code is in nptl/sysdeps/i386/tls.h.
>
> It does indeed use %gs. You can't change %gs yourself if your program
> uses TLS variables.
>
> Ian