aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm/lib/Object/ModuleSymbolTable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Object/ModuleSymbolTable.cpp')
-rw-r--r--contrib/llvm/lib/Object/ModuleSymbolTable.cpp80
1 files changed, 2 insertions, 78 deletions
diff --git a/contrib/llvm/lib/Object/ModuleSymbolTable.cpp b/contrib/llvm/lib/Object/ModuleSymbolTable.cpp
index 64446525b916..f0d70aefd426 100644
--- a/contrib/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/contrib/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -24,7 +24,6 @@
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
-#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
@@ -69,81 +68,6 @@ void ModuleSymbolTable::addModule(Module *M) {
});
}
-// Ensure ELF .symver aliases get the same binding as the defined symbol
-// they alias with.
-static void handleSymverAliases(const Module &M, RecordStreamer &Streamer) {
- if (Streamer.symverAliases().empty())
- return;
-
- // The name in the assembler will be mangled, but the name in the IR
- // might not, so we first compute a mapping from mangled name to GV.
- Mangler Mang;
- SmallString<64> MangledName;
- StringMap<const GlobalValue *> MangledNameMap;
- auto GetMangledName = [&](const GlobalValue &GV) {
- if (!GV.hasName())
- return;
-
- MangledName.clear();
- MangledName.reserve(GV.getName().size() + 1);
- Mang.getNameWithPrefix(MangledName, &GV, /*CannotUsePrivateLabel=*/false);
- MangledNameMap[MangledName] = &GV;
- };
- for (const Function &F : M)
- GetMangledName(F);
- for (const GlobalVariable &GV : M.globals())
- GetMangledName(GV);
- for (const GlobalAlias &GA : M.aliases())
- GetMangledName(GA);
-
- // Walk all the recorded .symver aliases, and set up the binding
- // for each alias.
- for (auto &Symver : Streamer.symverAliases()) {
- const MCSymbol *Aliasee = Symver.first;
- MCSymbolAttr Attr = MCSA_Invalid;
-
- // First check if the aliasee binding was recorded in the asm.
- RecordStreamer::State state = Streamer.getSymbolState(Aliasee);
- switch (state) {
- case RecordStreamer::Global:
- case RecordStreamer::DefinedGlobal:
- Attr = MCSA_Global;
- break;
- case RecordStreamer::UndefinedWeak:
- case RecordStreamer::DefinedWeak:
- Attr = MCSA_Weak;
- break;
- default:
- break;
- }
-
- // If we don't have a symbol attribute from assembly, then check if
- // the aliasee was defined in the IR.
- if (Attr == MCSA_Invalid) {
- const auto *GV = M.getNamedValue(Aliasee->getName());
- if (!GV) {
- auto MI = MangledNameMap.find(Aliasee->getName());
- if (MI != MangledNameMap.end())
- GV = MI->second;
- else
- continue;
- }
- if (GV->hasExternalLinkage())
- Attr = MCSA_Global;
- else if (GV->hasLocalLinkage())
- Attr = MCSA_Local;
- else if (GV->isWeakForLinker())
- Attr = MCSA_Weak;
- }
- if (Attr == MCSA_Invalid)
- continue;
-
- // Set the detected binding on each alias with this aliasee.
- for (auto &Alias : Symver.second)
- Streamer.EmitSymbolAttribute(Alias, Attr);
- }
-}
-
void ModuleSymbolTable::CollectAsmSymbols(
const Module &M,
function_ref<void(StringRef, BasicSymbolRef::Flags)> AsmSymbol) {
@@ -176,7 +100,7 @@ void ModuleSymbolTable::CollectAsmSymbols(
MCObjectFileInfo MOFI;
MCContext MCCtx(MAI.get(), MRI.get(), &MOFI);
MOFI.InitMCObjectFileInfo(TT, /*PIC*/ false, MCCtx);
- RecordStreamer Streamer(MCCtx);
+ RecordStreamer Streamer(MCCtx, M);
T->createNullTargetStreamer(Streamer);
std::unique_ptr<MemoryBuffer> Buffer(MemoryBuffer::getMemBuffer(InlineAsm));
@@ -195,7 +119,7 @@ void ModuleSymbolTable::CollectAsmSymbols(
if (Parser->Run(false))
return;
- handleSymverAliases(M, Streamer);
+ Streamer.flushSymverDirectives();
for (auto &KV : Streamer) {
StringRef Key = KV.first();