Currently lld uses base names of files to match against file patterns in
linker script SECTION rules. This patch extends it to use a fully specified
file name as it appears in --trace output to match agains, i.e,
"<path>/<objname>.o" or "<path>/<libname>.a(<objname>.o)".
Differential Revision: https://reviews.llvm.org/D37031
llvm-svn: 311713
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index ae8c9b6..a870aa2 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -174,18 +174,22 @@
return C->Kind == BytesDataKind;
}
-static StringRef basename(InputSectionBase *S) {
- if (S->File)
- return sys::path::filename(S->File->getName());
- return "";
+static std::string filename(InputSectionBase *S) {
+ if (!S->File)
+ return "";
+ if (S->File->ArchiveName.empty())
+ return S->File->getName();
+ return (S->File->ArchiveName + "(" + S->File->getName() + ")").str();
}
bool LinkerScript::shouldKeep(InputSectionBase *S) {
- for (InputSectionDescription *ID : Opt.KeptSections)
- if (ID->FilePat.match(basename(S)))
+ for (InputSectionDescription *ID : Opt.KeptSections) {
+ std::string Filename = filename(S);
+ if (ID->FilePat.match(Filename))
for (SectionPattern &P : ID->SectionPatterns)
if (P.SectionPat.match(S->Name))
return true;
+ }
return false;
}
@@ -280,7 +284,7 @@
if (Sec->Type == SHT_REL || Sec->Type == SHT_RELA)
continue;
- StringRef Filename = basename(Sec);
+ std::string Filename = filename(Sec);
if (!Cmd->FilePat.match(Filename) ||
Pat.ExcludedFilePat.match(Filename) ||
!Pat.SectionPat.match(Sec->Name))