From c6a233a68a6d0d870bb3126083c85e6cb0b71390 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Mon, 10 Sep 2018 21:54:56 +0000 Subject: [PATCH] [ELF] Don't emit .relr.dyn section if there are no relocs This resolves PR38875. Differential Revision: https://reviews.llvm.org/D51834 llvm-svn: 341870 --- lld/ELF/SyntheticSections.h | 1 + lld/test/ELF/empty-pack-dyn-relocs.s | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 lld/test/ELF/empty-pack-dyn-relocs.s diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index a14e831..f51e85c 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -536,6 +536,7 @@ struct RelativeReloc { class RelrBaseSection : public SyntheticSection { public: RelrBaseSection(); + bool empty() const override { return Relocs.empty(); } std::vector 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 index 0000000..b74a89d --- /dev/null +++ b/lld/test/ELF/empty-pack-dyn-relocs.s @@ -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 -- 2.7.4