Skip to content

Commit 4bf81e0

Browse files
committed
Build working on ARMv7l
1 parent 11b8bcf commit 4bf81e0

File tree

7 files changed

+134
-41
lines changed

7 files changed

+134
-41
lines changed

CMakeLists.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,28 @@ endfunction()
385385
# FIXME: separate the notions of SDKs used for compiler tools and target
386386
# binaries.
387387
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
388-
configure_sdk_unix(LINUX "Linux" "linux" "linux" "x86_64" "x86_64-unknown-linux-gnu")
389-
390388
set(CMAKE_EXECUTABLE_FORMAT "ELF")
391389

392390
set(SWIFT_HOST_VARIANT "linux" CACHE STRING
393391
"Deployment OS for Swift host tools (the compiler) [linux].")
394392

395393
set(SWIFT_HOST_VARIANT_SDK "LINUX")
396-
set(SWIFT_HOST_VARIANT_ARCH "x86_64")
397-
398394
set(SWIFT_PRIMARY_VARIANT_SDK_default "LINUX")
399-
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
395+
396+
# FIXME: This will not work while trying to cross-compile
397+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
398+
configure_sdk_unix(LINUX "Linux" "linux" "linux" "x86_64" "x86_64-unknown-linux-gnu")
399+
set(SWIFT_HOST_VARIANT_ARCH "x86_64")
400+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
401+
# FIXME: This only matches ARMv7l (by far the most common variant)
402+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
403+
configure_sdk_unix(LINUX "Linux" "linux" "linux" "armv7" "armv7-unknown-linux-gnueabihf")
404+
set(SWIFT_HOST_VARIANT_ARCH "armv7")
405+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "armv7")
406+
else()
407+
message(FATAL_ERROR "Unknown or unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
408+
endif()
409+
400410
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
401411
configure_sdk_unix(FREEBSD "FreeBSD" "freebsd" "freebsd" "x86_64" "x86_64-freebsd10")
402412

lib/Driver/ToolChains.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
11151115
// Add the linker script that coalesces protocol conformance sections.
11161116
Arguments.push_back("-Xlinker");
11171117
Arguments.push_back("-T");
1118-
Arguments.push_back(
1119-
context.Args.MakeArgString(Twine(RuntimeLibPath) + "/x86_64/swift.ld"));
1118+
1119+
// FIXME: This should also query the abi type (i.e. gnueabihf)
1120+
Arguments.push_back(context.Args.MakeArgString(
1121+
Twine(RuntimeLibPath) + "/" + getTriple().getArchName() + "/swift.ld"));
11201122

11211123
// This should be the last option, for convenience in checking output.
11221124
Arguments.push_back("-o");

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ namespace swift { extern "C" {
2828

2929
// This declaration is not universally correct. We verify its correctness for
3030
// the current platform in the runtime code.
31+
#if defined(__linux__) && defined (__arm__)
32+
typedef int __swift_ssize_t;
33+
#else
3134
typedef long int __swift_ssize_t;
35+
#endif
3236

3337
// General utilities <stdlib.h>
3438
// Memory management functions

stdlib/public/stubs/Stubs.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ extern "C" long double _swift_fmodl(long double lhs, long double rhs) {
216216
// This implementation is copied here to avoid a new dependency
217217
// on compiler-rt on Linux.
218218
// FIXME: rdar://14883575 Libcompiler_rt omits muloti4
219-
#if __arm64__ || !defined(__APPLE__)
219+
#if (defined(__APPLE__) && defined(__arm64__)) || \
220+
(defined(__linux__) && defined(__x86_64__))
220221

221222
typedef int ti_int __attribute__ ((mode (TI)));
222223
extern "C"
@@ -261,6 +262,54 @@ __muloti4(ti_int a, ti_int b, int* overflow)
261262

262263
#endif
263264

265+
#if defined(__linux__) && defined(__arm__)
266+
// Similar to above, but with mulodi4. Perhaps this is
267+
// something that shouldn't be done, and is a bandaid over
268+
// some other lower-level architecture issue that I'm
269+
// missing. Perhaps relevant bug report:
270+
// FIXME: https://llvm.org/bugs/show_bug.cgi?id=14469
271+
typedef int di_int __attribute__ ((mode (DI)));
272+
extern "C"
273+
di_int
274+
__mulodi4(di_int a, di_int b, int* overflow)
275+
{
276+
const int N = (int)(sizeof(di_int) * CHAR_BIT);
277+
const di_int MIN = (di_int)1 << (N-1);
278+
const di_int MAX = ~MIN;
279+
*overflow = 0;
280+
di_int result = a * b;
281+
if (a == MIN)
282+
{
283+
if (b != 0 && b != 1)
284+
*overflow = 1;
285+
return result;
286+
}
287+
if (b == MIN)
288+
{
289+
if (a != 0 && a != 1)
290+
*overflow = 1;
291+
return result;
292+
}
293+
di_int sa = a >> (N - 1);
294+
di_int abs_a = (a ^ sa) - sa;
295+
di_int sb = b >> (N - 1);
296+
di_int abs_b = (b ^ sb) - sb;
297+
if (abs_a < 2 || abs_b < 2)
298+
return result;
299+
if (sa == sb)
300+
{
301+
if (abs_a > MAX / abs_b)
302+
*overflow = 1;
303+
}
304+
else
305+
{
306+
if (abs_a > MIN / -abs_b)
307+
*overflow = 1;
308+
}
309+
return result;
310+
}
311+
#endif
312+
264313
// We can't return Float80, but we can receive a pointer to one, so
265314
// switch the return type and the out parameter on strtold.
266315
template <typename T>

test/Driver/linker.swift

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
// RUN: FileCheck -check-prefix watchOS_SIMPLE %s < %t.simple.txt
1313

1414
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-unknown-linux-gnu -Ffoo -framework bar -Lbaz -lboo -Xlinker -undefined %s 2>&1 > %t.linux.txt
15-
// RUN: FileCheck -check-prefix LINUX %s < %t.linux.txt
15+
// RUN: FileCheck -check-prefix LINUX-x86_64 %s < %t.linux.txt
16+
17+
// RUN: %swiftc_driver -driver-print-jobs -target armv7-unknown-linux-gnueabihf -Ffoo -framework bar -Lbaz -lboo -Xlinker -undefined %s 2>&1 > %t.linux.txt
18+
// RUN: FileCheck -check-prefix LINUX-armv7 %s < %t.linux.txt
1619

1720
// RUN: %swiftc_driver -driver-print-jobs -emit-library -target x86_64-apple-macosx10.9.1 %s -sdk %S/../Inputs/clang-importer-sdk -lfoo -framework bar -Lbaz -Fgarply -Xlinker -undefined -Xlinker dynamic_lookup -o sdk.out 2>&1 > %t.complex.txt
1821
// RUN: FileCheck %s < %t.complex.txt
1922
// RUN: FileCheck -check-prefix COMPLEX %s < %t.complex.txt
2023

2124
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -g %s | FileCheck -check-prefix DEBUG %s
22-
23-
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.10 %s | FileCheck -check-prefix NO_ARCLITE %s
24-
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-ios8.0 %s | FileCheck -check-prefix NO_ARCLITE %s
25+
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.10 %s | FileCheck -check-prefix NO_ARCLITE %s
26+
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-ios8.0 %s | FileCheck -check-prefix NO_ARCLITE %s
2527

2628
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -emit-library %s -module-name LINKER | FileCheck -check-prefix INFERRED_NAME %s
2729
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -emit-library %s -o libLINKER.dylib | FileCheck -check-prefix INFERRED_NAME %s
@@ -90,21 +92,37 @@
9092
// watchOS_SIMPLE: -o linker
9193

9294

93-
// LINUX: swift
94-
// LINUX: -o [[OBJECTFILE:.*]]
95-
96-
// LINUX: clang++{{"? }}
97-
// LINUX-DAG: [[OBJECTFILE]]
98-
// LINUX-DAG: -lswiftCore
99-
// LINUX-DAG: -L [[STDLIB_PATH:[^ ]+/lib/swift]]
100-
// LINUX-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
101-
// LINUX-DAG: -Xlinker -T /{{[^ ]+}}/linux/x86_64/swift.ld
102-
// LINUX-DAG: -F foo
103-
// LINUX-DAG: -framework bar
104-
// LINUX-DAG: -L baz
105-
// LINUX-DAG: -lboo
106-
// LINUX-DAG: -Xlinker -undefined
107-
// LINUX: -o linker
95+
// LINUX-x86_64: swift
96+
// LINUX-x86_64: -o [[OBJECTFILE:.*]]
97+
98+
// LINUX-x86_64: clang++{{"? }}
99+
// LINUX-x86_64-DAG: [[OBJECTFILE]]
100+
// LINUX-x86_64-DAG: -lswiftCore
101+
// LINUX-x86_64-DAG: -L [[STDLIB_PATH:[^ ]+/lib/swift]]
102+
// LINUX-x86_64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
103+
// LINUX-x86_64-DAG: -Xlinker -T /{{[^ ]+}}/linux/x86_64/swift.ld
104+
// LINUX-x86_64-DAG: -F foo
105+
// LINUX-x86_64-DAG: -framework bar
106+
// LINUX-x86_64-DAG: -L baz
107+
// LINUX-x86_64-DAG: -lboo
108+
// LINUX-x86_64-DAG: -Xlinker -undefined
109+
// LINUX-x86_64: -o linker
110+
111+
// LINUX-armv7: swift
112+
// LINUX-armv7: -o [[OBJECTFILE:.*]]
113+
114+
// LINUX-armv7: clang++{{"? }}
115+
// LINUX-armv7-DAG: [[OBJECTFILE]]
116+
// LINUX-armv7-DAG: -lswiftCore
117+
// LINUX-armv7-DAG: -L [[STDLIB_PATH:[^ ]+/lib/swift]]
118+
// LINUX-armv7-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
119+
// LINUX-armv7-DAG: -Xlinker -T /{{[^ ]+}}/linux/armv7/swift.ld
120+
// LINUX-armv7-DAG: -F foo
121+
// LINUX-armv7-DAG: -framework bar
122+
// LINUX-armv7-DAG: -L baz
123+
// LINUX-armv7-DAG: -lboo
124+
// LINUX-armv7-DAG: -Xlinker -undefined
125+
// LINUX-armv7: -o linker
108126

109127
// COMPLEX: bin/ld{{"? }}
110128
// COMPLEX-DAG: -dylib

test/lit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ if run_vendor == 'apple':
607607
"%s ld -L%s" %
608608
(xcrun_prefix, os.path.join(test_resource_dir, config.target_sdk_name)))
609609

610-
elif run_os == 'linux-gnu':
610+
elif run_os == 'linux-gnu' or run_os == 'linux-gnueabihf':
611611
# Linux
612612
lit_config.note("Testing Linux " + config.variant_triple)
613613
config.target_object_format = "elf"

utils/build-script-impl

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ function set_deployment_target_based_options() {
227227
linux-x86_64)
228228
SWIFT_HOST_VARIANT_ARCH="x86_64"
229229
;;
230+
linux-armv7)
231+
SWIFT_HOST_VARIANT_ARCH="armv7"
232+
;;
230233
freebsd-x86_64)
231234
SWIFT_HOST_VARIANT_ARCH="x86_64"
232235
;;
@@ -730,8 +733,8 @@ if [[ "$(uname -s)" == "Darwin" ]] ; then
730733
TOOLCHAIN_PREFIX=$(echo ${INSTALL_PREFIX} | sed -E 's/\/usr$//')
731734
fi
732735

733-
# A list of deployment targets to compile the Swift host tools for, in case when
734-
# we can run the resulting binaries natively on the build machine.
736+
# A list of deployment targets to compile the Swift host tools for, in cases
737+
# where we can run the resulting binaries natively on the build machine.
735738
NATIVE_TOOLS_DEPLOYMENT_TARGETS=()
736739

737740
# A list of deployment targets to cross-compile the Swift host tools for.
@@ -740,20 +743,24 @@ CROSS_TOOLS_DEPLOYMENT_TARGETS=()
740743

741744
# Determine the native deployment target for the build machine, that will be
742745
# used to jumpstart the standard library build when cross-compiling.
743-
case "$(uname -s)" in
744-
Linux)
746+
case "$(uname -s -m)" in
747+
Linux\ x86_64)
745748
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
746749
"linux-x86_64"
747750
)
748751
;;
749-
750-
Darwin)
752+
Linux\ armv7*)
753+
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
754+
"linux-armv7"
755+
)
756+
;;
757+
Darwin\ x86_64)
751758
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
752759
"macosx-x86_64"
753760
)
754761
;;
755762

756-
FreeBSD)
763+
FreeBSD\ x86_64)
757764
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
758765
"freebsd-x86_64"
759766
)
@@ -805,15 +812,18 @@ function is_cross_tools_deployment_target() {
805812
# A list of deployment targets that we compile or cross-compile the
806813
# Swift standard library for.
807814
STDLIB_DEPLOYMENT_TARGETS=()
808-
809-
case "$(uname -s)" in
810-
Linux)
815+
case "$(uname -s -m)" in
816+
Linux\ x86_64)
811817
STDLIB_DEPLOYMENT_TARGETS=(
812818
"linux-x86_64"
813819
)
814820
;;
815-
816-
Darwin)
821+
Linux\ armv7*)
822+
STDLIB_DEPLOYMENT_TARGETS=(
823+
"linux-armv7"
824+
)
825+
;;
826+
Darwin\ x86_64)
817827
STDLIB_DEPLOYMENT_TARGETS=(
818828
"macosx-x86_64"
819829
"iphonesimulator-i386"
@@ -830,7 +840,7 @@ case "$(uname -s)" in
830840
)
831841
;;
832842

833-
FreeBSD)
843+
FreeBSD\ x86_64)
834844
STDLIB_DEPLOYMENT_TARGETS=(
835845
"freebsd-x86_64"
836846
)

0 commit comments

Comments
 (0)