[PATCH] D67164: [ELF] Don't shrink RelrSection

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 07:37:11 PDT 2019


MaskRay updated this revision to Diff 218697.
MaskRay added a comment.

Add a test


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67164/new/

https://reviews.llvm.org/D67164

Files:
  ELF/SyntheticSections.cpp
  test/ELF/pack-dyn-relocs-relr-loop.s


Index: test/ELF/pack-dyn-relocs-relr-loop.s
===================================================================
--- /dev/null
+++ test/ELF/pack-dyn-relocs-relr-loop.s
@@ -0,0 +1,41 @@
+# REQUIRES: aarch64
+# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
+# RUN: ld.lld -pie --pack-dyn-relocs=relr -z max-page-size=4096 %t.o -o %t
+# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELR %s
+# RUN: llvm-readobj -r --raw-relr %t | FileCheck --check-prefix=RAW %s
+
+## This test makes sure we don't shrink .relr.dyn,
+## otherwise it size may oscillate between two numbers.
+
+## The test is very sensitive to the exact section sizes and offsets,
+## make sure .data is located at a page boundary.
+
+# RELR:      .relr.dyn {
+# RELR-NEXT:   0x2F40 R_AARCH64_RELATIVE - 0x0
+# RELR-NEXT:   0x2F48 R_AARCH64_RELATIVE - 0x0
+# RELR-NEXT:   0x3000 R_AARCH64_RELATIVE - 0x0
+# RELR-NEXT: }
+
+# RAW:      0x2F40
+# RAW-NEXT: 0x1000003
+## Trailing 0x1 does not decode any relocation.
+# RAW-NEXT: 0x1
+
+.section .data.rel.ro
+.align 3
+.space 0xce0
+foo:
+## Encoded by the first word of .relr.dyn
+.quad foo
+
+## Encoded by the second word of .relr.dyn
+.quad foo
+
+.section .data
+.align 3
+bar:
+## If .data is at 0x3000, the relocation will be encoded by the second word.
+## If we shrink .relr.dyn, the end of .dynamic will be at 0x2ff8 and .data
+## will be at 0x3ff8, this relocation will be encoded by the third word,
+## which will cause .relr.dyn to expand again.
+.quad bar
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1957,6 +1957,11 @@
     }
   }
 
+  // Don't allow the section to shrink; otherwise the size of the section can
+  // oscillate infinitely. Trailing 1s do not decode to more relocations.
+  if (relrRelocs.size() < oldSize)
+    relrRelocs.resize(oldSize, Elf_Relr(1));
+
   return relrRelocs.size() != oldSize;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67164.218697.patch
Type: text/x-patch
Size: 1974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190904/d10a29ca/attachment.bin>


More information about the llvm-commits mailing list