[lld] r283305 - [ELF] make KEEP command recognize file patterns
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 5 02:36:59 PDT 2016
Author: evgeny777
Date: Wed Oct 5 04:36:59 2016
New Revision: 283305
URL: http://llvm.org/viewvc/llvm-project?rev=283305&view=rev
Log:
[ELF] make KEEP command recognize file patterns
Differential revision: https://reviews.llvm.org/D25242
Added:
lld/trunk/test/ELF/linkerscript/Inputs/keep.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/test/ELF/linkerscript/sections-keep.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=283305&r1=283304&r2=283305&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Oct 5 04:36:59 2016
@@ -108,9 +108,15 @@ template <class ELFT> LinkerScript<ELFT>
template <class ELFT>
bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) {
- for (Regex *Re : Opt.KeptSections)
- if (Re->match(S->Name))
- return true;
+ for (InputSectionDescription *ID : Opt.KeptSections) {
+ StringRef Filename = S->getFile()->getName();
+ if (!ID->FileRe.match(sys::path::filename(Filename)))
+ continue;
+
+ for (SectionPattern &P : ID->SectionPatterns)
+ if (P.SectionRe.match(S->Name))
+ return true;
+ }
return false;
}
@@ -1247,8 +1253,7 @@ ScriptParser::readInputSectionDescriptio
StringRef FilePattern = next();
InputSectionDescription *Cmd = readInputSectionRules(FilePattern);
expect(")");
- for (SectionPattern &Pat : Cmd->SectionPatterns)
- Opt.KeptSections.push_back(&Pat.SectionRe);
+ Opt.KeptSections.push_back(Cmd);
return Cmd;
}
return readInputSectionRules(Tok);
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=283305&r1=283304&r2=283305&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Wed Oct 5 04:36:59 2016
@@ -184,7 +184,7 @@ struct ScriptConfiguration {
// List of section patterns specified with KEEP commands. They will
// be kept even if they are unused and --gc-sections is specified.
- std::vector<llvm::Regex *> KeptSections;
+ std::vector<InputSectionDescription *> KeptSections;
};
extern ScriptConfiguration *ScriptConfig;
Added: lld/trunk/test/ELF/linkerscript/Inputs/keep.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/Inputs/keep.s?rev=283305&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/Inputs/keep.s (added)
+++ lld/trunk/test/ELF/linkerscript/Inputs/keep.s Wed Oct 5 04:36:59 2016
@@ -0,0 +1,2 @@
+.section .keep, "a"
+ .long 0x41414141
Modified: lld/trunk/test/ELF/linkerscript/sections-keep.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/sections-keep.s?rev=283305&r1=283304&r2=283305&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/sections-keep.s (original)
+++ lld/trunk/test/ELF/linkerscript/sections-keep.s Wed Oct 5 04:36:59 2016
@@ -1,5 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/keep.s -o %t2.o
## First check that section "keep" is garbage collected without using KEEP
# RUN: echo "SECTIONS { \
@@ -69,6 +70,16 @@
# MIXED2-NEXT: 5 .shstrtab 0000002f 0000000000000000
# MIXED2-NEXT: 6 .strtab 00000012 0000000000000000
+# Check file pattern for kept sections.
+# RUN: echo "SECTIONS { \
+# RUN: . = SIZEOF_HEADERS; \
+# RUN: .keep : { KEEP(*2.o(.keep)) } \
+# RUN: }" > %t.script
+# RUN: ld.lld --gc-sections -o %t1 --script %t.script %t2.o %t
+# RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=FILEMATCH %s
+# FILEMATCH: Contents of section .keep:
+# FILEMATCH-NEXT: 00e8 41414141 AAAA
+
.global _start
_start:
mov temp, %eax
More information about the llvm-commits
mailing list