[PATCH] D55573: [MachO][TLOF] Add support for local symbols in the indirect symbol table
Francis Visoiu Mistrih via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 11 13:08:32 PST 2018
thegameg created this revision.
thegameg added reviewers: kledzik, steven_wu, dexonsmith, bruno.
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.
https://reviews.llvm.org/D55573
Files:
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
test/MC/MachO/cstexpr-gotpcrel-32.ll
Index: test/MC/MachO/cstexpr-gotpcrel-32.ll
===================================================================
--- test/MC/MachO/cstexpr-gotpcrel-32.ll
+++ test/MC/MachO/cstexpr-gotpcrel-32.ll
@@ -72,3 +72,24 @@
i32 ptrtoint (i32 (i32)* @t0 to i32)), %a
ret i32 %x
}
+
+; Text indirect local symbols.
+; CHECK-LABEL: _localindirect
+; CHECK: .long 65603
+ at localindirect = internal constant i32 65603
+ at got.localindirect = private unnamed_addr constant i32* @localindirect
+
+; CHECK-LABEL: _localindirectuser:
+; CHECK: .long L_localindirect$non_lazy_ptr-_localindirectuser
+ at localindirectuser = internal constant
+ i32 sub (i32 ptrtoint (i32** @got.localindirect to i32),
+ i32 ptrtoint (i32* @localindirectuser to i32))
+
+; CHECK-LABEL: L_localindirect$non_lazy_ptr:
+; CHECK: .indirect_symbol _localindirect
+; CHECK-NOT: .long 0
+; CHECK-NEXT: .long _localindirect
+define i8* @testRelativeIndirectSymbol() {
+ %1 = bitcast i32* @localindirectuser to i8*
+ ret i8* %1
+}
Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1119,9 +1119,12 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55573.177764.patch
Type: text/x-patch
Size: 1966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181211/b9a72b9a/attachment.bin>
More information about the llvm-commits
mailing list