From 1da3a52d118f1893c3d1bd00e5e27cc2e178b806 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Tue, 1 Nov 2016 20:11:01 +0000 Subject: [PATCH] [ELF/GC] Fix pending references to garbage collected sections. The example reported in PR30793 shows a case where gc reclaims a SHF_TLS section, but it doesn't reclaim the section containing the debug info for it. This is expected, as we do not reclaim non-alloc sections during the garbage collection phase (and this is not going to change anytime soon, at least this is what I gathered last I talked with Rafael about it). So, we end up with a pending reference, thinking that the input was invalid (which is not true, as it's GC that removed the SHT_TLS section, and therefore didn't create the PT_TLS *segment* for it). In cases like this, just assign a VA of zero at relocation time instead of error'ing out (this is what gold does as well, FWIW). Differential Revision: https://reviews.llvm.org/D26201 llvm-svn: 285735 --- lld/ELF/InputSection.cpp | 6 ++++-- lld/test/ELF/gc-debuginfo-tls.s | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 lld/test/ELF/gc-debuginfo-tls.s diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index d817fe12174f..c6f34be5564a 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -411,8 +411,10 @@ void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef Rels) { } uintX_t AddrLoc = this->OutSec->getVA() + Offset; - uint64_t SymVA = SignExtend64( - getSymVA(Type, Addend, AddrLoc, Sym, R_ABS)); + uint64_t SymVA = 0; + if (!Sym.isTls() || Out::TlsPhdr) + SymVA = SignExtend64( + getSymVA(Type, Addend, AddrLoc, Sym, R_ABS)); Target->relocateOne(BufLoc, Type, SymVA); } } diff --git a/lld/test/ELF/gc-debuginfo-tls.s b/lld/test/ELF/gc-debuginfo-tls.s new file mode 100644 index 000000000000..9884a578cca9 --- /dev/null +++ b/lld/test/ELF/gc-debuginfo-tls.s @@ -0,0 +1,23 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o --gc-sections -shared -o %t1 +# RUN: ld.lld %t.o -shared -o %t2 +# RUN: llvm-readobj -symbols %t1 | FileCheck %s --check-prefix=GC +# RUN: llvm-readobj -symbols %t2 | FileCheck %s --check-prefix=NOGC + +# NOGC: Symbol { +# NOGC: Name: .tbss +# NOGC: Value: 0x1000 +# NOGC: Size: 0 +# NOGC: Binding: Local +# NOGC: Type: TLS +# NOGC: Other: 0 +# NOGC: Section: .tbss +# NOGC: } + +# GC-NOT: tbss + +.section .tbss,"awT",@nobits +patatino: + .long 0 + .section .noalloc,"" + .quad patatino