Skip to content

Commit f1f06f3

Browse files
committed
[ELF] Move parse files from Driver.cpp to InputFiles.cpp. NFC
Fixes: 36146d2 When `doParseFile template defintion` in InputFiles.cpp is optimized out, we will get a link failure. Actually, we can move the file parsing loop from Driver.too to InputFiles.cpp and merge it with parseArmCMSEImportLib.
1 parent 8ebf741 commit f1f06f3

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

lld/ELF/Driver.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,19 +2725,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
27252725
for (StringRef name : config->undefined)
27262726
addUnusedUndefined(name)->referenced = true;
27272727

2728-
// Add all files to the symbol table. This will add almost all
2729-
// symbols that we need to the symbol table. This process might
2730-
// add files to the link, via autolinking, these files are always
2731-
// appended to the Files vector.
2732-
{
2733-
llvm::TimeTraceScope timeScope("Parse input files");
2734-
for (size_t i = 0; i < files.size(); ++i) {
2735-
llvm::TimeTraceScope timeScope("Parse input files", files[i]->getName());
2736-
doParseFile<ELFT>(files[i]);
2737-
}
2738-
if (armCmseImpLib)
2739-
parseArmCMSEImportLib(*armCmseImpLib);
2740-
}
2728+
parseFiles(files, armCmseImpLib);
27412729

27422730
// Now that we have every file, we can decide if we will need a
27432731
// dynamic symbol table.

lld/ELF/InputFiles.cpp

Lines changed: 17 additions & 5 deletions
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> void elf::doParseFile(InputFile *file) {
291+
template <class ELFT> static void doParseFile(InputFile *file) {
292292
if (!isCompatible(file))
293293
return;
294294

@@ -330,12 +330,24 @@ extern template void ObjFile<ELF32BE>::importCmseSymbols();
330330
extern template void ObjFile<ELF64LE>::importCmseSymbols();
331331
extern template void ObjFile<ELF64BE>::importCmseSymbols();
332332

333-
template <class ELFT> static void doParseArmCMSEImportLib(InputFile &file) {
334-
cast<ObjFile<ELFT>>(file).importCmseSymbols();
333+
template <class ELFT>
334+
static void doParseFiles(const std::vector<InputFile *> &files,
335+
InputFile *armCmseImpLib) {
336+
// Add all files to the symbol table. This will add almost all symbols that we
337+
// need to the symbol table. This process might add files to the link due to
338+
// addDependentLibrary.
339+
for (size_t i = 0; i < files.size(); ++i) {
340+
llvm::TimeTraceScope timeScope("Parse input files", files[i]->getName());
341+
doParseFile<ELFT>(files[i]);
342+
}
343+
if (armCmseImpLib)
344+
cast<ObjFile<ELFT>>(*armCmseImpLib).importCmseSymbols();
335345
}
336346

337-
void elf::parseArmCMSEImportLib(InputFile &file) {
338-
invokeELFT(doParseArmCMSEImportLib, file);
347+
void elf::parseFiles(const std::vector<InputFile *> &files,
348+
InputFile *armCmseImpLib) {
349+
llvm::TimeTraceScope timeScope("Parse input files");
350+
invokeELFT(doParseFiles, files, armCmseImpLib);
339351
}
340352

341353
// Concatenates arguments to construct a string representing an error location.

lld/ELF/InputFiles.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ 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);
5049
void parseFile(InputFile *file);
51-
52-
void parseArmCMSEImportLib(InputFile &file);
50+
void parseFiles(const std::vector<InputFile *> &files,
51+
InputFile *armCmseImpLib);
5352

5453
// The root class of input files.
5554
class InputFile {

0 commit comments

Comments
 (0)