Skip to content

Commit 9776ed4

Browse files
fix use-after-free
1 parent 106f91c commit 9776ed4

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,8 +1746,10 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
17461746

17471747
// Symbols can be duplicated in bitcode files because of '#include' and
17481748
// linkonce_odr. Use unique_saver to save symbol names for de-duplication.
1749-
if (!sym)
1750-
sym = symtab.insert(unique_saver().save(objSym.getName()));
1749+
if (!sym) {
1750+
objSym.Name = unique_saver().save(objSym.getName());
1751+
sym = symtab.insert(objSym.getName());
1752+
}
17511753

17521754
int c = objSym.getComdatIndex();
17531755
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
@@ -1797,18 +1799,18 @@ void BitcodeFile::parse() {
17971799
void BitcodeFile::parseLazy() {
17981800
numSymbols = obj->symbols().size();
17991801
symbols = std::make_unique<Symbol *[]>(numSymbols);
1800-
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
1802+
for (auto [i, irSym] : llvm::enumerate(obj->symbols())) {
1803+
// Keep copies of per-module undefined symbols for LTO::GlobalResolutions
1804+
// usage.
1805+
irSym.Name = unique_saver().save(irSym.getName());
18011806
if (!irSym.isUndefined()) {
18021807
// Symbols can be duplicated in bitcode files because of '#include' and
18031808
// linkonce_odr. Use unique_saver to save symbol names for de-duplication.
1804-
auto *sym = symtab.insert(unique_saver().save(irSym.getName()));
1809+
auto *sym = symtab.insert(irSym.getName());
18051810
sym->resolve(LazySymbol{*this});
18061811
symbols[i] = sym;
1807-
} else {
1808-
// Keep copies of per-module undefined symbols for LTO::GlobalResolutions
1809-
// usage.
1810-
unique_saver().save(irSym.getName());
18111812
}
1813+
}
18121814
}
18131815

18141816
void BitcodeFile::postParse() {

llvm/include/llvm/LTO/LTO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class InputFile {
138138

139139
/// The purpose of this class is to only expose the symbol information that an
140140
/// LTO client should need in order to do symbol resolution.
141-
class Symbol : irsymtab::Symbol {
141+
struct Symbol : irsymtab::Symbol {
142142
friend LTO;
143143

144144
public:

llvm/include/llvm/Object/IRSymtab.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ Error build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab,
169169
/// possibly a storage::Uncommon.
170170
struct Symbol {
171171
// Copied from storage::Symbol.
172-
StringRef Name, IRName;
172+
mutable StringRef Name;
173+
StringRef IRName;
173174
int ComdatIndex;
174175
uint32_t Flags;
175176

0 commit comments

Comments
 (0)