Skip to content

Make Swift work on Linux/armv7 #608

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
# FIXME: This only matches ARMv7l (by far the most common variant).
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
configure_sdk_unix(LINUX "Linux" "linux" "linux" "armv7" "armv7-unknown-linux-gnueabihf")
configure_sdk_unix(LINUX "Linux" "linux" "linux" "armv7" "thumbv7-unknown-linux-gnueabihf")
set(SWIFT_HOST_VARIANT_ARCH "armv7")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "armv7")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
Expand Down
6 changes: 6 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,14 @@ function(_add_variant_link_flags

if("${sdk}" STREQUAL "LINUX")
list(APPEND result "-lpthread" "-ldl")
if("${arch}" MATCHES "^arm")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except we don't need this for arm64, do we?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't arm64 aarch64, and therefore wouldn't match?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It it sometimes one and sometimes the other. I would prefer to hardcode the exact list here to make maintenance easier. Many people need to modify this file, but very few can test on more rare platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gribozavr Will fix.

list(APPEND result "-Wl,-Bsymbolic")
endif()
elseif("${sdk}" STREQUAL "FREEBSD")
# No extra libraries required.
if("${arch}" MATCHES "^arm")
list(APPEND result "-Wl,-Bsymbolic")
endif()
else()
list(APPEND result "-lobjc")
endif()
Expand Down
1 change: 1 addition & 0 deletions lib/Basic/LangOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
// Set the "arch" target configuration.
switch (Target.getArch()) {
case llvm::Triple::ArchType::arm:
case llvm::Triple::ArchType::thumb:
addTargetConfigOption("arch", "arm");
break;
case llvm::Triple::ArchType::aarch64:
Expand Down
12 changes: 12 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,18 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
break;
case LinkKind::DynamicLibrary:
Arguments.push_back("-shared");
switch (getTriple().getArch()) {
default:
break;
case llvm::Triple::arm:
case llvm::Triple::armeb:
case llvm::Triple::thumb:
case llvm::Triple::thumbeb:
// Avoid emitting R_ARM_REL32 which is not supported by shared objects
// on ELF targets.
Arguments.push_back("-Wl,-Bsymbolic");
break;
}
break;
}

Expand Down
29 changes: 22 additions & 7 deletions stdlib/public/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,30 @@ add_swift_library(swiftRuntime IS_STDLIB IS_STDLIB_CORE
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
if("${sdk}" STREQUAL "LINUX" OR "${sdk}" STREQUAL "FREEBSD")
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
if ("${sdk}" STREQUAL "LINUX" AND "${arch}" STREQUAL "armv7")
# Handle special case for ARM/Thumb on Linux.
# FIXME: Find a more elegant way to handle this case.
foreach(subarch armv7;armv7l;thumbv7;thumbv7l)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be just one directory (these platforms are all the same), see my other comment.

set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${subarch}")

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

swift_install_in_component(compiler
FILES "swift.ld"
DESTINATION "lib/swift/${arch_subdir}")
swift_install_in_component(compiler
FILES "swift.ld"
DESTINATION "lib/swift/${arch_subdir}")

endforeach()
else ()
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")

configure_file(
"swift.ld" "${SWIFTLIB_DIR}/${arch_subdir}/swift.ld" COPYONLY)

swift_install_in_component(compiler
FILES "swift.ld"
DESTINATION "lib/swift/${arch_subdir}")
endif ()

endforeach()
endif()
Expand Down
3 changes: 3 additions & 0 deletions test/1_stdlib/FloatingPointIR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func testConstantFoldFloatLiterals() {
// armv7: call void @{{.*}}_TF15FloatingPointIR13acceptFloat32FSfT_(float 1.000000e+00)
// armv7: call void @{{.*}}_TF15FloatingPointIR13acceptFloat64FSdT_(double 1.000000e+00)

// thumbv7: call void @{{.*}}_TF15FloatingPointIR13acceptFloat32FSfT_(float 1.000000e+00)
// thumbv7: call void @{{.*}}_TF15FloatingPointIR13acceptFloat64FSdT_(double 1.000000e+00)

// armv7k: call void @{{.*}}_TF15FloatingPointIR13acceptFloat32FSfT_(float 1.000000e+00)
// armv7k: call void @{{.*}}_TF15FloatingPointIR13acceptFloat64FSdT_(double 1.000000e+00)

Expand Down