On Tue, 9 Sep 2025, H.J. Lu wrote:

> > > to restore assert if not compiling for shared library.  When compiling
> > > for shared library, the recomputed model may be weaker.
> >
> > I don't understand why (for shared libraries), can you explain?
> 
> Another shared library or executable may override any global
> symbols with the default visibility in a shared library.

I know that symbols with default visibility can be interposed, but that doesn't
answer the question. Do you have a testcase that demonstrates the issue?
Otherwise, let's say we are talking about

extern __thread int tls_undef;
static __thread int tls_local;
/****/ __thread int tls_global;

With -fpic GCC initially selects local-dynamic for tls_local, global-dynamic
for tls_undef and tls_global. Why would recomputed model for tls_local be 
weaker?

> __thread int x;
> 
> __attribute__((common))
> __thread int x;
> 
> int *f()
> {
>     return &x;
> }
> [hjl@gnu-zen4-1 gcc]$ ./xgcc -B./ -O2 -std=c11 -fno-common -S /tmp/x.c
>  -fdump-ipa-whole-program
> [hjl@gnu-zen4-1 gcc]$ cat x.c.084i.whole-program
> 
> Marking local functions:
> 
> 
> Marking externally visible functions: f/3
> 
> 
> Marking externally visible variables: x/1
> 
> Clearing variable flags:
> 
> Reclaiming functions:
> Reclaiming variables:
> Clearing address taken flags:
> Symbol table:
> 
> f/3 (f)
>   Type: function definition analyzed
>   Visibility: externally_visible semantic_interposition public
>   References: x/1 (addr)
>   Referring:
>   Availability: available
>   Function flags: count:1073741824 (estimated locally) body
>   Called by:
>   Calls:
> x/1 (x)
>   Type: variable definition analyzed
>   Visibility: externally_visible semantic_interposition public common
>   References:
>   Referring: f/3 (addr)
>   Availability: overwritable
>   Varpool flags: tls-local-exec

Thanks. Unrelated to this particular patch, but this is questionable: we have
local-exec for an interposable (Availability: overwritable) symbol. Perhaps
it's better to error out on the redeclaration, when the previous declaration
set a stronger TLS model?

Alexander

Reply via email to