https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85400

            Bug ID: 85400
           Summary: R_SPARC_TLS_*: invalid relocations generated for
                    optimized builds on sparc
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: phantall at gmail dot com
  Target Milestone: ---

In Solaris 10 & 11 using GCC versions 4.8, 4.9.2, 7.2.0 I get relocation errors
when thread_local variables are used in a struct/class.  Example code that
reproduces the problem:

> struct Test {
>   int blah( int y ) {
>     thread_local mything = 3;
>     mything = y > 0 ? y : mything;
>     return mything;
>   }
> };
> int stuff( Test& test, int y ) {
>   return test.blah(y);
> }

When compiled:

> $ g++ -m32 -fPIC -std=gnu++14 blah.cc -c -o blah1.o
> $ g++ -m32 -fPIC -std=gnu++14 blah.cc -c -o blah2.o -O3
> $ objdump -xC blah1.o | grep mything
> (...)
> 00000038 R_SPARC_TLS_GD_HI22  Test::blah(int)::mything
> 0000003c R_SPARC_TLS_GD_LO10  Test::blah(int)::mything
> (...)
> $ objdump -xC blah2.o | grep mything
> (...)
> 00000014 R_SPARC_TLS_LDM_HI22  Test::blah(int)::mything
> 0000001c R_SPARC_TLS_LDO_HIX22  Test::blah(int)::mything
> 00000020 R_SPARC_TLS_LDM_LO10  Test::blah(int)::mything
> 00000024 R_SPARC_TLS_LDO_LOX10  Test::blah(int)::mything
> (...)
> $ g++ -m32 -fPIC -shared blah2.o -o libblah.so
> ld: fatal: relocation error: R_SPARC_TLS_LDM_HI22: file blah2.o: symbol: 
> _ZZN4Test4blahEiE7mything: bound to: blah.o: relocation illegal when not 
> bound to object being created
> ld: fatal: relocation error: R_SPARC_TLS_LDM_HIX22: file blah2.o: symbol: 
> _ZZN4Test4blahEiE7mything: bound to: blah.o: relocation illegal when not 
> bound to object being created
> ...


For reference:

* It happens at all optimization levels above -O0 and for all combinations of
-std={c,gnu}++{11,14}
* This was discovered while building boost 1.66.0 with -std=gnu++14.  The error
occurs while linking libboost_fiber.so and comes from work_stealing.cpp for
boost::fibers::detail::spinlock_ttas::lock()::generator ... where "generator"
in that code is a static thread_local at member-function scope.
* The compilers I built and those produced by OpenCSW use the Solaris assembler
(/usr/ccs/bin/as) instead of gas.

Reply via email to