[Aboriginal] Fun with TLS [was requires approval]

Rob Landley rob at landley.net
Mon Nov 3 14:07:40 PST 2014



On 11/03/14 03:14, David Halls wrote:
> On 3 November 2014 07:18, David Halls <dahalls at gmail.com
> <mailto:dahalls at gmail.com>> wrote:
> 
>     Sure:
> 
>     (x86_64:1) /home/source/go/src # cat test.c
>     __thread int foo;
> 
>     int main(int argc, char**argv)
>     {
>     }
>
>     (x86_64:1) /home/source/go/src # gcc test.c
>     (x86_64:1) /home/source/go/src # ./a.out

I built that with simple-cross-compiler-i686 and
simple-cross-compiler-x86 (building --static each time) and nothing
happened.

However, when I change it to:

#include <stdio.h>

__thread int foo;

int main(int argc, char**argv) { printf("%d\n", foo);}


The result segfaulted on x86-64. (Printed 0 on i686.)

>     On 1 November 2014 23:54, Rob Landley <rob at landley.net
>     <mailto:rob at landley.net>> wrote:
> 
>         On 11/01/14 17:03, David Halls wrote:
>         > Thanks Rob.
>         >
>         > Regarding the TLS problem, I added:
>         >
>         >     UCLIBC_HAS_TLS=y
>         >
>         > to baseconfig-uClibc but am still getting:
>         >
>         >     Program uses unsupported TLS data!

You're building with the native compiler in the aboriginal image?

Ah, I see. Yup, works on i686, gives me the message on x86-64.

>         > It seems the code in ldso.c which does this checks for
>         USE_TLS, which
>         > should be set because native threads are configured, right?
> 
>         Ah, the old "has" vs "use" nonsense uClibc kept doing:
> 
>         http://lists.uclibc.org/pipermail/uclibc/2009-July/042818.html
> 
>         Is there a reasonably small tls test program I can use to check
>         if I've
>         enabled it right? I can take another crack at it, but don't
>         currently
>         know what success looks like so can't tell when I've done it.
> 
>         Rob
> 
> 
> 
> If I remove this line from sources/targets/x86_64:
> 
> LINUXTHREADS_OLD=y
> 
> then ntpl tries to build but I get:
> 
> /home/david/Downloads/aboriginal-1.2.9/build/simple-cross-compiler-x86_64/lib/../x86_64-unknown-linux/bin/ld:
> libpthread/nptl/libpthread_so.a(pthread_once.oS): relocation
> R_X86_64_PC32 against `__fork_generation' can not be used when making a
> shared object; recompile with -fPIC
> /home/david/Downloads/aboriginal-1.2.9/build/simple-cross-compiler-x86_64/lib/../x86_64-unknown-linux/bin/ld:
> final link failed: Bad value
> collect2: ld returned 1 exit status
> libpthread/nptl/Makefile.in:78: recipe for target 'lib/libpthread.so' failed
> make: *** [lib/libpthread.so] Error 1

Sigh. I very vaguely recall that...

Ah: http://landley.net/hg/aboriginal/rev/1522

Ok, yeah, I left a thing I need to fix. :)

Rob

 1415052460.0


More information about the Aboriginal mailing list