diff options
-rw-r--r-- | lld/ELF/Writer.cpp | 13 | ||||
-rw-r--r-- | lld/test/ELF/mips-64.s | 8 | ||||
-rw-r--r-- | lld/test/ELF/relocation-non-alloc.s | 2 |
3 files changed, 12 insertions, 11 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 708e29049fb..d1604a27679 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -674,17 +674,22 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) { if (needsPlt(Expr) || Expr == R_THUNK || refersToGotEntry(Expr) || !Body.isPreemptible()) { - // If the relocation points to something in the file, remember it so that - // we can apply it when writting the section. - C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); + // If the relocation points to something in the file, we can process it. + bool Constant = isStaticLinkTimeConstant<ELFT>(Expr, Type, Body); // If the output being produced is position independent, the final value // is still not known. In that case we still need some help from the // dynamic linker. We can however do better than just copying the incoming // relocation. We can process some of it and and just ask the dynamic // linker to add the load address. - if (!isStaticLinkTimeConstant<ELFT>(Expr, Type, Body)) + if (!Constant) AddDyn({Target->RelativeRel, C.OutSec, Offset, true, &Body, Addend}); + + // If the produced value is a constant, we just remember to write it + // when outputting this section. We also have to do it if the format + // uses Elf_Rel, since in that case the written value is the addend. + if (Constant || !RelTy::IsRela) + C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); } else { // We don't know anything about the finaly symbol. Just ask the dynamic // linker to handle the relocation for us. diff --git a/lld/test/ELF/mips-64.s b/lld/test/ELF/mips-64.s index 3d5c16a8a6f..689669e4b09 100644 --- a/lld/test/ELF/mips-64.s +++ b/lld/test/ELF/mips-64.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t.o # RUN: ld.lld -shared %t.o -o %t.so -# RUN: llvm-objdump -t -s %t.so | FileCheck -check-prefix=SYM %s +# RUN: llvm-objdump -t %t.so | FileCheck -check-prefix=SYM %s # RUN: llvm-readobj -r -dynamic-table -mips-plt-got %t.so | FileCheck %s # REQUIRES: mips @@ -24,11 +24,6 @@ v2: .quad v2+8 # R_MIPS_64 target v2 addend 8 .quad v1 # R_MIPS_64 target v1 addend 0 -# SYM: Contents of section .data: -# SYM-NEXT: 30000 00000000 00000000 00000000 00000000 -# ^-- v2 -# SYM-NEXT: 30010 00000000 00030000 -# ^-- v1 # SYM: SYMBOL TABLE: # SYM: 00030000 l .data 00000004 v1 @@ -37,6 +32,7 @@ v2: # CHECK: Relocations [ # CHECK-NEXT: Section (7) .rela.dyn { # CHECK-NEXT: 0x30010 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE - 0x30000 +# ^-- v1 # CHECK-NEXT: 0x30008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE v2 0x8 # CHECK-NEXT: } # CHECK-NEXT: ] diff --git a/lld/test/ELF/relocation-non-alloc.s b/lld/test/ELF/relocation-non-alloc.s index 14199d6335b..43f6f5ff1e4 100644 --- a/lld/test/ELF/relocation-non-alloc.s +++ b/lld/test/ELF/relocation-non-alloc.s @@ -18,7 +18,7 @@ // CHECK-NEXT: AddressAlignment: 1 // CHECK-NEXT: EntrySize: 0 // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 00200000 00000000 00000000 00000000 +// CHECK-NEXT: 0000: 00000000 00000000 00000000 00000000 // CHECK-NEXT: ) // CHECK: Name: foo |