From a9ee8d6eccfbe01c6c25829a26dd7c9c4286d222 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 4 Nov 2016 22:25:39 +0000 Subject: [PATCH] Don't gc .interp section. This change fixes a bug that was introduced by r285851. r285851 converted .interp section as an output section to an input section. But I forgot to make it a "Live" section, so if -gc-section is given, it was garbage collected. llvm-svn: 286025 --- lld/ELF/SyntheticSections.cpp | 6 +++++- lld/test/ELF/gc-sections-synthetic.s | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/gc-sections-synthetic.s diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 0df51b3..0026566 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -46,12 +46,16 @@ static ArrayRef createInterp() { template InterpSection::InterpSection() : InputSection(SHF_ALLOC, SHT_PROGBITS, 1, createInterp(), - ".interp") {} + ".interp") { + this->Live = true; +} template BuildIdSection::BuildIdSection(size_t HashSize) : InputSection(SHF_ALLOC, SHT_NOTE, 1, ArrayRef(), ".note.gnu.build-id") { + this->Live = true; + Buf.resize(16 + HashSize); const endianness E = ELFT::TargetEndianness; write32(Buf.data(), 4); // Name size diff --git a/lld/test/ELF/gc-sections-synthetic.s b/lld/test/ELF/gc-sections-synthetic.s new file mode 100644 index 0000000..5c36081 --- /dev/null +++ b/lld/test/ELF/gc-sections-synthetic.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 + +# Linker-synthesized sections shouldn't be gc'ed. + +# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/Inputs/shared.s -o %t.o +# RUN: ld.lld %t2 -shared -o %t.so +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2 +# RUN: ld.lld %t2 %t.so -build-id -dynamic-linker /foo/bar -o %t.out +# RUN: llvm-readobj -sections %t.out | FileCheck %s + +# CHECK: Name: .interp +# CHECK: Name: .note.gnu.build-id + +.globl _start +_start: + ret -- 2.7.4