This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How do values get into the %gs:0x0 location?


Hi Amittai,

> Thanks a lot, Eduardo!

You're welcome! I've been studying these things, so I will tell you
what I know (or what I think I know :-). I hope someone else here with
more experience can help us both.

> But how does the linker get
> the information about which objects to put into the first TLS area at
> startup?

The ELF file has a segment whose type is PT_TLS (You might find useful
to read the chapter 9 of the book "Self-Service Linux: Mastering the
Art of Problem Determination", since it shows how the content of the
ELF file is organized). This segment holds the initial image that the
linker (and the thread library) uses to initiate the thread-local
data. For instance, if you have a static variable with an initial
value, this value is there in this image with a specific offset from
the beginning of the TLS.

> In particular, I know that my program has to store pointers to at
> least three locale-related objects -- _nl_C_LC_CTYPE, _nl_C_LC_MONETARY, and
> _nl_C_LC_NUMERIC. ?So I have a couple of questions about that --

These objects are related to locale specific data, I suppose.

> The compiler knows the offsets within the TLS section (for the startup
> thread) for those objects, since it refers to them by offset from %gs:0x0.
> ?But where does it get those offsets? ?The compiler must build a table at
> compile time mapping locale objects (and perhaps other objects needed at
> startup) to offsets, or else there must already be a table somewhere that
> maps such objects to standard offsets.

As far as I can tell, the compiler has a type of table with the
offsets to each TLS variable. So, these offsets are established during
compiler time and are fixed. They are not like the GOT.

> The linker knows the actual virtual addresses of the needed objects, but how
> does it know which objects are needed? ?Let's assume static linkage -- which
> is what I am using. ?How does the linker know which addresses to have the
> system store at the offsets known at compile time?

Hum... I think I didn't understand what you mean.

> Although I found Ulrich Drepper's paper "ELF Handling for Thread-Local
> Storage" helpful for understanding the general organization and handling of
> the TLS section, I couldn't find the answers to my questions there. ?Did I
> miss something?

Probably you can find a lot answers there. However, I think reading
that paper is a challenge.

Best regards,
Eduardo

P.S.:Hey, I am also a grad student, but from Brazil. Although I am now
at UIUC for a while.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]