Skip to content

Commit d36b96a

Browse files
committed
[LinkerWrapper] Fix use of string savers and correctly pass bitcode libraries
This patch removes some uses of string savers that are no-longer needed. We also create a new string saver when linking bitcode files. It seems that occasionally the symbol string references can go out of scope when they are added to the LTO input so we need to save these names that are used for symbol resolution. Additionally, a previous patch added new logic for handling bitcode libraries, but failed to actually add them to the input. This bug has been fixed. Fixes llvm#56445 Reviewed By: ye-luo Differential Revision: https://reviews.llvm.org/D129383
1 parent b069801 commit d36b96a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,15 @@ fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
525525
if (!TempFileOrErr)
526526
return TempFileOrErr.takeError();
527527

528-
BumpPtrAllocator Alloc;
529-
StringSaver Saver(Alloc);
530-
531528
SmallVector<StringRef, 16> CmdArgs;
532529
CmdArgs.push_back(*FatBinaryPath);
533530
CmdArgs.push_back(Triple.isArch64Bit() ? "-64" : "-32");
534531
CmdArgs.push_back("--create");
535532
CmdArgs.push_back(*TempFileOrErr);
536533
for (const auto &FileAndArch : InputFiles)
537-
CmdArgs.push_back(Saver.save("--image=profile=" + std::get<1>(FileAndArch) +
538-
",file=" + std::get<0>(FileAndArch)));
534+
CmdArgs.push_back(
535+
Args.MakeArgString("--image=profile=" + std::get<1>(FileAndArch) +
536+
",file=" + std::get<0>(FileAndArch)));
539537

540538
if (Error Err = executeCommands(*FatBinaryPath, CmdArgs))
541539
return std::move(Err);
@@ -808,6 +806,8 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles,
808806
SmallVector<OffloadFile, 4> BitcodeInputFiles;
809807
DenseSet<StringRef> UsedInRegularObj;
810808
DenseSet<StringRef> UsedInSharedLib;
809+
BumpPtrAllocator Alloc;
810+
StringSaver Saver(Alloc);
811811

812812
// Search for bitcode files in the input and create an LTO input file. If it
813813
// is not a bitcode file, scan its symbol table for symbols we need to save.
@@ -844,9 +844,9 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles,
844844

845845
// Record if we've seen these symbols in any object or shared libraries.
846846
if ((*ObjFile)->isRelocatableObject())
847-
UsedInRegularObj.insert(*Name);
847+
UsedInRegularObj.insert(Saver.save(*Name));
848848
else
849-
UsedInSharedLib.insert(*Name);
849+
UsedInSharedLib.insert(Saver.save(*Name));
850850
}
851851
continue;
852852
}
@@ -908,7 +908,8 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles,
908908
// We will use this as the prevailing symbol definition in LTO unless
909909
// it is undefined or another definition has already been used.
910910
Res.Prevailing =
911-
!Sym.isUndefined() && PrevailingSymbols.insert(Sym.getName()).second;
911+
!Sym.isUndefined() &&
912+
PrevailingSymbols.insert(Saver.save(Sym.getName())).second;
912913

913914
// We need LTO to preseve the following global symbols:
914915
// 1) Symbols used in regular objects.
@@ -1193,8 +1194,6 @@ linkAndWrapDeviceFiles(SmallVectorImpl<OffloadFile> &LinkerInputFiles,
11931194
InputsForTarget[File].emplace_back(std::move(File));
11941195
LinkerInputFiles.clear();
11951196

1196-
BumpPtrAllocator Alloc;
1197-
UniqueStringSaver Saver(Alloc);
11981197
DenseMap<OffloadKind, SmallVector<OffloadingImage, 2>> Images;
11991198
for (auto &InputForTarget : InputsForTarget) {
12001199
SmallVector<OffloadFile, 4> &Input = InputForTarget.getSecond();
@@ -1395,6 +1394,7 @@ int main(int Argc, char **Argv) {
13951394
auto FileOrErr = getInputBitcodeLibrary(Library);
13961395
if (!FileOrErr)
13971396
reportError(FileOrErr.takeError());
1397+
InputFiles.push_back(std::move(*FileOrErr));
13981398
}
13991399

14001400
DenseSet<OffloadFile::TargetID> IsTargetUsed;

0 commit comments

Comments
 (0)