}
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;
}
*(ulittle32_t *)FixupPtr = Value;
break;
}
- case Pointer64: {
+ case Pointer64:
+ case Pointer64Anon: {
uint64_t Value = E.getTarget().getAddress() + E.getAddend();
*(ulittle64_t *)FixupPtr = Value;
break;
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.
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)
--- /dev/null
+# 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
--- /dev/null
+# 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
--- /dev/null
+# 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