This is the mail archive of the
mailing list for the binutils project.
Re: Question on scope of class member static variable
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Jing Yu <jingyu at google dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Fri, 9 May 2014 08:36:17 -0700
- Subject: Re: Question on scope of class member static variable
- Authentication-results: sourceware.org; auth=none
- References: <CAJ_rGWRmBBtyNXdzT9SGQ=MVUc5ZGhGdxkd3ORCNBwSVUv9uxw at mail dot gmail dot com>
On Thu, May 8, 2014 at 8:51 PM, Jing Yu <email@example.com> 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
> 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.