We would need to see what file was being built. SwiftRT-ELF-WASM.cpp only refers to the symbol, it doesn't define it. The compiler is supposed to emit it into the objects so that swiftrt.o can extract them and make them visible to the runtime. We'd need to see the full swiftc invocation above the link failure to have a better idea of what was getting the symbol removed.
Unsure why it doesn't work if you patched the CMake config and passed in the flags, may help to look in build/hosttools/swift-linux-x86_64/CMakeCache.txt and see if those flags all show up.
Okay, after a few weeks (!) of experimentation, I've managed to get source builds going for Gentoo. The base changes are currently live on GURU, though I've put out a few cleanup/fix commits that haven't made it out yet.
Some notes:
I tried to see if it was possible to get Swift to link using bfd for Gentoo systems that don't have lld and the answer appears to be a resounding "no" (hence why Swift normally defaults to gold); so LLD is required in all cases, both at build time and at runtime
Part of what took so long was trying to get Swift built inside of the Portage sandbox:
Packages are built inside of a very restrictive sandbox (great!), which is a different environment from building locally inside of, e.g., your home folder, which means different failure modes
When compilation fails inside of the sandbox, there's no way to "go in", fix things up, and try again from that point — which means that my poor CPU has built LLVM so many times at this point that the source code is etched into its branch predictors
I was able to use the pre-built Fedora 39 compiler to build Swift, but not in one go. I never managed to figure out why, but attempting to build a full toolchain in a single go with the prebuilt compiler (with a dummy ld.gold pointing to ld.lld in the PATH) always got stuck in building lldb with something attempting to link using bfd and failing. When this would happen, deleting the lldb build dir and re-running the build script (with the same args) would then build successfully ¯\(ツ)/¯
I ended up forgoing the pre-built compiler and using a self-bootstrapping 3-stage build that's been tightened up a little from @etcwilde's original scripts:
stage0 builds just LLVM+Clang, CMark, and a bare Swift compiler with no Swift driver/macros:
Avoiding rebuilding LLVM+Clang between stages saves a huge amount of time (45min per stage on my machine), as does building and installing local copies of curl, libicu, and libxml2, which are present on the filesystem as dependencies
With extra-cmake-options, I also avoid building test code + binaries which tend to be built by default:
local _extra_cmake_options=(
'-DSWIFT_USE_LINKER=lld',
'-DBUILD_TESTING:BOOL=NO',
'-DSWIFT_INCLUDE_TESTS:BOOL=NO',
'-DSWIFT_INCLUDE_TEST_BINARIES:BOOL=NO',
'-DCOMPILER_RT_BUILD_ORC:BOOL=NO'
)
Given the build product sharing between these stages, a 2-stage build process with the pre-built compiler didn't save enough time over a 3-stage process to warrant the additional 500Mb+ download, in my eyes
In all, this was... an interesting exercise... and I hope that the process for adapting this to building Swift 6 will be a bit easier now.
Very cool! I think Swift 6 may bring new challenges (at least it has challenged me in trying to get it to cross compile for armv7)...but I'm looking forward to trying a build on a local Gentoo and see how it goes!