Bug 11956

Summary: relocation truncated to fit R_MIPS_TLS_GD linking xulrunner
Product: binutils Reporter: Lluís Batlle <viric>
Component: ldAssignee: unassigned
Status: RESOLVED WONTFIX    
Severity: normal CC: bug-binutils, petr.pisar, r0bertz, rixed
Priority: P2    
Version: 2.21   
Target Milestone: ---   
Host: mips64-unknown-linux Target: mips64-unknown-linux
Build: mips64-unknown-linux Last reconfirmed:

Description Lluís Batlle 2010-08-30 07:37:36 UTC
Hello,

since some time ago (I think all 2.20 versions suffer from this problem too)
xulrunner from firefox 3.6.8 (and some older) don't link properly in mips.

This happens compiling for ABI n32.

r0bertz did some analysis about the problem already two or three months ago, in
the binutils mailing list. And we still have not found any solution:
http://old.nabble.com/R_MIPS_TLS_GD-reloc-overflow-when-linking->%3Dxulrunner-1.9.1.5-td26755056.html

The last binutils I tried was a snapshot from the 12th of August.

So here you have the symptom. When linking libxul.so, it reports:
../../staticlib/components/libxpconnect.a(xpcjsruntime.o): In function
`XPCJSRuntime::GCCallback(JSContext*, JSGCStatus)':
xpcjsruntime.cpp:(.text+0x1514): relocation truncated to fit: R_MIPS_TLS_GD
against `gTLSIsMainThread'
../../staticlib/components/libxpconnect.a(xpcthreadcontext.o): In function
`XPCPerThreadData::GetDataImpl(JSContext*)':
xpcthreadcontext.cpp:(.text+0x834): relocation truncated to fit: R_MIPS_TLS_GD
against `gTLSIsMainThread'
../../staticlib/components/libnecko.a(nsSocketTransportService2.o): In function
`nsSocketTransportService::Shutdown()':
nsSocketTransportService2.cpp:(.text+0x1890): relocation truncated to fit:
R_MIPS_TLS_GD against `gTLSIsMainThread'
../../staticlib/components/libnecko.a(nsSocketTransportService2.o): In function
`nsSocketTransportService::Init()':
nsSocketTransportService2.cpp:(.text+0x19e4): relocation truncated to fit:
R_MIPS_TLS_GD against `gTLSIsMainThread'
../../staticlib/components/libuconv.a(nsCharsetConverterManager.o): In function
`nsCharsetConverterManager::GetCharsetAlias(char const*, nsACString_internal&)':
nsCharsetConverterManager.cpp:(.text+0xa78): relocation truncated to fit:
R_MIPS_TLS_GD against `gTLSIsMainThread'
collect2: ld returned 1 exit status

The objects linked have a gcc command-line like this:
c++ -o nsRDFResource.o -c -fvisibility=hidden -DMOZ_ENABLE_GTK2 -DMOZ_PLUGINS
-DMOZ_XPFE_COMPONENTS -DMOZ_XPINSTALL -DMOZ_JSDEBUGGER -DMOZ_PREF_EXTENSIONS
-DMOZ_AUTH_EXTENSION -DMOZ_PERMISSIONS -DMOZ_UNIVERSALCHARDET -DMOZ_FILEVIEW
-DMOZ_ENABLE_POSTSCRIPT -DMOZ_SPELLCHECK -DMOZ_ZIPWRITER -DMOZILLA_INTERNAL_API
-DOSTYPE=\"Linux2.6.35\" -DOSARCH=Linux -D_IMPL_NS_COM -D_IMPL_NS_STRINGAPI
-DEXPORT_XPT_API -DEXPORT_XPTC_API -D_IMPL_NS_GFX -D_IMPL_NS_WIDGET
-DIMPL_XREAPI -I../../intl/unicharutil/util -I../../config
-I../../widget/src/windows -I../../widget/src/build  -I. -I.
-I../../dist/include -fPIC   -fno-rtti -fno-exceptions -Wall -Wpointer-arith
-Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor
-Wcast-align -Wno-invalid-offsetof -Wno-long-long -pedantic -fno-strict-aliasing
-fshort-wchar -pthread -pipe -DNDEBUG -DTRIMMED -Os -freorder-blocks
-fno-reorder-functions -DMOZILLA_CLIENT -include ../../mozilla-config.h
-Wp,-MD,.deps/nsRDFResource.pp nsRDFResource.cpp

The 'c++' linking command line mentions:
 -fno-rtti -fno-exceptions -Wall -Wpointer-arith -Woverloaded-virtual -Wsynth
-Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-invalid-offsetof
-Wno-long-long -pedantic -fno-strict-aliasing -fshort-wchar -pthread -pipe 
-DNDEBUG -DTRIMMED -Os -freorder-blocks -fno-reorder-functions  -fPIC -shared

Regards,
Lluís.
Comment 1 Lluís Batlle 2010-08-30 07:38:51 UTC
Additional information: I was using gcc 4.5.1, glibc 2.12.1, kernel headers from
2.6.32, all natively built.
gcc by default produces code for mips3 n32.
Comment 2 Lluís Batlle 2010-08-31 06:58:32 UTC
The problem may be related to a TLS variable exported in a shared object (in the
global-dynamic way).
The TLS variable is gTLSIsMainThread, and the errors from ld come for all the
places where it is used.

The upstream mozilla people decided to disallow TLS completely on mips due to
this binutils problem. More information here:
https://bugzilla.mozilla.org/show_bug.cgi?id=528687
Comment 3 ZHANG, Le 2010-09-04 20:28:09 UTC
http://sourceware.org/ml/binutils/2010-09/msg00042.htm

some new findings on the above link
Comment 4 ZHANG, Le 2010-09-05 18:14:34 UTC
sorry the link should be http://sourceware.org/ml/binutils/2010-09/msg00042.html
Comment 5 Jackie Rosen 2014-02-16 19:44:02 UTC Comment hidden (spam)
Comment 6 Alan Modra 2022-08-25 07:27:26 UTC
According to the analysis already done in comment #4, this is an overflow of the GOT table.  That can't be fixed except by changing code so either needs a lot of code editing by the linker (support which is unlikely to be written), or you need to generate different code in gcc.  -mxgot might help,