-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Android: always build libraries as PIC #71932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This adjusts the stdlib bits to be built as position independent. As we build a single instance of the code and then create static and dynamic runtimes, simply pay a penalty when performing static linking of the runtime to make the dynamic case work properly. This repairs part of the runtime build on Android where we would previously see when building SwiftRemoteMirror: ``` ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'construction vtable for std::__ndk1::basic_istream<char, std::__ndk1::char_traits<char>>-in-std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'construction vtable for std::__ndk1::basic_istream<char, std::__ndk1::char_traits<char>>-in-std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'VTT for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'VTT for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(swift::reflection::TypeRefBuilder::ReflectionTypeDescriptorFinder::collectFieldTypes(std::__ndk1::optional<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>)) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::~basic_stringstream()) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::~basic_stringstream()) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::~basic_stringstream()) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::~basic_stringstream()) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'VTT for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::~basic_stringstream()) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'VTT for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::~basic_stringstream()) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(non-virtual thunk to std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::~basic_stringstream()) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>'; recompile with -fPIC >>> defined in lib/swift/android/aarch64/libswiftRemoteInspection.a(TypeRefBuilder.cpp.o) >>> referenced by TypeRefBuilder.cpp >>> TypeRefBuilder.cpp.o:(non-virtual thunk to std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::~basic_stringstream()) in archive lib/swift/android/aarch64/libswiftRemoteInspection.a ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors) ```
@swift-ci please test |
Huh, I just checked and for the normal cross-compilation command of the Swift stdlib from linux to Android detailed in the doc, this flag is added:
Now, it is possible that this simply happens to work when cross-compiling from linux because some CMake default flag for linux is passed in, while Windows does not have that CMake default. Is that what's going on here? I have no problem with this pull if you are remedying something broken with CMake, just trying to understand why it is necessary. If @etcwilde is switching all this over to CMake's built-in cross-compilation support soon, this flag may not be needed. |
Yes, I think that is the case -
Yes, that would also fix this properly. Unfortunately, that isn't imminently ready to merge, so I figure that this workaround for the time being might be the best way forward :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Saleem, this is simply making explicit what is already implicitly required, so LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine.
This adjusts the stdlib bits to be built as position independent. As we build a single instance of the code and then create static and dynamic runtimes, simply pay a penalty when performing static linking of the runtime to make the dynamic case work properly. This repairs part of the runtime build on Android where we would previously see when building SwiftRemoteMirror: