Skip to content

Commit 6fb3fbc

Browse files
committed
generator/linux: copy ELF interpreter from architecture-specific locations
Issue #147 occurs because the ELF interpreter is found at different paths, and with different names, on different architectures. We happen to pick up the x86_64 interpreter because it is stored in /lib64, which we aready copy, but we miss the aarch64 interpreter. An ELF binary contains an interpreter path which can point anywhere, but there are defacto standard default locations. * According to https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf) the x86_64 / amd64 ABI specifies that the interpreter should be at /lib/ld64.so.1, but Linux overrides this and uses /lib64/ld-linux-x86-64.so.2. * I couldn't find a similar document for ARM64 / aarch64 - https://github.com/ARM-software/abi-aa/tree/main/aaelf64 is silent on the interpreter path - but most sources I could find place it at /lib/ld-linux-aarch64.so.1 - for example zulu-openjdk/zulu-openjdk#11 There is a pattern to the paths and filenames but it seems risky to try to construct them; instead this PR adds a new field to `Triple` which returns the default path for each architecture. For now we only support x86_64 and aarch64 - if new architectures are added in future we will need to add new entries for them. This change fixes issue #147. Compared to #153, all the basic 'hello world' tests now pass. The tests which import Foundation still fail on all Swift 6.0 SDKs. | SDK | Hello World | Foundation | | ----------------------------------------- | ----------- | ---------- | | ubuntu_aarch64_5.9.2-RELEASE | ok | ok | | ubuntu_aarch64_5.9.2-RELEASE_with-docker | ok | ok | | ubuntu_aarch64_5.10.1-RELEASE | ok | ok | | ubuntu_aarch64_5.10.1-RELEASE_with-docker | ok | ok | | ubuntu_aarch64_6.0.2-RELEASE | ok | FAIL2 | | ubuntu_aarch64_6.0.2-RELEASE_with-docker | ok | FAIL2 | | | | | | ubuntu_x86_64_5.9.2-RELEASE | ok | ok | | ubuntu_x86_64_5.9.2-RELEASE_with-docker | ok | ok | | ubuntu_x86_64_5.10.1-RELEASE | ok | ok | | ubuntu_x86_64_5.10.1-RELEASE_with-docker | ok | ok | | ubuntu_x86_64_6.0.2-RELEASE | ok | FAIL2 | | ubuntu_x86_64_6.0.2-RELEASE_with-docker | ok | FAIL2 | | | | | | rhel_aarch64_5.9.2-RELEASE_with-docker | ok | ok | | rhel_aarch64_5.10.1-RELEASE_with-docker | ok | ok | | rhel_aarch64_6.0.2-RELEASE_with-docker | ok | FAIL2 | | | | | | rhel_x86_64_5.9.2-RELEASE_with-docker | ok | ok | | rhel_x86_64_5.10.1-RELEASE_with-docker | ok | ok | | rhel_x86_64_6.0.2-RELEASE_with-docker | ok | FAIL2 | FAIL1: cannot find /lib/ld-linux-aarch64.so.1 FAIL2: missing required module '_FoundationCShims' Fixes: #147
1 parent 512bcaa commit 6fb3fbc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ extension SwiftSDKGenerator {
8585
}
8686
try await generator.createSymlink(at: sdkDirPath.appending("lib"), pointingTo: "usr/lib")
8787

88+
// Copy the ELF interpreter
89+
try await generator.copyFromDockerContainer(
90+
id: containerID,
91+
from: FilePath(targetTriple.interpreterPath),
92+
to: sdkDirPath.appending(targetTriple.interpreterPath),
93+
failIfNotExists: true
94+
)
95+
8896
// Python artifacts are redundant.
8997
try await generator.removeRecursively(at: sdkUsrLibPath.appending("python3.10"))
9098

@@ -109,3 +117,13 @@ extension SwiftSDKGenerator {
109117
}
110118
}
111119
}
120+
121+
extension Triple {
122+
var interpreterPath: String {
123+
switch self.archName {
124+
case "x86_64": "/lib64/ld-linux-x86-64.so.2"
125+
case "aarch64": "/lib/ld-linux-aarch64.so.1"
126+
default: fatalError("unsupported architecture \(self.archName)")
127+
}
128+
}
129+
}

Tests/SwiftSDKGeneratorTests/EndToEndTests.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ final class Swift59_UbuntuEndToEndTests: XCTestCase {
270270
}
271271

272272
func testAarch64FromContainer() async throws {
273-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/147")
274273
try skipSlow()
275274
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
276275
}
@@ -300,7 +299,6 @@ final class Swift510_UbuntuEndToEndTests: XCTestCase {
300299
}
301300

302301
func testAarch64FromContainer() async throws {
303-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/147")
304302
try skipSlow()
305303
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
306304
}
@@ -353,7 +351,6 @@ final class Swift59_RHELEndToEndTests: XCTestCase {
353351
)
354352

355353
func testAarch64FromContainer() async throws {
356-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/147")
357354
try skipSlow()
358355
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
359356
}
@@ -373,7 +370,6 @@ final class Swift510_RHELEndToEndTests: XCTestCase {
373370
)
374371

375372
func testAarch64FromContainer() async throws {
376-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/147")
377373
try skipSlow()
378374
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
379375
}
@@ -393,7 +389,7 @@ final class Swift60_RHELEndToEndTests: XCTestCase {
393389
)
394390

395391
func testAarch64FromContainer() async throws {
396-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/147")
392+
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/152")
397393
try skipSlow()
398394
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
399395
}

0 commit comments

Comments
 (0)