[PATCH] D45788: Mitigate relocation overflow [part 1 of 2]

Han Shen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 27 09:46:56 PDT 2018


shenhan updated this revision to Diff 144362.
shenhan marked an inline comment as done and an inline comment as not done.

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D45788

Files:
  ELF/Writer.cpp
  test/ELF/aarch64-copy.s
  test/ELF/arm-copy.s
  test/ELF/dynsec-at-beginning.s


Index: test/ELF/dynsec-at-beginning.s
===================================================================
--- /dev/null
+++ test/ELF/dynsec-at-beginning.s
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+
+# RUN: ld.lld --hash-style=gnu -o %t1  %t -shared
+# RUN: llvm-readobj -elf-output-style=GNU -s %t1 | FileCheck %s
+
+# Dynamic symbol and dynamic strtab sections are at the beginning of
+# SHF_ALLOC sections.
+# CHECK:      .dynsym  {{.*}}   A
+# CHECK-NEXT: .dynstr  {{.*}}   A
+# CHECK-NEXT: .hash    {{.*}}   A
+# CHECK-NEXT: .text    {{.*}}   AX
+# CHECK-NEXT: foo      {{.*}}   WA
+
+.section foo, "aw"
+.byte 0
Index: test/ELF/arm-copy.s
===================================================================
--- test/ELF/arm-copy.s
+++ test/ELF/arm-copy.s
@@ -78,4 +78,4 @@
 
 // RODATA: Contents of section .rodata:
 // S(z) = 0x13004
-// RODATA-NEXT: 10114 04300100
+// RODATA-NEXT: 10144 04300100
Index: test/ELF/aarch64-copy.s
===================================================================
--- test/ELF/aarch64-copy.s
+++ test/ELF/aarch64-copy.s
@@ -90,4 +90,4 @@
 
 // RODATA: Contents of section .rodata:
 // S(z) = 0x40014
-// RODATA-NEXT:  101c8 14000400
+// RODATA-NEXT:  10228 14000400
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -717,6 +717,16 @@
   if (!(Sec->Flags & SHF_ALLOC))
     return Rank | RF_NOT_ALLOC;
 
+  // Place .dynsym and .dynstr at the beginning of SHF_ALLOC
+  // sections. We want to do this to mitigate the possibility that
+  // huge .dynsym and .dynstr sections placed between text sections
+  // cause relocation overflow.  Note: .dynstr has SHT_STRTAB type and
+  // SHF_ALLOC attribute, whereas sections that only have SHT_STRTAB
+  // but without SHF_ALLOC is placed at the end. All "Sec" reaching
+  // here has SHF_ALLOC bit set.
+  if (Sec->Type == SHT_DYNSYM || Sec->Type == SHT_STRTAB)
+    return Rank;
+
   // Sort sections based on their access permission in the following
   // order: R, RX, RWX, RW.  This order is based on the following
   // considerations:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45788.144362.patch
Type: text/x-patch
Size: 2161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180427/a95ab5b5/attachment.bin>


More information about the llvm-commits mailing list