Skip to content

Commit

Permalink
generator/linux: copy ELF interpreter from architecture-specific loca…
Browse files Browse the repository at this point in the history
…tions

Issue swiftlang#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 swiftlang#147.   Compared to swiftlang#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: swiftlang#147
  • Loading branch information
euanh committed Nov 25, 2024
1 parent b7cf646 commit e690ad4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 18 additions & 0 deletions Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ extension SwiftSDKGenerator {
}
try await generator.createSymlink(at: sdkDirPath.appending("lib"), pointingTo: "usr/lib")

// Copy the dynamic linker, following symlinks if necessary
try await generator.copyFromDockerContainer(
id: containerID,
from: FilePath(targetTriple.interpreterPath),
to: sdkDirPath.appending(targetTriple.interpreterPath),
failIfNotExists: true
)

// Python artifacts are redundant.
try await generator.removeRecursively(at: sdkUsrLibPath.appending("python3.10"))

Expand All @@ -109,3 +117,13 @@ extension SwiftSDKGenerator {
}
}
}

extension Triple {
var interpreterPath: String {
switch self.archName {
case "x86_64": "/lib64/ld-linux-x86-64.so.2"
case "aarch64": "/lib/ld-linux-aarch64.so.1"
default: fatalError("unsupported architecture \(self.archName)")
}
}
}
6 changes: 1 addition & 5 deletions Tests/SwiftSDKGeneratorTests/EndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ final class Swift59_UbuntuEndToEndTests: XCTestCase {
}

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

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

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

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

func testAarch64FromContainer() async throws {
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/147")
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/152")
try skipSlow()
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
}
Expand Down

0 comments on commit e690ad4

Please sign in to comment.