You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passing the -sdk flag to the trunk 6.1 compiler on linux has the driver and frontend looking in different directories for the same linux SDK overlay
#76381
Open
finagolfin opened this issue
Sep 10, 2024
· 0 comments
This is with no system Swift installed in /usr. If a system Swift 5.10 happens to be there, the link happens to pass because it uses the 5.10 /usr/lib/swift/linux/x86_64/swiftrt.o instead, but that is the wrong version and could break any time that object file changes. A local Swift 5.10 and a recent 6.0 snapshot don't have this problem, ie they don't look in /usr for an SDK overlay altogether.
There are two problems with the above commands in Swift 6.1:
Linking fails because the Swift compiler tells the linker to look for a swiftrt.o that doesn't exist.
The swift-frontend looks for the linux SDK overlay Swift modules in -resource-dir /home/finagolfin/swift-DEVELOPMENT-SNAPSHOT-2024-09-06-a-ubi9/usr/lib/swift/ and finds them, but the swift-driver tells clang to look for swiftrt.o from that same linux SDK overlay in /usr/lib/swift/linux/x86_64/ instead, which doesn't exist. In other words, the Swift compiler is looking in completely different directories for files from the same linux SDK.
This all appears to be a consequence of the recent push to change the meaning of certain core compilation flags, as detailed in #73581. Briefly, the goal outlined there is to change the currently used flags of -resource-dir and -sdk, which specify the paths to a platform SDK overlay and platform C/C++ sysroot respectively, to the flags -sdk and -sysroot instead, ie -sdk now points at the platform SDK overlay and -sysroot at the platform C/C++ sysroot.
I am fine with this transition in principle, but we need to handle the actual implementation more carefully or very basic commands like this are going to break without explanation. This particular change was made in swiftlang/swift-driver#1560, which I argued against strongly at that time.
Reproduction
See command above
Expected behavior
Everything compiles fine or user is told what they did wrong.
Environment
Fedora 40 linux x86_64
Additional information
There are two ways we could handle this planned transition, which so far has only been partially implemented for non-Darwin platforms:
a) Tell everyone to use the new set of flags and have things randomly break like this if they use the old flags.
b) Put in some logic to guess what the user is trying to do, then try to either translate the flags based on context or give them better error messages on what they're doing wrong.
If we go with a) then 1. above may be fine, but 2. still shows a problem in the underlying compiler logic.
Ideally, we would also centralize all this platform-specific -sdk logic in one place in the compiler, rather than have different components of the compiler like swift-frontend or the ClangImporter do things differently, which caused #74696.
@compnerd, what do you say? We need a better plan for this transition.
@al45tair, as chair of the Platform Steering Group, perhaps you'd like to weigh in here.
The text was updated successfully, but these errors were encountered:
finagolfin
added
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
labels
Sep 10, 2024
Description
I just tried the following command on linux with the latest Sep. 6 trunk 6.1 snapshot toolchain and it failed for the first time:
This is with no system Swift installed in
/usr
. If a system Swift 5.10 happens to be there, the link happens to pass because it uses the 5.10/usr/lib/swift/linux/x86_64/swiftrt.o
instead, but that is the wrong version and could break any time that object file changes. A local Swift 5.10 and a recent 6.0 snapshot don't have this problem, ie they don't look in/usr
for an SDK overlay altogether.There are two problems with the above commands in Swift 6.1:
swiftrt.o
that doesn't exist.swift-frontend
looks for the linux SDK overlay Swift modules in-resource-dir /home/finagolfin/swift-DEVELOPMENT-SNAPSHOT-2024-09-06-a-ubi9/usr/lib/swift/
and finds them, but theswift-driver
tellsclang
to look forswiftrt.o
from that same linux SDK overlay in/usr/lib/swift/linux/x86_64/
instead, which doesn't exist. In other words, the Swift compiler is looking in completely different directories for files from the same linux SDK.This all appears to be a consequence of the recent push to change the meaning of certain core compilation flags, as detailed in #73581. Briefly, the goal outlined there is to change the currently used flags of
-resource-dir
and-sdk
, which specify the paths to a platform SDK overlay and platform C/C++ sysroot respectively, to the flags-sdk
and-sysroot
instead, ie-sdk
now points at the platform SDK overlay and-sysroot
at the platform C/C++ sysroot.I am fine with this transition in principle, but we need to handle the actual implementation more carefully or very basic commands like this are going to break without explanation. This particular change was made in swiftlang/swift-driver#1560, which I argued against strongly at that time.
Reproduction
See command above
Expected behavior
Everything compiles fine or user is told what they did wrong.
Environment
Fedora 40 linux x86_64
Additional information
There are two ways we could handle this planned transition, which so far has only been partially implemented for non-Darwin platforms:
a) Tell everyone to use the new set of flags and have things randomly break like this if they use the old flags.
b) Put in some logic to guess what the user is trying to do, then try to either translate the flags based on context or give them better error messages on what they're doing wrong.
If we go with a) then 1. above may be fine, but 2. still shows a problem in the underlying compiler logic.
Ideally, we would also centralize all this platform-specific
-sdk
logic in one place in the compiler, rather than have different components of the compiler likeswift-frontend
or theClangImporter
do things differently, which caused #74696.@compnerd, what do you say? We need a better plan for this transition.
@al45tair, as chair of the Platform Steering Group, perhaps you'd like to weigh in here.
The text was updated successfully, but these errors were encountered: