X86: emit hidden stubs into a proper non_lazy_symbol_pointer section.

rdar://problem/16660411

llvm-svn: 207518
This commit is contained in:
Tim Northover 2014-04-29 10:06:10 +00:00
parent 2372301bcf
commit 9e7782dcf3
2 changed files with 78 additions and 31 deletions

View File

@ -527,6 +527,30 @@ void X86AsmPrinter::EmitStartOfAsmFile(Module &M) {
}
}
static void
emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
MachineModuleInfoImpl::StubValueTy &MCSym) {
// L_foo$stub:
OutStreamer.EmitLabel(StubLabel);
// .indirect_symbol _foo
OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
if (MCSym.getInt())
// External to current translation unit.
OutStreamer.EmitIntValue(0, 4/*size*/);
else
// Internal to current translation unit.
//
// When we place the LSDA into the TEXT section, the type info
// pointers need to be indirect and pc-rel. We accomplish this by
// using NLPs; however, sometimes the types are local to the file.
// We need to fill in the value for the NLP in those cases.
OutStreamer.EmitValue(
MCSymbolRefExpr::Create(MCSym.getPointer(), OutStreamer.getContext()),
4 /*size*/);
}
void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
if (Subtarget->isTargetMacho()) {
@ -571,44 +595,24 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
SectionKind::getMetadata());
OutStreamer.SwitchSection(TheSection);
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
// L_foo$non_lazy_ptr:
OutStreamer.EmitLabel(Stubs[i].first);
// .indirect_symbol _foo
MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second;
OutStreamer.EmitSymbolAttribute(MCSym.getPointer(),
MCSA_IndirectSymbol);
// .long 0
if (MCSym.getInt())
// External to current translation unit.
OutStreamer.EmitIntValue(0, 4/*size*/);
else
// Internal to current translation unit.
//
// When we place the LSDA into the TEXT section, the type info
// pointers need to be indirect and pc-rel. We accomplish this by
// using NLPs. However, sometimes the types are local to the file. So
// we need to fill in the value for the NLP in those cases.
OutStreamer.EmitValue(MCSymbolRefExpr::Create(MCSym.getPointer(),
OutContext), 4/*size*/);
}
for (auto &Stub : Stubs)
emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
Stubs.clear();
OutStreamer.AddBlankLine();
}
Stubs = MMIMacho.GetHiddenGVStubList();
if (!Stubs.empty()) {
OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
EmitAlignment(2);
const MCSection *TheSection =
OutContext.getMachOSection("__IMPORT", "__pointers",
MachO::S_NON_LAZY_SYMBOL_POINTERS,
SectionKind::getMetadata());
OutStreamer.SwitchSection(TheSection);
for (auto &Stub : Stubs)
emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
// L_foo$non_lazy_ptr:
OutStreamer.EmitLabel(Stubs[i].first);
// .long _foo
OutStreamer.EmitValue(MCSymbolRefExpr::
Create(Stubs[i].second.getPointer(),
OutContext), 4/*size*/);
}
Stubs.clear();
OutStreamer.AddBlankLine();
}

View File

@ -0,0 +1,43 @@
; RUN: llc -mtriple=i686-apple-macosx -o - %s | FileCheck %s
; x86 doesn't normally use indirect symbols, particularly hidden ones, but it
; can be tricked into it for exception-handling typeids.
@hidden_typeid = external hidden constant i8*
@normal_typeid = external constant i8*
declare void @throws()
define void @get_indirect_hidden() {
invoke void @throws() to label %end unwind label %lpad
lpad:
%tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
catch i8* bitcast (i8** @hidden_typeid to i8*)
br label %end
end:
ret void
}
define void @get_indirect() {
invoke void @throws() to label %end unwind label %lpad
lpad:
%tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
catch i8* bitcast (i8** @normal_typeid to i8*)
br label %end
end:
ret void
}
declare i32 @__gxx_personality_v0(...)
; CHECK: .section __IMPORT,__pointers,non_lazy_symbol_pointers
; CHECK-NOT: __DATA,__data
; CHECK: .indirect_symbol _normal_typeid
; CHECK-NEXT: .long 0
; CHECK-NOT: __DATA,__data
; CHECK: .indirect_symbol _hidden_typeid
; CHECK-NEXT: .long 0