From abb7484c31d5346c5f7b06fb65549b0fef75dccf Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 3 Jun 2019 05:34:25 +0000 Subject: [PATCH] [ELF] Don't create an output section named `/DISCARD/` if it is assigned to the special phdr `NONE` Fixes the remaining issue of PR41673 after D61186: with `/DISCARD/ { ... } :NONE`, we may create an output section named `/DISCARD/`. Note, if an input section is named `/DISCARD/`, ld.bfd discards it but lld keeps it. It is probably not worth copying this behavior as it is unrealistic. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D62768 llvm-svn: 362356 --- lld/ELF/LinkerScript.cpp | 3 +++ lld/test/ELF/linkerscript/discard-phdr.s | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index a6354c8..3f68e6e 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -824,6 +824,9 @@ void LinkerScript::assignOffsets(OutputSection *Sec) { } static bool isDiscardable(OutputSection &Sec) { + if (Sec.Name == "/DISCARD/") + return true; + // We do not remove empty sections that are explicitly // assigned to any segment. if (!Sec.Phdrs.empty()) diff --git a/lld/test/ELF/linkerscript/discard-phdr.s b/lld/test/ELF/linkerscript/discard-phdr.s index 311dcba..dc2c823 100644 --- a/lld/test/ELF/linkerscript/discard-phdr.s +++ b/lld/test/ELF/linkerscript/discard-phdr.s @@ -10,7 +10,7 @@ # RUN: /DISCARD/ : { *(.discard) } :NONE \ # RUN: }" > %t.script # RUN: ld.lld -o %t --script %t.script %t.o -# RUN: llvm-readelf -S -l %t | FileCheck %s +# RUN: llvm-readelf -S -l %t | FileCheck --implicit-check-not=/DISCARD/ %s ## Check that /DISCARD/ does not interfere with the assignment of segments to ## sections. -- 2.7.4