[lld] e83afbe - [ELF] Remove unneeded sec->file check
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 16 22:17:23 PST 2024
Author: Fangrui Song
Date: 2024-12-16T22:17:18-08:00
New Revision: e83afbe793071727533d822bcc29f547dfab2905
URL: https://github.com/llvm/llvm-project/commit/e83afbe793071727533d822bcc29f547dfab2905
DIFF: https://github.com/llvm/llvm-project/commit/e83afbe793071727533d822bcc29f547dfab2905.diff
LOG: [ELF] Remove unneeded sec->file check
Added:
Modified:
lld/ELF/LinkerScript.cpp
lld/ELF/LinkerScript.h
Removed:
################################################################################
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 7d24c6750b0d10..a8e3d6486353d5 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -402,33 +402,30 @@ void LinkerScript::assignSymbol(SymbolAssignment *cmd, bool inSec) {
cmd->sym->type = v.type;
}
-static inline StringRef getFilename(const InputFile *file) {
- return file ? file->getNameForScript() : StringRef();
-}
-
-bool InputSectionDescription::matchesFile(const InputFile *file) const {
+bool InputSectionDescription::matchesFile(const InputFile &file) const {
if (filePat.isTrivialMatchAll())
return true;
- if (!matchesFileCache || matchesFileCache->first != file)
- matchesFileCache.emplace(file, filePat.match(getFilename(file)));
+ if (!matchesFileCache || matchesFileCache->first != &file)
+ matchesFileCache.emplace(&file, filePat.match(file.getNameForScript()));
return matchesFileCache->second;
}
-bool SectionPattern::excludesFile(const InputFile *file) const {
+bool SectionPattern::excludesFile(const InputFile &file) const {
if (excludedFilePat.empty())
return false;
- if (!excludesFileCache || excludesFileCache->first != file)
- excludesFileCache.emplace(file, excludedFilePat.match(getFilename(file)));
+ if (!excludesFileCache || excludesFileCache->first != &file)
+ excludesFileCache.emplace(&file,
+ excludedFilePat.match(file.getNameForScript()));
return excludesFileCache->second;
}
bool LinkerScript::shouldKeep(InputSectionBase *s) {
for (InputSectionDescription *id : keptSections)
- if (id->matchesFile(s->file))
+ if (id->matchesFile(*s->file))
for (SectionPattern &p : id->sectionPatterns)
if (p.sectionPat.match(s->name) &&
(s->flags & id->withFlags) == id->withFlags &&
@@ -557,7 +554,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd,
if (!pat.sectionPat.match(sec->name))
continue;
- if (!cmd->matchesFile(sec->file) || pat.excludesFile(sec->file) ||
+ if (!cmd->matchesFile(*sec->file) || pat.excludesFile(*sec->file) ||
sec->parent == &outCmd || !flagsMatch(sec))
continue;
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 328368fd3b4333..721425166296ae 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -186,7 +186,7 @@ class SectionPattern {
sortOuter(SortSectionPolicy::Default),
sortInner(SortSectionPolicy::Default) {}
- bool excludesFile(const InputFile *file) const;
+ bool excludesFile(const InputFile &file) const;
StringMatcher sectionPat;
SortSectionPolicy sortOuter;
@@ -212,7 +212,7 @@ class InputSectionDescription : public SectionCommand {
return c->kind == InputSectionKind;
}
- bool matchesFile(const InputFile *file) const;
+ bool matchesFile(const InputFile &file) const;
// Input sections that matches at least one of SectionPatterns
// will be associated with this InputSectionDescription.
More information about the llvm-commits
mailing list