Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang boostrap fails at link time with TLS errors #32797

Closed Quuxplusone closed 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR33825
Status RESOLVED FIXED
Importance P normal
Reported by Fedor Sergeev (fedor.v.sergeev@gmail.com)
Reported on 2017-07-17 14:50:21 -0700
Last modified on 2017-07-25 12:56:19 -0700
Version trunk
Hardware Sun All
CC llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Attempt to (manually) bootstrap clang fails when trying to link tablegen:

[246/1342] Linking CXX executable bin/llvm-tblgen
FAILED: bin/llvm-tblgen
: && /export/home/fsergeev/LLVM/llvm-build/sparc-50/bin/clang++   -m64 -fPIC -
fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-
parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -
Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-
dtor -Wstring-conversion -fcolor-diagnostics -ffunction-sections -fdata-
sections -O3 -DNDEBUG  -m64  -Wl,-R/export/home/fsergeev/LLVM/llvm-build/sparc-
50/lib/sparcv9    -Wl,-z -Wl,discard-unused=sections
utils/TableGen/CMakeFiles/obj.llvm-tblgen.dir/AsmMatcherEmitter.cpp.o <...cut
some stuff here..>  -o bin/llvm-tblgen  lib/libLLVMSupport.a
lib/libLLVMTableGen.a lib/libLLVMSupport.a -lrt -ldl -lcurses -lz -lm
lib/libLLVMDemangle.a && :
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file
lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): symbol _ZL20PrettyStackTraceHead:
value 0x3fffffffc00001 does not fit

] elfdump -r  ./lib/Support/CMakeFiles/LLVMSupport.dir/PrettyStackTrace.cpp.o
| grep HIX22.*_ZL20PrettyStackTraceHead
    [4]  R_SPARC_TLS_LDO_HIX22    0x28 0x3fffff      0  .text._ZN4llvm _ZL20PrettyStackTraceHead
    [2]  R_SPARC_TLS_LDO_HIX22    0x24 0x3fffff      0  .text._ZN4llvm _ZL20PrettyStackTraceHead
    [2]  R_SPARC_TLS_LDO_HIX22    0x14 0x3fffff      0  .text._ZN4llvm _ZL20PrettyStackTraceHead
    [2]  R_SPARC_TLS_LDO_HIX22    0x14 0x3fffff      0  .text._ZN4llvm _ZL20PrettyStackTraceHead
    [4]  R_SPARC_TLS_LDO_HIX22    0x2c 0x3fffff      0  .text._ZN4llvm _ZL20PrettyStackTraceHead
    [4]  R_SPARC_TLS_LDO_HIX22    0x2c 0x3fffff      0  .text._ZN4llvm _ZL20PrettyStackTraceHead
    [4]  R_SPARC_TLS_LDO_HIX22    0x2c 0x3fffff      0  .text._ZN4llvm _ZL20PrettyStackTraceHead
    [7]  R_SPARC_TLS_LDO_HIX22    0x64 0x3fffff      0  .text._ZN4llvm _ZL20PrettyStackTraceHead
    [7]  R_SPARC_TLS_LDO_HIX22    0x64 0x3fffff      0  .text._ZN4llvm _ZL20PrettyStackTraceHead
    [3]  R_SPARC_TLS_LDO_HIX22    0x20 0x3fffff      0  .text._ZL12Cra _ZL20PrettyStackTraceHead

It appears that generation of TLS_LDO_HIX22 relocation for sparc is broken.

Reduced testcase:
] cat tls-hix.cc
static thread_local void* StackTraceHead = nullptr;

void* foo() {
  return StackTraceHead;
}

int main() {
  return !foo();
}
] bin/clang++ tls-hix.cc -std=c++11 -m64
ld: fatal: relocation error: R_SPARC_TLS_LE_HIX22: file /var/tmp/tls-hix-
548455.o: symbol _ZL14StackTraceHead: value 0x3fffffffc00001 does not fit
clang-5.0: error: linker command failed with exit code 1 (use -v to see
invocation)
]
Quuxplusone commented 7 years ago
For this code gcc generates:
] g++ tls-hix.cc -std=c++11 -m64 -c; elfdump -r tls-hix.o | grep TLS
    [0]  R_SPARC_TLS_LE_HIX22     0x4     0      0  .text   _ZL14StackTraceHead
    [1]  R_SPARC_TLS_LE_LOX10     0x8     0      0  .text   _ZL14StackTraceHead
]

And clang generates:
] bin/clang++ tls-hix.cc  -std=c++11 -m64 -c; elfdump -r tls-hix.o | grep TLS
    [0]  R_SPARC_TLS_LE_HIX22    0x1c 0x3fffff      0  .text     _ZL14StackTraceHead
    [1]  R_SPARC_TLS_LE_LOX10    0x20   0x1c00      0  .text     _ZL14StackTraceHead
]

Something is clearly wrong with values here...
Quuxplusone commented 7 years ago
Hmm... I'm not sure what I did wrong in the above, but it strangely messes up
LDO and LE relocations. Anyway, both LDO and LE have problems, LDO_HIX22 used
for PIC code and LE_HIX22 for non-PIC one.

In Oracle's (former Sun) "Linker and Libraries Guide", its "SPARC: Thread-Local
Storage Relocation Types" subsection, this relocation is being defined as:

R_SPARC_TLS_LDO_HIX22   T-simm22  @dtpoff(S + A) >> 10
R_SPARC_TLS_LE_HIX22    T-imm22   (@tpoff(S + A) ^0xffffffffffffffff) >> 10

If I read it right this is what linker should be doing when given Symbol (S)
and Addend (A). And Value is not present there at all.
Yet the code in lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp seems to be
doing some nontrivial fixups for the Value:

  case Sparc::fixup_sparc_tls_ldo_hix22:
  case Sparc::fixup_sparc_tls_le_hix22:
    return (~Value >> 10) & 0x3fffff;

I believe this fixup should just be deleted.
Quuxplusone commented 7 years ago

https://reviews.llvm.org/D35567 solves this problem for me.

Quuxplusone commented 7 years ago
Fixed with:
  rL308978: [Sparc] invalid adjustments in TLS_LE/TLS_LDO relocations removed