Skip to content

Commit eb7db25

Browse files
[lld][ELF] Allow implicit wildcard in archive file name
1 parent a4e2927 commit eb7db25

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lld/ELF/LinkerScript.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class SectionPattern {
195195

196196
class InputSectionDescription : public SectionCommand {
197197
SingleStringMatcher filePat;
198+
SmallString<0> implicitArchiveWildcardPat;
198199

199200
// Cache of the most recent input argument and result of matchesFile().
200201
mutable std::optional<std::pair<const InputFile *, bool>> matchesFileCache;
@@ -203,9 +204,19 @@ class InputSectionDescription : public SectionCommand {
203204
InputSectionDescription(StringRef filePattern, uint64_t withFlags = 0,
204205
uint64_t withoutFlags = 0, StringRef classRef = {})
205206
: SectionCommand(InputSectionKind), filePat(filePattern),
206-
classRef(classRef), withFlags(withFlags), withoutFlags(withoutFlags) {
207+
implicitArchiveWildcardPat(), classRef(classRef), withFlags(withFlags),
208+
withoutFlags(withoutFlags) {
207209
assert((filePattern.empty() || classRef.empty()) &&
208210
"file pattern and class reference are mutually exclusive");
211+
212+
// Fixes up the input file pattern, adding an implicit wildcard
213+
// if the trailing character is an ':' to allow matching entire archives
214+
if (!filePattern.empty() && filePattern.back() == ':') {
215+
implicitArchiveWildcardPat.reserve(filePattern.size() + 1);
216+
implicitArchiveWildcardPat.append(filePattern);
217+
implicitArchiveWildcardPat.push_back('*');
218+
filePat = SingleStringMatcher(implicitArchiveWildcardPat);
219+
}
209220
}
210221

211222
static bool classof(const SectionCommand *c) {

lld/test/ELF/linkerscript/filename-spec.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# RUN: llvm-objdump -s 8 | FileCheck --check-prefix=SECONDFIRST %s
5656

5757
## Verify matching of archive library names in KEEP.
58-
# RUN: echo 'SECTIONS{.foo :{ KEEP(*lib2*(.foo)) KEEP(*lib1*(.foo)) }}' > 9.t
58+
# RUN: echo 'SECTIONS{.foo :{ KEEP(*lib2.a:(.foo)) KEEP(*lib1*(.foo)) }}' > 9.t
5959
# RUN: ld.lld -o 9 -T 9.t --whole-archive \
6060
# RUN: dir1/lib1.a dir2/lib2.a
6161
# RUN: llvm-objdump -s 9 | FileCheck --check-prefix=SECONDFIRST %s

0 commit comments

Comments
 (0)