[lld] r269417 - When using Rela, don't write the addend to the output section.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri May 13 07:15:37 PDT 2016


Author: rafael
Date: Fri May 13 09:15:37 2016
New Revision: 269417

URL: http://llvm.org/viewvc/llvm-project?rev=269417&view=rev
Log:
When using Rela, don't write the addend to the output section.

The Elf_Rela has an explicit addend. It doesn't need the addend to be
written to the section being relocated.

Since relative relocations are very common in the output, this is a
noticeable speedup. The results I got were

chromium
  master 4.778149487
  patch  4.761120792 0.996436131802
chromium fast
  master 1.896253636
  patch  1.840990582 0.970856718241
the gold plugin
  master 0.399337811
  patch  0.392279276 0.982324401032
clang
  master 0.666873675
  patch  0.665895708 0.998533504865
llvm-as
  master 0.037101095
  patch  0.037123149 1.00059442989
the gold plugin fsds
  master 0.422473396
  patch  0.414192879 0.980399909016
clang fsds
  master 0.747302008
  patch  0.744843964 0.996710775599
llvm-as fsds
  master 0.033146245
  patch  0.033064531 0.997534743377
scylla
  master 4.08857525
  patch  4.082245184 0.998451767275

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/mips-64.s
    lld/trunk/test/ELF/relocation-non-alloc.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=269417&r1=269416&r2=269417&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri May 13 09:15:37 2016
@@ -674,17 +674,22 @@ void Writer<ELFT>::scanRelocs(InputSecti
 
     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.

Modified: lld/trunk/test/ELF/mips-64.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-64.s?rev=269417&r1=269416&r2=269417&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-64.s (original)
+++ lld/trunk/test/ELF/mips-64.s Fri May 13 09:15:37 2016
@@ -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: ]

Modified: lld/trunk/test/ELF/relocation-non-alloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocation-non-alloc.s?rev=269417&r1=269416&r2=269417&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocation-non-alloc.s (original)
+++ lld/trunk/test/ELF/relocation-non-alloc.s Fri May 13 09:15:37 2016
@@ -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




More information about the llvm-commits mailing list