Skip to content

Commit 89c5491

Browse files
committed
Add support to generate correct code on ARM ELF targets.
Adds -Bsymbolic at link time when producing shared objects so that the linker will not produce the forbidden relocation R_ARM_REL32. Do the same also when linking Swift standard libraries.
1 parent 30b9d80 commit 89c5491

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,14 @@ function(_add_variant_link_flags
160160

161161
if("${sdk}" STREQUAL "LINUX")
162162
list(APPEND result "-lpthread" "-ldl")
163+
if("${arch}" MATCHES "^arm")
164+
list(APPEND result "-Wl,-Bsymbolic")
165+
endif()
163166
elseif("${sdk}" STREQUAL "FREEBSD")
164167
# No extra libraries required.
168+
if("${arch}" MATCHES "^arm")
169+
list(APPEND result "-Wl,-Bsymbolic")
170+
endif()
165171
else()
166172
list(APPEND result "-lobjc")
167173
endif()

lib/Driver/ToolChains.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,16 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
10471047
break;
10481048
case LinkKind::DynamicLibrary:
10491049
Arguments.push_back("-shared");
1050+
switch (getTriple().getArch()) {
1051+
default:
1052+
break;
1053+
case llvm::Triple::arm:
1054+
case llvm::Triple::armeb:
1055+
// Avoid emitting R_ARM_REL32 which is not supported by shared objects
1056+
// on ELF targets.
1057+
Arguments.push_back("-Wl,-Bsymbolic");
1058+
break;
1059+
}
10501060
break;
10511061
}
10521062

stdlib/public/runtime/CMakeLists.txt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,30 @@ add_swift_library(swiftRuntime IS_STDLIB IS_STDLIB_CORE
7474
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
7575
if("${sdk}" STREQUAL "LINUX" OR "${sdk}" STREQUAL "FREEBSD")
7676
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
77-
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
77+
if ("${sdk}" STREQUAL "LINUX" AND "${arch}" STREQUAL "armv7")
78+
# Handle special case for ARM on Linux.
79+
# FIXME: Find a more elegant way to handle this case.
80+
foreach(subarch armv7;armv7l)
81+
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${subarch}")
7882

79-
# FIXME: We will need a different linker script for 32-bit builds.
80-
configure_file(
81-
"swift.ld" "${SWIFTLIB_DIR}/${arch_subdir}/swift.ld" COPYONLY)
83+
configure_file(
84+
"swift.ld" "${SWIFTLIB_DIR}/${arch_subdir}/swift.ld" COPYONLY)
8285

83-
swift_install_in_component(compiler
84-
FILES "swift.ld"
85-
DESTINATION "lib/swift/${arch_subdir}")
86+
swift_install_in_component(compiler
87+
FILES "swift.ld"
88+
DESTINATION "lib/swift/${arch_subdir}")
89+
90+
endforeach()
91+
else ()
92+
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
93+
94+
configure_file(
95+
"swift.ld" "${SWIFTLIB_DIR}/${arch_subdir}/swift.ld" COPYONLY)
96+
97+
swift_install_in_component(compiler
98+
FILES "swift.ld"
99+
DESTINATION "lib/swift/${arch_subdir}")
100+
endif ()
86101

87102
endforeach()
88103
endif()

0 commit comments

Comments
 (0)