Skip to content

Commit c355611

Browse files
committed
Android: always build libraries as PIC
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) ```
1 parent ba21a14 commit c355611

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,9 @@ function(add_swift_target_library_single target name)
12371237
PROPERTIES
12381238
INSTALL_RPATH "$ORIGIN")
12391239
endif()
1240+
1241+
set_target_properties(${target} PROPERTIES
1242+
POSITION_INDEPENDENT_CODE YES)
12401243
elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "OPENBSD")
12411244
set_target_properties("${target}"
12421245
PROPERTIES

0 commit comments

Comments
 (0)