Skip to content

Commit 7c02f8c

Browse files
rmazIanWood1
authored andcommitted
[lld] handle re-exports for full framework paths (llvm#137989)
Framework load paths can be either the top level framework name, or subpaths of the framework bundle pointing to specific framework binary versions. Extend the framework lookup logic to handle the latter case.
1 parent d383887 commit 7c02f8c

File tree

2 files changed

+129
-5
lines changed

2 files changed

+129
-5
lines changed

lld/MachO/InputFiles.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,14 +1580,19 @@ static DylibFile *findDylib(StringRef path, DylibFile *umbrella,
15801580
// Search order:
15811581
// 1. Install name basename in -F / -L directories.
15821582
{
1583+
// Framework names can be in multiple formats:
1584+
// - Foo.framework/Foo
1585+
// - Foo.framework/Versions/A/Foo
15831586
StringRef stem = path::stem(path);
1584-
SmallString<128> frameworkName;
1585-
path::append(frameworkName, path::Style::posix, stem + ".framework", stem);
1586-
bool isFramework = path.ends_with(frameworkName);
1587-
if (isFramework) {
1587+
SmallString<128> frameworkName("/");
1588+
frameworkName += stem;
1589+
frameworkName += ".framework/";
1590+
size_t i = path.rfind(frameworkName);
1591+
if (i != StringRef::npos) {
1592+
StringRef frameworkPath = path.substr(i + 1);
15881593
for (StringRef dir : config->frameworkSearchPaths) {
15891594
SmallString<128> candidate = dir;
1590-
path::append(candidate, frameworkName);
1595+
path::append(candidate, frameworkPath);
15911596
if (std::optional<StringRef> dylibPath =
15921597
resolveDylibPath(candidate.str()))
15931598
return loadDylib(*dylibPath, umbrella);
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# REQUIRES: aarch64, shell
2+
# RUN: rm -rf %t; split-file %s %t
3+
# RUN: ln -s Versions/A/Developer %t/Developer/Library/Frameworks/Developer.framework/
4+
# RUN: ln -s Versions/A/DeveloperCore %t/Developer/Library/PrivateFrameworks/DeveloperCore.framework/
5+
# RUN: llvm-mc -filetype obj -triple arm64-apple-macos11.0 %t/test.s -o %t/test.o
6+
# RUN: %lld -arch arm64 -platform_version macos 11.0 11.0 -o %t/test -framework Developer -F %t/Developer/Library/Frameworks -L %t/Developer/usr/lib %t/test.o
7+
# RUN: llvm-objdump --bind --no-show-raw-insn -d %t/test | FileCheck %s
8+
# CHECK: Bind table:
9+
# CHECK-DAG: __DATA __data {{.*}} pointer 0 Developer _funcPublic
10+
# CHECK-DAG: __DATA __data {{.*}} pointer 0 Developer _funcCore
11+
# CHECK-DAG: __DATA __data {{.*}} pointer 0 libDeveloperSupport _funcSupport
12+
13+
#--- Developer/Library/Frameworks/Developer.framework/Versions/A/Developer
14+
{
15+
"tapi_tbd_version": 5,
16+
"main_library": {
17+
"target_info": [
18+
{
19+
"target": "arm64-macos"
20+
}
21+
],
22+
"install_names": [
23+
{
24+
"name": "@rpath/Developer.framework/Versions/A/Developer"
25+
}
26+
],
27+
"rpaths": [
28+
{
29+
"paths": [
30+
"@loader_path/../../../../PrivateFrameworks/"
31+
]
32+
}
33+
],
34+
"reexported_libraries": [
35+
{
36+
"names": [
37+
"@rpath/DeveloperCore.framework/Versions/A/DeveloperCore"
38+
]
39+
}
40+
],
41+
"exported_symbols": [
42+
{
43+
"text": {
44+
"global": ["_funcPublic"]
45+
}
46+
}
47+
]
48+
}
49+
}
50+
#--- Developer/Library/PrivateFrameworks/DeveloperCore.framework/Versions/A/DeveloperCore
51+
{
52+
"tapi_tbd_version": 5,
53+
"main_library": {
54+
"target_info": [
55+
{
56+
"target": "arm64-macos"
57+
}
58+
],
59+
"install_names": [
60+
{
61+
"name": "@rpath/DeveloperCore.framework/Versions/A/DeveloperCore"
62+
}
63+
],
64+
"allowable_clients": [
65+
{
66+
"clients": ["Developer"]
67+
}
68+
],
69+
"exported_symbols": [
70+
{
71+
"text": {
72+
"global": ["_funcCore"]
73+
}
74+
}
75+
]
76+
}
77+
}
78+
#--- Developer/usr/lib/libDeveloperSupport.tbd
79+
{
80+
"tapi_tbd_version": 5,
81+
"main_library": {
82+
"target_info": [
83+
{
84+
"target": "arm64-macos"
85+
}
86+
],
87+
"install_names": [
88+
{
89+
"name": "@rpath/libDeveloperSupport.dylib"
90+
}
91+
],
92+
"reexported_libraries": [
93+
{
94+
"names": [
95+
"@rpath/Developer.framework/Versions/A/Developer"
96+
]
97+
}
98+
],
99+
"exported_symbols": [
100+
{
101+
"text": {
102+
"global": ["_funcSupport"]
103+
}
104+
}
105+
]
106+
}
107+
}
108+
#--- test.s
109+
.text
110+
.globl _main
111+
.linker_option "-lDeveloperSupport"
112+
113+
_main:
114+
ret
115+
116+
.data
117+
.quad _funcPublic
118+
.quad _funcCore
119+
.quad _funcSupport

0 commit comments

Comments
 (0)