forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ORC][llvm-jitlink] Add support for emulating ld64 -weak-lx / -weak_l…
…ibrary. Linking libraries in ld64 with -weak-lx / -weak_library causes all references to symbols in those libraries to be made weak, allowing the librarie to be missing at runtime. This patch extends EPCDynamicLibrarySearchGenerator with support for emulating this behavior: If an instance is constructed with an Allow predicate but no dylib handle then all symbols matching the predicate are immediately resolved to null. The llvm-jitlink tool is updated with -weak-lx / -weak_library options for testing. Unlike their ld64 counterparts these options take a TBD file as input, and always resolve all exports in the TBD file to null.
- Loading branch information
Showing
9 changed files
with
241 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===---- GetTapiInterface.h -- Get interface from TAPI file ----*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Get symbol interface from TAPI file. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_EXECUTIONENGINE_ORC_GETTAPIINTERFACE_H | ||
#define LLVM_EXECUTIONENGINE_ORC_GETTAPIINTERFACE_H | ||
|
||
#include "llvm/ExecutionEngine/Orc/Core.h" | ||
#include "llvm/Object/TapiUniversal.h" | ||
|
||
namespace llvm::orc { | ||
|
||
/// Returns a SymbolNameSet containing the exported symbols defined in the | ||
/// relevant slice of the TapiUniversal file. | ||
Expected<SymbolNameSet> getInterfaceFromTapiFile(ExecutionSession &ES, | ||
object::TapiUniversal &TU); | ||
|
||
} // namespace llvm::orc | ||
|
||
#endif // LLVM_EXECUTIONENGINE_ORC_GETTAPIINTERFACE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===--------- GetTapiInterface.cpp - Get interface from TAPI file --------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/ExecutionEngine/Orc/GetTapiInterface.h" | ||
|
||
#define DEBUG_TYPE "orc" | ||
|
||
namespace llvm::orc { | ||
|
||
Expected<SymbolNameSet> getInterfaceFromTapiFile(ExecutionSession &ES, | ||
object::TapiUniversal &TU) { | ||
SymbolNameSet Symbols; | ||
|
||
auto CPUType = MachO::getCPUType(ES.getTargetTriple()); | ||
if (!CPUType) | ||
return CPUType.takeError(); | ||
|
||
auto CPUSubType = MachO::getCPUSubType(ES.getTargetTriple()); | ||
if (!CPUSubType) | ||
return CPUSubType.takeError(); | ||
|
||
auto &TUIF = TU.getInterfaceFile(); | ||
auto ArchInterface = | ||
TUIF.extract(MachO::getArchitectureFromCpuType(*CPUType, *CPUSubType)); | ||
if (!ArchInterface) | ||
return ArchInterface.takeError(); | ||
|
||
for (auto *Sym : (*ArchInterface)->exports()) | ||
Symbols.insert(ES.intern(Sym->getName())); | ||
|
||
return Symbols; | ||
} | ||
|
||
} // namespace llvm::orc |
23 changes: 23 additions & 0 deletions
23
llvm/test/ExecutionEngine/JITLink/AArch64/Inputs/MachO_Foo.tbd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- !tapi-tbd | ||
tbd-version: 4 | ||
targets: [ arm64-macos ] | ||
uuids: | ||
- target: arm64-macos | ||
value: 00000000-0000-0000-0000-000000000000 | ||
flags: [ installapi ] | ||
install-name: Foo.framework/Foo | ||
current-version: 1.2.3 | ||
compatibility-version: 1.2 | ||
swift-abi-version: 5 | ||
parent-umbrella: | ||
- targets: [ arm64-macos ] | ||
umbrella: System | ||
exports: | ||
- targets: [ arm64-macos ] | ||
symbols: [ _foo ] | ||
objc-classes: [] | ||
objc-eh-types: [] | ||
objc-ivars: [] | ||
weak-symbols: [] | ||
thread-local-symbols: [] | ||
... |
15 changes: 15 additions & 0 deletions
15
llvm/test/ExecutionEngine/JITLink/AArch64/Inputs/MachO_main_ret_foo.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.section __TEXT,__text,regular,pure_instructions | ||
.globl _main | ||
.p2align 2 | ||
_main: | ||
.cfi_startproc | ||
Lloh0: | ||
adrp x0, _foo@GOTPAGE | ||
Lloh1: | ||
ldr x0, [x0, _foo@GOTPAGEOFF] | ||
|
||
ret | ||
.loh AdrpLdrGot Lloh0, Lloh1 | ||
.cfi_endproc | ||
|
||
.subsections_via_symbols |
8 changes: 8 additions & 0 deletions
8
llvm/test/ExecutionEngine/JITLink/AArch64/MachO_weak_link.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# RUN: rm -rf %t && mkdir -p %t | ||
# RUN: llvm-mc -triple=arm64-apple-darwin19 -filetype=obj -o %t/main.o \ | ||
# RUN: %S/Inputs/MachO_main_ret_foo.s | ||
# RUN: llvm-jitlink -noexec %t/main.o -weak_library %S/Inputs/MachO_Foo.tbd | ||
|
||
# Check that we can load main.o, which unconditionally uses symbol foo, by | ||
# using -weak_library on a TBD file to emulate forced weak linking against | ||
# a library that supplies foo, but is missing at runtime. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters