We have a Swift project which is is aggregating a bunch of high level libraries, and one of them transitively uses LLVM. This almost works fine, except that the Swift runtime library redefines an LLVM symbol here:
We’re building on Linux and statically linking everything together. I think that the symbol above ends up being “not a problem” on apple platforms, because this code gets linked into a dylib with -fvisibility-hidden to hide the symbol. Is there some other reasonable way for the Swift runtime to achieve whatever it is doing?
For example, Dmitri suggests that we could go with a header-only solution like this:
LLVM_ATTRIBUTE_WEAK is a macro that expands to __attribute__((weak)). If you change the declaration in the LLVM header then both the Swift runtime and LLVM definitions are going to end up being weak, and we only want the Swift runtime’s definition to be. Try declaring fixed_seed_override as weak only in the Swift runtime source file that defines it.
Hm, I’m not sure why you would still be getting linker errors in that case, but I agree in principle with Jordan that it’d be better if a statically-linked Swift runtime didn’t include symbols that might collide with LLVM. There are a few other things we could do to mitigate the problem. As Jordan suggested, we could copy the LLVM hashing libraries Swift uses into the runtime and tweak them not to collide with LLVM. It might also be a good idea to change how static libswiftCore.a is built so that it’s incrementally linked into a single .o file, which then only exports the public interface of the runtime and standard library. This would ensure in the long term that implementation details of the Swift runtime and standard library don’t interfere with any other library a statically-linked executable may use in tandem with them.
I’m sorry I didn’t reply to this sooner, but this isn’t good enough for the static version of the stdlib. We might be able to get away with this some day in the future when the stdlib only shipped in dylib form as part of the OS, but we can’t take it today.