This is the mail archive of the mailing list for the binutils 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: Question on scope of class member static variable

On Thu, May 8, 2014 at 8:51 PM, Jing Yu <> wrote:
> Hi binutils@,
> I have a piece of code which behave differently on x86 and aarch64.
> The scenario is that both executable and shared library define a TLS
> class member static variable.
> On aarch64, the executable exports the symbol in dynamic symbol stable
> with GLOBAL attribute. When shared library is dlopened, dynamic loader
> finds the symbol in executable's symbol table and binds with it. Thus
> both dynamic library and executable share the same copy of this
> variable.
> On x86, executable does not export this symbol. Dynamic loader binds
> shared library with its own copy of the variable. Thus the executable
> and shared library operates on separate copy of the variable.
> My question is whether a class member static variable is accessible by
> external shared library. In my code, which behavior (x86 or aarch64)
> is correct.

I believe x86 has the correct behavior on Linux.   By default,
Linux linker doesn't make global symbols in executable dynamic
unless it is referenced by a shared library. You can use the linker
switch --export-dynamic or --dynamic-list to change it.


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