swift: [build] fails to build on Amazon Linux 2023

I am trying to build the tool chain on Amazon Linux 2023 (ALI2023)

I identified two changes on ALI2023 (vs ALI2) that impact the build:

  • the first one is the lack of support for ld.gold forcing me to modify the swift build scripts to use lld on Amazon Linux 2023 only (other platforms Ubuntu, ALI2, RedHat, Oracle Linux, Debian all provide ld.gold)
  • the second one is specific to Arm : the clang tool chain is located under /lib/gcc/aarch64-amazon-linux/11 which is not found - by default - by clang.

Knowing that, I managed to build LLVM and Swift and its dependencies on x64 and arm64 architectures using build-script with NO PRESETS. This is the command that works. As I mentioned, I have to use lld because ld.gold is unavailable on Amazon Linux 2023.

./swift//utils/build-script --release-debuginfo --skip-early-swift-driver --extra-cmake-options="-DLLVM_USE_LINKER=lld"

🎉 this builds the entire project

My ultimate goal is to add support for ALi2023 to the swift-installer-scripts project. This projects uses the build-scriptpython script with presets. So I created a new preset for Amazon Linux 2023 to mimic both current behaviour when building Amazon Linux 2 + the two new settings I used on the command that works.

This is my new preset in build-preset.ini :

[preset: buildbot_amazon_linux_2023,no_assertions,no_test]
extra-cmake-options=-DLLVM_USE_LINKER=lld
skip-early-swift-driver
mixin-preset=
    buildbot_linux,no_assertions
    mixin_buildbot_linux,no_test

And the command I use to test it

swift/utils/build-script --preset=buildbot_amazon_linux_2023,no_assertions,no_test install_destdir=/tmp installable_package=/tmp/swift-5.7.3-amazonlinux2023.tar.gz

This fails when the build tests the newly built swiftc compiler because it looks like the LLVM_USE_LINKER=lld flag is passed as environment variable but the CMakeList.txt script is not executed to test the new compiler, hence gold being used.

Here is the full error message. What am I doing wrong ?

+ env /usr/bin/cmake -DENABLE_SWIFT=YES -G Ninja -DCMAKE_C_COMPILER:PATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:PATH=/usr/bin/clang++ -DCMAKE_Swift_COMPILER:PATH= -DCMAKE_LIBTOOL:PATH= -DCMAKE_AR:PATH=/usr/bin/ar -DCMAKE_RANLIB:PATH=/usr/bin/ranlib -DLLVM_VERSION_MAJOR:STRING=13 -DLLVM_VERSION_MINOR:STRING=0 -DLLVM_VERSION_PATCH:STRING=0 -DCLANG_VERSION_MAJOR:STRING=13 -DCLANG_VERSION_MINOR:STRING=0 -DCLANG_VERSION_PATCH:STRING=0 -DCMAKE_MAKE_PROGRAM=/home/ec2-user/project-swift/build/buildbot_linux/ninja-build/ninja -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_C_COMPILER:PATH=/home/ec2-user/project-swift/build/buildbot_linux/llvm-linux-aarch64/bin/clang -DCMAKE_CXX_COMPILER:PATH=/home/ec2-user/project-swift/build/buildbot_linux/llvm-linux-aarch64/bin/clang++ -DCMAKE_SWIFT_COMPILER:PATH=/home/ec2-user/project-swift/build/buildbot_linux/swift-linux-aarch64/bin/swiftc -DCMAKE_Swift_COMPILER:PATH=/home/ec2-user/project-swift/build/buildbot_linux/swift-linux-aarch64/bin/swiftc '-DCMAKE_Swift_FLAGS:STRING=  -module-cache-path "/home/ec2-user/project-swift/build/buildbot_linux/libdispatch-linux-aarch64/module-cache" ' -DCMAKE_INSTALL_PREFIX:PATH=/usr/ -DCMAKE_INSTALL_LIBDIR:PATH=lib -DSwift_DIR=/home/ec2-user/project-swift/build/buildbot_linux/swift-linux-aarch64/lib/cmake/swift -DENABLE_TESTING=YES -DBUILD_SHARED_LIBS=YES -DLLVM_USE_LINKER=lld /home/ec2-user/project-swift/swift-corelibs-libdispatch
-- The C compiler identification is Clang 13.0.0
-- The CXX compiler identification is Clang 13.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/ec2-user/project-swift/build/buildbot_linux/llvm-linux-aarch64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/ec2-user/project-swift/build/buildbot_linux/llvm-linux-aarch64/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- The Swift compiler identification is Apple 5.7.3
-- Check for working Swift compiler: /home/ec2-user/project-swift/build/buildbot_linux/swift-linux-aarch64/bin/swiftc
-- Check for working Swift compiler: /home/ec2-user/project-swift/build/buildbot_linux/swift-linux-aarch64/bin/swiftc - broken
CMake Error at /usr/share/cmake/Modules/CMakeTestSwiftCompiler.cmake:44 (message):
  The Swift compiler

    "/home/ec2-user/project-swift/build/buildbot_linux/swift-linux-aarch64/bin/swiftc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/ec2-user/project-swift/build/buildbot_linux/libdispatch-linux-aarch64/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/home/ec2-user/project-swift/build/buildbot_linux/ninja-build/ninja cmTC_5c601 && [1/1][100%][0.112s] Linking Swift executable cmTC_5c601
    FAILED: cmTC_5c601 CMakeFiles/cmTC_5c601.dir/main.swift.o cmTC_5c601.swiftmodule 
    : && /home/ec2-user/project-swift/build/buildbot_linux/swift-linux-aarch64/bin/swiftc -output-file-map CMakeFiles/cmTC_5c601.dir//output-file-map.json -incremental -j 64 -emit-executable -o cmTC_5c601 -emit-dependencies  -module-cache-path "/home/ec2-user/project-swift/build/buildbot_linux/libdispatch-linux-aarch64/module-cache"    -module-cache-path "/home/ec2-user/project-swift/build/buildbot_linux/libdispatch-linux-aarch64/module-cache"  /home/ec2-user/project-swift/build/buildbot_linux/libdispatch-linux-aarch64/CMakeFiles/CMakeTmp/main.swift    && :
    clang-15: error: invalid linker name in argument '-fuse-ld=gold'
    <unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:128 (enable_language)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

I had to let this project aside for a while. Thank you @finagolfin you were correct. After doing a full clean, git clone again etc. I managed to build 5.9.1 without patching anything, just by ensuring 5.8 is installed and available in the path (and using the gold linker)

You’re right @finagolfin I should have shared more details

[1254/1356][ 92%][1020.234s] Compiling /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/stdlib/public/libexec/swift-backtrace//LINUX/x86_64/swift_backtrace_linux_x86_64.o
FAILED: stdlib/public/libexec/swift-backtrace/LINUX/x86_64/swift_backtrace_linux_x86_64.o /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/stdlib/public/libexec/swift-backtrace/LINUX/x86_64/swift_backtrace_linux_x86_64.o 
cd /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/stdlib/public/libexec/swift-backtrace && /usr/bin/cmake -E make_directory /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/stdlib/public/libexec/swift-backtrace/LINUX/x86_64 && /usr/bin/cmake -E env PYTHONIOENCODING=UTF8 /usr/bin/python3.9 /home/ec2-user/swift-project/swift/utils/line-directive @/home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/stdlib/public/libexec/swift-backtrace/84aba54f62480cdf960f1f3cc76ec2c2c5fc8d33.txt -- /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/./bin/swiftc -c -sdk / -target x86_64-unknown-linux-gnu -resource-dir /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/./lib/swift -O -g -D INTERNAL_CHECKS_ENABLED -D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY -D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED -D SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -D SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING -D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING -D SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION -D SWIFT_RUNTIME_OS_VERSIONING -D SWIFT_STDLIB_ENABLE_UNICODE_DATA -D SWIFT_STDLIB_ENABLE_VECTOR_TYPES -D SWIFT_STDLIB_HAS_COMMANDLINE -D SWIFT_STDLIB_HAS_STDIN -D SWIFT_STDLIB_HAS_ENVIRON -Xcc -DSWIFT_STDLIB_HAS_ENVIRON -D SWIFT_THREADING_LINUX -tools-directory /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-linux-x86_64/./bin -module-cache-path /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/./module-cache -no-link-objc-runtime -D SWIFT_ENABLE_REFLECTION -module-name swift_backtrace_linux_x86_64 -Xfrontend -disable-objc-interop -I/home/ec2-user/swift-project/swift/stdlib/public/Backtracing/modules -Xcc -I/home/ec2-user/swift-project/swift/include -Xcc -I/home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/include -parse-as-library -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -Xcc -fno-omit-frame-pointer -whole-module-optimization -color-diagnostics -resource-dir /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/./lib/swift -I /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/./lib/swift/linux -o /home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/stdlib/public/libexec/swift-backtrace//LINUX/x86_64/swift_backtrace_linux_x86_64.o @/home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/stdlib/public/libexec/swift-backtrace/84aba54f62480cdf960f1f3cc76ec2c2c5fc8d33.txt
/home/ec2-user/swift-project/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bin/swiftc: error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory
[ec2-user@ip-172-31-46-120 swift]$ find .. -name libswiftCore.so
../build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bootstrapping0/lib/swift/linux/libswiftCore.so
../build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bootstrapping1/lib/swift/linux/libswiftCore.so