Skip to content

Commit 36146d2

Browse files
committed
[ELF] Make LinkerDrive::link a template. NFC
This avoids many invokeELFT in `link`.
1 parent 4bf06be commit 36146d2

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

lld/ELF/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class LinkerDriver {
126126
private:
127127
void createFiles(llvm::opt::InputArgList &args);
128128
void inferMachineType();
129-
void link(llvm::opt::InputArgList &args);
129+
template <class ELFT> void link(llvm::opt::InputArgList &args);
130130
template <class ELFT> void compileBitcodeFiles(bool skipLinkedOutput);
131131
bool tryAddFatLTOFile(MemoryBufferRef mb, StringRef archiveName,
132132
uint64_t offsetInArchive, bool lazy);

lld/ELF/Driver.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
650650
if (errorCount())
651651
return;
652652

653-
link(args);
653+
invokeELFT(link, args);
654654
}
655655

656656
if (config->timeTraceEnabled) {
@@ -2711,7 +2711,7 @@ static void postParseObjectFile(ELFFileBase *file) {
27112711

27122712
// Do actual linking. Note that when this function is called,
27132713
// all linker scripts have already been parsed.
2714-
void LinkerDriver::link(opt::InputArgList &args) {
2714+
template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
27152715
llvm::TimeTraceScope timeScope("Link", StringRef("LinkerDriver::Link"));
27162716

27172717
// Handle --trace-symbol.
@@ -2733,7 +2733,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
27332733
llvm::TimeTraceScope timeScope("Parse input files");
27342734
for (size_t i = 0; i < files.size(); ++i) {
27352735
llvm::TimeTraceScope timeScope("Parse input files", files[i]->getName());
2736-
parseFile(files[i]);
2736+
doParseFile<ELFT>(files[i]);
27372737
}
27382738
if (armCmseImpLib)
27392739
parseArmCMSEImportLib(*armCmseImpLib);
@@ -2867,15 +2867,15 @@ void LinkerDriver::link(opt::InputArgList &args) {
28672867

28682868
// Handle --lto-validate-all-vtables-have-type-infos.
28692869
if (config->ltoValidateAllVtablesHaveTypeInfos)
2870-
invokeELFT(ltoValidateAllVtablesHaveTypeInfos, args);
2870+
ltoValidateAllVtablesHaveTypeInfos<ELFT>(args);
28712871

28722872
// Do link-time optimization if given files are LLVM bitcode files.
28732873
// This compiles bitcode files into real object files.
28742874
//
28752875
// With this the symbol table should be complete. After this, no new names
28762876
// except a few linker-synthesized ones will be added to the symbol table.
28772877
const size_t numObjsBeforeLTO = ctx.objectFiles.size();
2878-
invokeELFT(compileBitcodeFiles, skipLinkedOutput);
2878+
compileBitcodeFiles<ELFT>(skipLinkedOutput);
28792879

28802880
// Symbol resolution finished. Report backward reference problems,
28812881
// --print-archive-stats=, and --why-extract=.
@@ -2940,7 +2940,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
29402940
llvm::erase_if(ctx.inputSections, [](InputSectionBase *s) {
29412941
if (s->type != SHT_LLVM_SYMPART)
29422942
return false;
2943-
invokeELFT(readSymbolPartitionSection, s);
2943+
readSymbolPartitionSection<ELFT>(s);
29442944
return true;
29452945
});
29462946
}
@@ -2998,10 +2998,10 @@ void LinkerDriver::link(opt::InputArgList &args) {
29982998
ctx.inputSections.push_back(createCommentSection());
29992999

30003000
// Split SHF_MERGE and .eh_frame sections into pieces in preparation for garbage collection.
3001-
invokeELFT(splitSections,);
3001+
splitSections<ELFT>();
30023002

30033003
// Garbage collection and removal of shared symbols from unused shared objects.
3004-
invokeELFT(markLive,);
3004+
markLive<ELFT>();
30053005

30063006
// Make copies of any input sections that need to be copied into each
30073007
// partition.
@@ -3014,7 +3014,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
30143014

30153015
// Create synthesized sections such as .got and .plt. This is called before
30163016
// processSectionCommands() so that they can be placed by SECTIONS commands.
3017-
invokeELFT(createSyntheticSections,);
3017+
createSyntheticSections<ELFT>();
30183018

30193019
// Some input sections that are used for exception handling need to be moved
30203020
// into synthetic sections. Do that now so that they aren't assigned to
@@ -3054,18 +3054,18 @@ void LinkerDriver::link(opt::InputArgList &args) {
30543054
// Two input sections with different output sections should not be folded.
30553055
// ICF runs after processSectionCommands() so that we know the output sections.
30563056
if (config->icf != ICFLevel::None) {
3057-
invokeELFT(findKeepUniqueSections, args);
3058-
invokeELFT(doIcf,);
3057+
findKeepUniqueSections<ELFT>(args);
3058+
doIcf<ELFT>();
30593059
}
30603060

30613061
// Read the callgraph now that we know what was gced or icfed
30623062
if (config->callGraphProfileSort != CGProfileSortKind::None) {
30633063
if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file))
30643064
if (std::optional<MemoryBufferRef> buffer = readFile(arg->getValue()))
30653065
readCallGraph(*buffer);
3066-
invokeELFT(readCallGraphsFromObjectFiles,);
3066+
readCallGraphsFromObjectFiles<ELFT>();
30673067
}
30683068

30693069
// Write the result to the file.
3070-
invokeELFT(writeResult,);
3070+
writeResult<ELFT>();
30713071
}

lld/ELF/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static bool isCompatible(InputFile *file) {
288288
return false;
289289
}
290290

291-
template <class ELFT> static void doParseFile(InputFile *file) {
291+
template <class ELFT> void elf::doParseFile(InputFile *file) {
292292
if (!isCompatible(file))
293293
return;
294294

lld/ELF/InputFiles.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern std::unique_ptr<llvm::TarWriter> tar;
4646
std::optional<MemoryBufferRef> readFile(StringRef path);
4747

4848
// Add symbols in File to the symbol table.
49+
template <class ELFT> void doParseFile(InputFile *file);
4950
void parseFile(InputFile *file);
5051

5152
void parseArmCMSEImportLib(InputFile *file);

0 commit comments

Comments
 (0)