mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
[JITLink][MachO] Treat linker private symbols as hidden rather than private.
Linker-private symbols should be resolvable across object file boundaries.
This commit is contained in:
parent
da59eff7c0
commit
16ceeef4af
@ -64,9 +64,7 @@ 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)
|
||||
if (Name.startswith("l") || (Type & MachO::N_PEXT))
|
||||
return Scope::Hidden;
|
||||
if (Type & MachO::N_EXT)
|
||||
return Scope::Default;
|
||||
|
@ -89,14 +89,25 @@ 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.
|
||||
if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined)
|
||||
continue;
|
||||
|
||||
// Skip symbols that are not global.
|
||||
if (!(Sym.getFlags() & object::BasicSymbolRef::SF_Global))
|
||||
// Get the symbol name.
|
||||
auto Name = Sym.getName();
|
||||
if (!Name)
|
||||
return Name.takeError();
|
||||
|
||||
bool IsLinkerPrivate = IsMachO && Name->startswith("l");
|
||||
|
||||
// Skip symbols that are not global. Treat linker private symbols as global
|
||||
// hidden.
|
||||
if (!(Sym.getFlags() & object::BasicSymbolRef::SF_Global) &&
|
||||
!IsLinkerPrivate)
|
||||
continue;
|
||||
|
||||
// Skip symbols that have type SF_File.
|
||||
@ -106,9 +117,6 @@ getObjectSymbolInfo(ExecutionSession &ES, MemoryBufferRef ObjBuffer) {
|
||||
} else
|
||||
return SymType.takeError();
|
||||
|
||||
auto Name = Sym.getName();
|
||||
if (!Name)
|
||||
return Name.takeError();
|
||||
auto InternedName = ES.intern(*Name);
|
||||
auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym);
|
||||
if (!SymFlags)
|
||||
@ -118,9 +126,10 @@ getObjectSymbolInfo(ExecutionSession &ES, MemoryBufferRef ObjBuffer) {
|
||||
|
||||
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,10 @@
|
||||
# Supplies a linker private definition, "l_foo".
|
||||
|
||||
.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,19 @@
|
||||
# RUN: rm -rf %t && mkdir -p %t
|
||||
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj \
|
||||
# RUN: -o %t/MachO_linker_private_def.o %S/Inputs/MachO_linker_private_def.s
|
||||
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj \
|
||||
# RUN: -o %t/MachO_linker_private_symbols.o %s
|
||||
# RUN: llvm-jitlink -noexec %t/MachO_linker_private_def.o \
|
||||
# RUN: %t/MachO_linker_private_symbols.o
|
||||
#
|
||||
# Check that we can resolve linker-private symbol definitions 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
Block a user