Skip to content

Commit e7e6f15

Browse files
committed
[lld][MachO] Respect allowable-clients field in .tbds
Closes #114146.
1 parent 316ee58 commit e7e6f15

File tree

2 files changed

+74
-9
lines changed

2 files changed

+74
-9
lines changed

lld/MachO/InputFiles.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,12 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella,
18991899
exportingFile = (canBeImplicitlyLinked && isImplicitlyLinked(installName))
19001900
? this
19011901
: umbrella;
1902+
1903+
if (!canBeImplicitlyLinked)
1904+
for (const auto &allowableClient : interface.allowableClients())
1905+
allowableClients.push_back(
1906+
*make<std::string>(allowableClient.getInstallName().data()));
1907+
19021908
auto addSymbol = [&](const llvm::MachO::Symbol &symbol,
19031909
const Twine &name) -> void {
19041910
StringRef savedName = saver().save(name);

lld/test/MachO/allowable-client.s

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,74 @@
11
# REQUIRES: x86
2-
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
3-
# RUN: not %lld -o %t %t.o -L%S/Inputs -lallowable_client 2>&1 | FileCheck %s --check-prefix=NOTALLOWED1
4-
# RUN: not %lld -o %t %t.o -L%S/Inputs -lallowable_client -client_name notallowed 2>&1 | FileCheck %s --check-prefix=NOTALLOWED2
5-
# RUN: %lld -o %t %t.o -L%S/Inputs -lallowable_client -client_name allowed
6-
# RUN: %lld -o %t %t.o -L%S/Inputs -lallowable_client -client_name all
2+
# RUN: rm -rf %t; split-file %s %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
74

8-
# NOTALLOWED1: error: cannot link directly with 'liballowable_client.dylib' because {{.*}} is not an allowed client
9-
# NOTALLOWED2: error: cannot link directly with 'liballowable_client.dylib' because notallowed is not an allowed client
5+
# Check linking against a .dylib
6+
# RUN: not %lld -o %t/test %t/test.o -L%S/Inputs -lallowable_client 2>&1 | FileCheck %s --check-prefix=NOTALLOWED-IMPLICIT
7+
# RUN: not %lld -o %t/libtest_debug.exe %t/test.o -L%S/Inputs -lallowable_client 2>&1 | FileCheck %s --check-prefix=NOTALLOWED-IMPLICIT
8+
# RUN: not %lld -o %t/test %t/test.o -L%S/Inputs -lallowable_client -client_name notallowed 2>&1 | FileCheck %s --check-prefix=NOTALLOWED-EXPLICIT
9+
# RUN: %lld -o %t/test %t/test.o -L%S/Inputs -lallowable_client -client_name allowed
10+
# RUN: %lld -o %t/test %t/test.o -L%S/Inputs -lallowable_client -client_name all
11+
# RUN: %lld -o %t/all %t/test.o -L%S/Inputs -lallowable_client
12+
# RUN: %lld -o %t/allowed %t/test.o -L%S/Inputs -lallowable_client
13+
# RUN: %lld -o %t/liballowed_debug.exe %t/test.o -L%S/Inputs -lallowable_client
1014

15+
# Check linking against a .tbd
16+
# RUN: not %lld -o %t/test %t/test.o -L%t -lallowable_client 2>&1 | FileCheck %s --check-prefix=NOTALLOWED-IMPLICIT
17+
# RUN: not %lld -o %t/libtest_debug.exe %t/test.o -L%t -lallowable_client 2>&1 | FileCheck %s --check-prefix=NOTALLOWED-IMPLICIT
18+
# RUN: not %lld -o %t/test %t/test.o -L%t -lallowable_client -client_name notallowed 2>&1 | FileCheck %s --check-prefix=NOTALLOWED-EXPLICIT
19+
# RUN: %lld -o %t/test %t/test.o -L%t -lallowable_client -client_name allowed
20+
# RUN: %lld -o %t/test %t/test.o -L%t -lallowable_client -client_name all
21+
# RUN: %lld -o %t/all %t/test.o -L%t -lallowable_client
22+
# RUN: %lld -o %t/allowed %t/test.o -L%t -lallowable_client
23+
# RUN: %lld -o %t/liballowed_debug.exe %t/test.o -L%t -lallowable_client
24+
25+
# NOTALLOWED-IMPLICIT: error: cannot link directly with 'liballowable_client.dylib' because test is not an allowed client
26+
# NOTALLOWED-EXPLICIT: error: cannot link directly with 'liballowable_client.dylib' because notallowed is not an allowed client
27+
28+
#--- test.s
1129
.text
12-
.global _main
30+
.globl _main
1331
_main:
14-
mov $0, %rax
1532
ret
33+
34+
#--- liballowable_client.tbd
35+
{
36+
"main_library": {
37+
"allowable_clients": [
38+
{
39+
"clients": [
40+
"allowed"
41+
]
42+
}
43+
],
44+
"compatibility_versions": [
45+
{
46+
"version": "0"
47+
}
48+
],
49+
"current_versions": [
50+
{
51+
"version": "0"
52+
}
53+
],
54+
"flags": [
55+
{
56+
"attributes": [
57+
"not_app_extension_safe"
58+
]
59+
}
60+
],
61+
"install_names": [
62+
{
63+
"name": "lib/liballowable_client.dylib"
64+
}
65+
],
66+
"target_info": [
67+
{
68+
"min_deployment": "10.11",
69+
"target": "x86_64-macos"
70+
}
71+
]
72+
},
73+
"tapi_tbd_version": 5
74+
}

0 commit comments

Comments
 (0)