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: Global variables and shared libraries


On 28 November 2012 11:11, Bharath Ramesh <bramesh@vt.edu> wrote:
> I want to export a global variable that has been defined in a
> shared library to the binary that links with it. The most common
> approach would be to declare the global variable as an extern
> variable in the application code. This approach would make the
> actual reference to the global variable be present in the data
> segment of the binary. My use case would require that the

No it wouldn't, unless the binary is statically linked.  It comes up
as an undefined symbol in the binary and it is resolved at runtime by
the dynamic linker.  You can see this by doing an `objdump -x` on the
generated binary.  The global variable is defined in the data section
of the DSO binary.

> segment after linking. I was thinking some what in the way errno
> is linked, but I believe it ends up as a function call eventually
> so that appropriate address can be dereferenced, please do
> correct me if I am wrong. I do not want to access the variable

errno is a thread-local variable and __errno_location returns the
value from the TLS variable, which is defined in the .tbss section in
libc.so.

> using get/set calls either. If this is not the appropriate forum
> for this question, I would greatly appreciate it if you could
> point me in the direction of a more suitable forum as well.

This is the right forum for this question.


Siddhesh

-- 
http://siddhesh.in


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