Skip to content

Commit 1422de0

Browse files
authored
Merge pull request #738 from buttaface/elf-rpath
[5.5] Enable checking for -no-toolchain-stdlib-rpath and use it on this repo's binaries before installing
2 parents c5d858b + 6905cd9 commit 1422de0

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ extension GenericUnixToolchain {
124124
let staticExecutable = parsedOptions.hasFlag(positive: .staticExecutable,
125125
negative: .noStaticExecutable,
126126
default: false)
127+
let toolchainStdlibRpath = parsedOptions
128+
.hasFlag(positive: .toolchainStdlibRpath,
129+
negative: .noToolchainStdlibRpath,
130+
default: true)
127131
let hasRuntimeArgs = !(staticStdlib || staticExecutable)
128132

129133
let runtimePaths = try runtimeLibraryPaths(
@@ -133,7 +137,8 @@ extension GenericUnixToolchain {
133137
isShared: hasRuntimeArgs
134138
)
135139

136-
if hasRuntimeArgs && targetTriple.environment != .android {
140+
if hasRuntimeArgs && targetTriple.environment != .android &&
141+
toolchainStdlibRpath {
137142
// FIXME: We probably shouldn't be adding an rpath here unless we know
138143
// ahead of time the standard library won't be copied.
139144
for path in runtimePaths {

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,16 @@ final class SwiftDriverTests: XCTestCase {
11211121
}
11221122
#endif
11231123

1124+
do {
1125+
var driver = try Driver(args: commonArgs + ["-emit-library", "-no-toolchain-stdlib-rpath",
1126+
"-target", "aarch64-unknown-linux"], env: env)
1127+
let plannedJobs = try driver.planBuild()
1128+
XCTAssertEqual(plannedJobs.count, 4)
1129+
let linkJob = plannedJobs[3]
1130+
let cmd = linkJob.commandLine
1131+
XCTAssertFalse(cmd.contains(subsequence: [.flag("-Xlinker"), .flag("-rpath"), .flag("-Xlinker")]))
1132+
}
1133+
11241134
do {
11251135
// Object file inputs
11261136
var driver = try Driver(args: commonArgs + ["baz.o", "-emit-library", "-target", "x86_64-apple-macosx10.15"], env: env)

Utilities/build-script-helper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def get_swiftpm_options(args):
109109
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
110110
]
111111

112+
if args.action == 'install':
113+
swiftpm_args += ['-Xswiftc', '-no-toolchain-stdlib-rpath']
114+
112115
return swiftpm_args
113116

114117
def install_binary(file, source_dir, install_dir, verbose):

0 commit comments

Comments
 (0)