forked from OSchip/llvm-project
[JITLink][MachO] Re-apply b64afadf30
, MachO linker-private support, with fixes.
Global symbols with linker-private prefixes should be resolvable across object boundaries, but internal symbols with linker-private prefixes should not.
This commit is contained in:
parent
4dfe92e465
commit
9c9eb60b4b
|
@ -64,12 +64,14 @@ Linkage MachOLinkGraphBuilder::getLinkage(uint16_t Desc) {
|
|||
}
|
||||
|
||||
Scope MachOLinkGraphBuilder::getScope(StringRef Name, uint8_t Type) {
|
||||
if (Name.startswith("l"))
|
||||
return Scope::Local;
|
||||
if (Type & MachO::N_PEXT)
|
||||
return Scope::Hidden;
|
||||
if (Type & MachO::N_EXT)
|
||||
return Scope::Default;
|
||||
if (Type & MachO::N_EXT) {
|
||||
if (Name.startswith("l"))
|
||||
return Scope::Hidden;
|
||||
else
|
||||
return Scope::Default;
|
||||
}
|
||||
return Scope::Local;
|
||||
}
|
||||
|
||||
|
|
|
@ -560,7 +560,8 @@ private:
|
|||
*(ulittle32_t *)FixupPtr = Value;
|
||||
break;
|
||||
}
|
||||
case Pointer64: {
|
||||
case Pointer64:
|
||||
case Pointer64Anon: {
|
||||
uint64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
*(ulittle64_t *)FixupPtr = Value;
|
||||
break;
|
||||
|
|
|
@ -89,6 +89,8 @@ getObjectSymbolInfo(ExecutionSession &ES, MemoryBufferRef ObjBuffer) {
|
|||
if (!Obj)
|
||||
return Obj.takeError();
|
||||
|
||||
bool IsMachO = isa<object::MachOObjectFile>(Obj->get());
|
||||
|
||||
SymbolFlagsMap SymbolFlags;
|
||||
for (auto &Sym : (*Obj)->symbols()) {
|
||||
// Skip symbols not defined in this object file.
|
||||
|
@ -113,14 +115,20 @@ getObjectSymbolInfo(ExecutionSession &ES, MemoryBufferRef ObjBuffer) {
|
|||
auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym);
|
||||
if (!SymFlags)
|
||||
return SymFlags.takeError();
|
||||
|
||||
// Strip the 'exported' flag from MachO linker-private symbols.
|
||||
if (IsMachO && Name->startswith("l"))
|
||||
*SymFlags &= ~JITSymbolFlags::Exported;
|
||||
|
||||
SymbolFlags[InternedName] = std::move(*SymFlags);
|
||||
}
|
||||
|
||||
SymbolStringPtr InitSymbol;
|
||||
|
||||
if (auto *MachOObj = dyn_cast<object::MachOObjectFile>(Obj->get())) {
|
||||
for (auto &Sec : MachOObj->sections()) {
|
||||
auto SecType = MachOObj->getSectionType(Sec);
|
||||
if (IsMachO) {
|
||||
auto &MachOObj = cast<object::MachOObjectFile>(*Obj->get());
|
||||
for (auto &Sec : MachOObj.sections()) {
|
||||
auto SecType = MachOObj.getSectionType(Sec);
|
||||
if ((SecType & MachO::SECTION_TYPE) == MachO::S_MOD_INIT_FUNC_POINTERS) {
|
||||
std::string InitSymString;
|
||||
raw_string_ostream(InitSymString)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# Supplies a global definition, l_foo, with a linker-private prefix. Since this
|
||||
# definition is marked as global it should be resolvable outside the object.
|
||||
|
||||
.section __TEXT,__text,regular,pure_instructions
|
||||
.macosx_version_min 10, 14
|
||||
.globl l_foo
|
||||
.p2align 4, 0x90
|
||||
l_foo:
|
||||
xorl %eax, %eax
|
||||
retq
|
||||
|
||||
.subsections_via_symbols
|
|
@ -0,0 +1,12 @@
|
|||
# Supplies an internal definition, l_foo, with a linker-private prefix. Since
|
||||
# this definition is not marked as global it should not be resolvable outside
|
||||
# the object.
|
||||
|
||||
.section __TEXT,__text,regular,pure_instructions
|
||||
.macosx_version_min 10, 14
|
||||
.p2align 4, 0x90
|
||||
l_foo:
|
||||
xorl %eax, %eax
|
||||
retq
|
||||
|
||||
.subsections_via_symbols
|
|
@ -0,0 +1,22 @@
|
|||
# RUN: rm -rf %t && mkdir -p %t
|
||||
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj \
|
||||
# RUN: -o %t/global_lp_def.o %S/Inputs/MachO_global_linker_private_def.s
|
||||
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj \
|
||||
# RUN: -o %t/internal_lp_def.o %S/Inputs/MachO_internal_linker_private_def.s
|
||||
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj \
|
||||
# RUN: -o %t/macho_lp_test.o %s
|
||||
# RUN: llvm-jitlink -noexec %t/global_lp_def.o %t/macho_lp_test.o
|
||||
# RUN: not llvm-jitlink -noexec %t/internal_lp_def.o %t/macho_lp_test.o
|
||||
#
|
||||
# Check that we can resolve global symbols whose names start with the
|
||||
# linker-private prefix 'l' across object boundaries, and that we can't resolve
|
||||
# internals with the linker-private prefix across object boundaries.
|
||||
|
||||
.section __TEXT,__text,regular,pure_instructions
|
||||
.macosx_version_min 10, 14
|
||||
.globl _main
|
||||
.p2align 4, 0x90
|
||||
_main:
|
||||
jmp l_foo
|
||||
|
||||
.subsections_via_symbols
|
Loading…
Reference in New Issue