[ELF] Don't emit .relr.dyn section if there are no relocs
authorPetr Hosek <phosek@chromium.org>
Mon, 10 Sep 2018 21:54:56 +0000 (21:54 +0000)
committerPetr Hosek <phosek@chromium.org>
Mon, 10 Sep 2018 21:54:56 +0000 (21:54 +0000)
This resolves PR38875.

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

llvm-svn: 341870

lld/ELF/SyntheticSections.h
lld/test/ELF/empty-pack-dyn-relocs.s [new file with mode: 0644]

index a14e831..f51e85c 100644 (file)
@@ -536,6 +536,7 @@ struct RelativeReloc {
 class RelrBaseSection : public SyntheticSection {
 public:
   RelrBaseSection();
+  bool empty() const override { return Relocs.empty(); }
   std::vector<RelativeReloc> Relocs;
 };
 
diff --git a/lld/test/ELF/empty-pack-dyn-relocs.s b/lld/test/ELF/empty-pack-dyn-relocs.s
new file mode 100644 (file)
index 0000000..b74a89d
--- /dev/null
@@ -0,0 +1,11 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.o -o %t
+// RUN: llvm-readobj -sections %t | FileCheck %s
+
+.global _start
+_start:
+  nop
+
+# CHECK-NOT: Name: .relr.dyn