summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>2018-12-13 17:23:30 +0000
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>2018-12-13 17:23:30 +0000
commit91e69d8a929c25fb94c6f3b8efe2160d987e5562 (patch)
tree6edff0063fa6d1965e0dfe32180118a416a1e977 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
parent0250e29e50da8a0cd4572fe0ca0079c1995c69d9 (diff)
downloadbcm5719-llvm-91e69d8a929c25fb94c6f3b8efe2160d987e5562.tar.gz
bcm5719-llvm-91e69d8a929c25fb94c6f3b8efe2160d987e5562.zip
[MachO][TLOF] Add support for local symbols in the indirect symbol table
On 32-bit archs, before, we would assume that an indirect symbol will never have local linkage. This can lead to miscompiles where the symbol's value would be 0 and the linker would use that value, because the indirect symbol table would contain the value `INDIRECT_SYMBOL_LOCAL` for that specific symbol. Differential Revision: https://reviews.llvm.org/D55573 llvm-svn: 349060
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 5f4421f5433..394281e3329 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1100,6 +1100,22 @@ const MCExpr *TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel(
// .indirect_symbol _extfoo
// .long 0
//
+ // The indirect symbol table (and sections of non_lazy_symbol_pointers type)
+ // may point to both local (same translation unit) and global (other
+ // translation units) symbols. Example:
+ //
+ // .section __DATA,__pointers,non_lazy_symbol_pointers
+ // L1:
+ // .indirect_symbol _myGlobal
+ // .long 0
+ // L2:
+ // .indirect_symbol _myLocal
+ // .long _myLocal
+ //
+ // If the symbol is local, instead of the symbol's index, the assembler
+ // places the constant INDIRECT_SYMBOL_LOCAL into the indirect symbol table.
+ // Then the linker will notice the constant in the table and will look at the
+ // content of the symbol.
MachineModuleInfoMachO &MachOMMI =
MMI->getObjFileInfo<MachineModuleInfoMachO>();
MCContext &Ctx = getContext();
@@ -1119,9 +1135,12 @@ const MCExpr *TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel(
MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Stub);
- if (!StubSym.getPointer())
- StubSym = MachineModuleInfoImpl::
- StubValueTy(const_cast<MCSymbol *>(Sym), true /* access indirectly */);
+ if (!StubSym.getPointer()) {
+ bool IsIndirectLocal = Sym->isDefined() && !Sym->isExternal();
+ // With the assumption that IsIndirectLocal == GV->hasLocalLinkage().
+ StubSym = MachineModuleInfoImpl::StubValueTy(const_cast<MCSymbol *>(Sym),
+ !IsIndirectLocal);
+ }
const MCExpr *BSymExpr =
MCSymbolRefExpr::create(BaseSym, MCSymbolRefExpr::VK_None, Ctx);
OpenPOWER on IntegriCloud