[lld] r361036 - [ELF] -r: fix R_*_NONE to section symbols on Elf*_Rel targets

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 07:11:03 PDT 2019


Author: maskray
Date: Fri May 17 07:11:03 2019
New Revision: 361036

URL: http://llvm.org/viewvc/llvm-project?rev=361036&view=rev
Log:
[ELF] -r: fix R_*_NONE to section symbols on Elf*_Rel targets

On Elf*_Rel targets, for a relocation to a section symbol, an R_ABS is
added which will be used by relocateOne() to compute the implicit
addend.

Addends of R_*_NONE should be ignored, so don't emit an R_ABS.

This fixes crashes on X86 and ARM because their relocateOne() do not
handle R_*_NONE.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D62052

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/test/ELF/relocation-none-arm.s
    lld/trunk/test/ELF/relocation-none-i386.s

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=361036&r1=361035&r2=361036&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Fri May 17 07:11:03 2019
@@ -470,7 +470,7 @@ void InputSection::copyRelocations(uint8
 
       if (RelTy::IsRela)
         P->r_addend = Sym.getVA(Addend) - Section->getOutputSection()->Addr;
-      else if (Config->Relocatable)
+      else if (Config->Relocatable && Type != Target->NoneRel)
         Sec->Relocations.push_back({R_ABS, Type, Rel.r_offset, Addend, &Sym});
     }
   }

Modified: lld/trunk/test/ELF/relocation-none-arm.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocation-none-arm.s?rev=361036&r1=361035&r2=361036&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocation-none-arm.s (original)
+++ lld/trunk/test/ELF/relocation-none-arm.s Fri May 17 07:11:03 2019
@@ -8,6 +8,13 @@
 # CHECK: .data
 # CHECK: There are no relocations in this file.
 
+# RUN: ld.lld -r %t.o -o %t
+# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s
+
+# RELOC:      Section ({{.*}}) .rel.text {
+# RELOC-NEXT:   0x0 R_ARM_NONE .data 0x0
+# RELOC-NEXT: }
+
 .globl _start
 _start:
   nop

Modified: lld/trunk/test/ELF/relocation-none-i386.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocation-none-i386.s?rev=361036&r1=361035&r2=361036&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocation-none-i386.s (original)
+++ lld/trunk/test/ELF/relocation-none-i386.s Fri May 17 07:11:03 2019
@@ -8,6 +8,13 @@
 # CHECK: .data
 # CHECK: There are no relocations in this file.
 
+# RUN: ld.lld -r %t.o -o %t
+# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s
+
+# RELOC:      Section ({{.*}}) .rel.text {
+# RELOC-NEXT:   0x0 R_386_NONE .data 0x0
+# RELOC-NEXT: }
+
 .globl _start
 _start:
   ret




More information about the llvm-commits mailing list