aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm/lib/Object/IRSymtab.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Object/IRSymtab.cpp')
-rw-r--r--contrib/llvm/lib/Object/IRSymtab.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/contrib/llvm/lib/Object/IRSymtab.cpp b/contrib/llvm/lib/Object/IRSymtab.cpp
index da1ef9946b50..bb3d1b2cf695 100644
--- a/contrib/llvm/lib/Object/IRSymtab.cpp
+++ b/contrib/llvm/lib/Object/IRSymtab.cpp
@@ -28,14 +28,12 @@ struct Builder {
Builder(SmallVector<char, 0> &Symtab, SmallVector<char, 0> &Strtab)
: Symtab(Symtab), Strtab(Strtab) {}
- StringTableBuilder StrtabBuilder{StringTableBuilder::ELF};
+ StringTableBuilder StrtabBuilder{StringTableBuilder::RAW};
BumpPtrAllocator Alloc;
StringSaver Saver{Alloc};
DenseMap<const Comdat *, unsigned> ComdatMap;
- ModuleSymbolTable Msymtab;
- SmallPtrSet<GlobalValue *, 8> Used;
Mangler Mang;
Triple TT;
@@ -49,6 +47,7 @@ struct Builder {
void setStr(storage::Str &S, StringRef Value) {
S.Offset = StrtabBuilder.add(Value);
+ S.Size = Value.size();
}
template <typename T>
void writeRange(storage::Range<T> &R, const std::vector<T> &Objs) {
@@ -59,18 +58,24 @@ struct Builder {
}
Error addModule(Module *M);
- Error addSymbol(ModuleSymbolTable::Symbol Sym);
+ Error addSymbol(const ModuleSymbolTable &Msymtab,
+ const SmallPtrSet<GlobalValue *, 8> &Used,
+ ModuleSymbolTable::Symbol Sym);
Error build(ArrayRef<Module *> Mods);
};
Error Builder::addModule(Module *M) {
+ SmallPtrSet<GlobalValue *, 8> Used;
collectUsedGlobalVariables(*M, Used, /*CompilerUsed*/ false);
- storage::Module Mod;
- Mod.Begin = Msymtab.symbols().size();
+ ModuleSymbolTable Msymtab;
Msymtab.addModule(M);
- Mod.End = Msymtab.symbols().size();
+
+ storage::Module Mod;
+ Mod.Begin = Syms.size();
+ Mod.End = Syms.size() + Msymtab.symbols().size();
+ Mod.UncBegin = Uncommons.size();
Mods.push_back(Mod);
if (TT.isOSBinFormatCOFF()) {
@@ -84,20 +89,25 @@ Error Builder::addModule(Module *M) {
}
}
+ for (ModuleSymbolTable::Symbol Msym : Msymtab.symbols())
+ if (Error Err = addSymbol(Msymtab, Used, Msym))
+ return Err;
+
return Error::success();
}
-Error Builder::addSymbol(ModuleSymbolTable::Symbol Msym) {
+Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
+ const SmallPtrSet<GlobalValue *, 8> &Used,
+ ModuleSymbolTable::Symbol Msym) {
Syms.emplace_back();
storage::Symbol &Sym = Syms.back();
Sym = {};
- Sym.UncommonIndex = -1;
storage::Uncommon *Unc = nullptr;
auto Uncommon = [&]() -> storage::Uncommon & {
if (Unc)
return *Unc;
- Sym.UncommonIndex = Uncommons.size();
+ Sym.Flags |= 1 << storage::Symbol::FB_has_uncommon;
Uncommons.emplace_back();
Unc = &Uncommons.back();
*Unc = {};
@@ -194,15 +204,10 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
setStr(Hdr.SourceFileName, IRMods[0]->getSourceFileName());
TT = Triple(IRMods[0]->getTargetTriple());
- // This adds the symbols for each module to Msymtab.
for (auto *M : IRMods)
if (Error Err = addModule(M))
return Err;
- for (ModuleSymbolTable::Symbol Msym : Msymtab.symbols())
- if (Error Err = addSymbol(Msym))
- return Err;
-
COFFLinkerOptsOS.flush();
setStr(Hdr.COFFLinkerOpts, COFFLinkerOpts);