Skip to content
Merged
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
20 changes: 15 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,18 +385,28 @@ endfunction()
# FIXME: separate the notions of SDKs used for compiler tools and target
# binaries.
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
configure_sdk_unix(LINUX "Linux" "linux" "linux" "x86_64" "x86_64-unknown-linux-gnu")

set(CMAKE_EXECUTABLE_FORMAT "ELF")

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

set(SWIFT_HOST_VARIANT_SDK "LINUX")
set(SWIFT_HOST_VARIANT_ARCH "x86_64")

set(SWIFT_PRIMARY_VARIANT_SDK_default "LINUX")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")

# FIXME: This will not work while trying to cross-compile
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
configure_sdk_unix(LINUX "Linux" "linux" "linux" "x86_64" "x86_64-unknown-linux-gnu")
set(SWIFT_HOST_VARIANT_ARCH "x86_64")
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")
set(SWIFT_HOST_VARIANT_ARCH "armv7")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "armv7")
else()
message(FATAL_ERROR "Unknown or unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()

elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
configure_sdk_unix(FREEBSD "FreeBSD" "freebsd" "freebsd" "x86_64" "x86_64-freebsd10")

Expand Down
6 changes: 4 additions & 2 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
// Add the linker script that coalesces protocol conformance sections.
Arguments.push_back("-Xlinker");
Arguments.push_back("-T");
Arguments.push_back(
context.Args.MakeArgString(Twine(RuntimeLibPath) + "/x86_64/swift.ld"));

// FIXME: This should also query the abi type (i.e. gnueabihf)
Copy link
Contributor

Choose a reason for hiding this comment

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

@hpux735 @gribozavr Sorry if I'm missing something, but would something like the following work?

diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 712ea65..872843a 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -1115,10 +1115,11 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
   // Add the linker script that coalesces protocol conformance sections.
   Arguments.push_back("-Xlinker");
   Arguments.push_back("-T");
-
-  // FIXME: This should also query the abi type (i.e. gnueabihf)
+
   Arguments.push_back(context.Args.MakeArgString(
-    Twine(RuntimeLibPath) + "/" + getTriple().getArchName() + "/swift.ld"));
+    Twine(RuntimeLibPath) + "/" + getTriple().getArchName() + \
+    llvm::Triple::getEnvironmentTypeName(getTriple().getEnvironment()) + \
+    "/swift.ld"));

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, with a dash in between.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome. I'll send a pull request; there's also a test that needs updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you’ll need to update the location where the stdlib is built into, otherwise the paths won’t match. I tried this last night.

On Dec 14, 2015, at 7:25 AM, Brian Gesiak notifications@github.com wrote:

In lib/Driver/ToolChains.cpp #439 (comment):

@@ -1115,8 +1115,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
// Add the linker script that coalesces protocol conformance sections.
Arguments.push_back("-Xlinker");
Arguments.push_back("-T");

  • Arguments.push_back(
  •  context.Args.MakeArgString(Twine(RuntimeLibPath) + "/x86_64/swift.ld"));
    
  • // FIXME: This should also query the abi type (i.e. gnueabihf)
    Awesome. I'll send a pull request; there's also a test that needs updating.


Reply to this email directly or view it on GitHub https://github.com/apple/swift/pull/439/files#r47509595.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, gotcha. Looks like it isn't as simple as I thought in #536, then. 😛

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a good idea, but there's just one more piece to the puzzle. :)

Arguments.push_back(context.Args.MakeArgString(
Twine(RuntimeLibPath) + "/" + getTriple().getArchName() + "/swift.ld"));

// This should be the last option, for convenience in checking output.
Arguments.push_back("-o");
Expand Down
4 changes: 4 additions & 0 deletions stdlib/public/SwiftShims/LibcShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ namespace swift { extern "C" {

// This declaration is not universally correct. We verify its correctness for
// the current platform in the runtime code.
#if defined(__linux__) && defined (__arm__)
typedef int __swift_ssize_t;
#else
typedef long int __swift_ssize_t;
#endif

// General utilities <stdlib.h>
// Memory management functions
Expand Down
51 changes: 50 additions & 1 deletion stdlib/public/stubs/Stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ extern "C" long double _swift_fmodl(long double lhs, long double rhs) {
// This implementation is copied here to avoid a new dependency
// on compiler-rt on Linux.
// FIXME: rdar://14883575 Libcompiler_rt omits muloti4
#if __arm64__ || !defined(__APPLE__)
#if (defined(__APPLE__) && defined(__arm64__)) || \
(defined(__linux__) && defined(__x86_64__))

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

#endif

#if defined(__linux__) && defined(__arm__)
// Similar to above, but with mulodi4. Perhaps this is
// something that shouldn't be done, and is a bandaid over
// some other lower-level architecture issue that I'm
// missing. Perhaps relevant bug report:
// FIXME: https://llvm.org/bugs/show_bug.cgi?id=14469
typedef int di_int __attribute__ ((mode (DI)));
extern "C"
di_int
__mulodi4(di_int a, di_int b, int* overflow)
{
const int N = (int)(sizeof(di_int) * CHAR_BIT);
const di_int MIN = (di_int)1 << (N-1);
const di_int MAX = ~MIN;
*overflow = 0;
di_int result = a * b;
if (a == MIN)
{
if (b != 0 && b != 1)
*overflow = 1;
return result;
}
if (b == MIN)
{
if (a != 0 && a != 1)
*overflow = 1;
return result;
}
di_int sa = a >> (N - 1);
di_int abs_a = (a ^ sa) - sa;
di_int sb = b >> (N - 1);
di_int abs_b = (b ^ sb) - sb;
if (abs_a < 2 || abs_b < 2)
return result;
if (sa == sb)
{
if (abs_a > MAX / abs_b)
*overflow = 1;
}
else
{
if (abs_a > MIN / -abs_b)
*overflow = 1;
}
return result;
}
#endif

// We can't return Float80, but we can receive a pointer to one, so
// switch the return type and the out parameter on strtold.
template <typename T>
Expand Down
56 changes: 37 additions & 19 deletions test/Driver/linker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
// RUN: FileCheck -check-prefix watchOS_SIMPLE %s < %t.simple.txt

// 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
// RUN: FileCheck -check-prefix LINUX %s < %t.linux.txt
// RUN: FileCheck -check-prefix LINUX-x86_64 %s < %t.linux.txt

// RUN: %swiftc_driver -driver-print-jobs -target armv7-unknown-linux-gnueabihf -Ffoo -framework bar -Lbaz -lboo -Xlinker -undefined %s 2>&1 > %t.linux.txt
// RUN: FileCheck -check-prefix LINUX-armv7 %s < %t.linux.txt

// 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
// RUN: FileCheck %s < %t.complex.txt
// RUN: FileCheck -check-prefix COMPLEX %s < %t.complex.txt

// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -g %s | FileCheck -check-prefix DEBUG %s

// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.10 %s | FileCheck -check-prefix NO_ARCLITE %s
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-ios8.0 %s | FileCheck -check-prefix NO_ARCLITE %s
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.10 %s | FileCheck -check-prefix NO_ARCLITE %s
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-ios8.0 %s | FileCheck -check-prefix NO_ARCLITE %s

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


// LINUX: swift
// LINUX: -o [[OBJECTFILE:.*]]

// LINUX: clang++{{"? }}
// LINUX-DAG: [[OBJECTFILE]]
// LINUX-DAG: -lswiftCore
// LINUX-DAG: -L [[STDLIB_PATH:[^ ]+/lib/swift]]
// LINUX-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
// LINUX-DAG: -Xlinker -T /{{[^ ]+}}/linux/x86_64/swift.ld
// LINUX-DAG: -F foo
// LINUX-DAG: -framework bar
// LINUX-DAG: -L baz
// LINUX-DAG: -lboo
// LINUX-DAG: -Xlinker -undefined
// LINUX: -o linker
// LINUX-x86_64: swift
// LINUX-x86_64: -o [[OBJECTFILE:.*]]

// LINUX-x86_64: clang++{{"? }}
// LINUX-x86_64-DAG: [[OBJECTFILE]]
// LINUX-x86_64-DAG: -lswiftCore
// LINUX-x86_64-DAG: -L [[STDLIB_PATH:[^ ]+/lib/swift]]
// LINUX-x86_64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
// LINUX-x86_64-DAG: -Xlinker -T /{{[^ ]+}}/linux/x86_64/swift.ld
// LINUX-x86_64-DAG: -F foo
// LINUX-x86_64-DAG: -framework bar
// LINUX-x86_64-DAG: -L baz
// LINUX-x86_64-DAG: -lboo
// LINUX-x86_64-DAG: -Xlinker -undefined
// LINUX-x86_64: -o linker

// LINUX-armv7: swift
// LINUX-armv7: -o [[OBJECTFILE:.*]]

// LINUX-armv7: clang++{{"? }}
// LINUX-armv7-DAG: [[OBJECTFILE]]
// LINUX-armv7-DAG: -lswiftCore
// LINUX-armv7-DAG: -L [[STDLIB_PATH:[^ ]+/lib/swift]]
// LINUX-armv7-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
// LINUX-armv7-DAG: -Xlinker -T /{{[^ ]+}}/linux/armv7/swift.ld
// LINUX-armv7-DAG: -F foo
// LINUX-armv7-DAG: -framework bar
// LINUX-armv7-DAG: -L baz
// LINUX-armv7-DAG: -lboo
// LINUX-armv7-DAG: -Xlinker -undefined
// LINUX-armv7: -o linker

// COMPLEX: bin/ld{{"? }}
// COMPLEX-DAG: -dylib
Expand Down
2 changes: 1 addition & 1 deletion test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ if run_vendor == 'apple':
"%s ld -L%s" %
(xcrun_prefix, os.path.join(test_resource_dir, config.target_sdk_name)))

elif run_os == 'linux-gnu':
elif run_os == 'linux-gnu' or run_os == 'linux-gnueabihf':
# Linux
lit_config.note("Testing Linux " + config.variant_triple)
config.target_object_format = "elf"
Expand Down
36 changes: 23 additions & 13 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ function set_deployment_target_based_options() {
linux-x86_64)
SWIFT_HOST_VARIANT_ARCH="x86_64"
;;
linux-armv7)
SWIFT_HOST_VARIANT_ARCH="armv7"
;;
freebsd-x86_64)
SWIFT_HOST_VARIANT_ARCH="x86_64"
;;
Expand Down Expand Up @@ -730,8 +733,8 @@ if [[ "$(uname -s)" == "Darwin" ]] ; then
TOOLCHAIN_PREFIX=$(echo ${INSTALL_PREFIX} | sed -E 's/\/usr$//')
fi

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

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

# Determine the native deployment target for the build machine, that will be
# used to jumpstart the standard library build when cross-compiling.
case "$(uname -s)" in
Linux)
case "$(uname -s -m)" in
Linux\ x86_64)
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
"linux-x86_64"
)
;;

Darwin)
Linux\ armv7*)
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
"linux-armv7"
)
;;
Darwin\ x86_64)
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
"macosx-x86_64"
)
;;

FreeBSD)
FreeBSD\ x86_64)
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
"freebsd-x86_64"
)
Expand Down Expand Up @@ -805,15 +812,18 @@ function is_cross_tools_deployment_target() {
# A list of deployment targets that we compile or cross-compile the
# Swift standard library for.
STDLIB_DEPLOYMENT_TARGETS=()

case "$(uname -s)" in
Linux)
case "$(uname -s -m)" in
Linux\ x86_64)
STDLIB_DEPLOYMENT_TARGETS=(
"linux-x86_64"
)
;;

Darwin)
Linux\ armv7*)
STDLIB_DEPLOYMENT_TARGETS=(
"linux-armv7"
)
;;
Darwin\ x86_64)
STDLIB_DEPLOYMENT_TARGETS=(
"macosx-x86_64"
"iphonesimulator-i386"
Expand All @@ -830,7 +840,7 @@ case "$(uname -s)" in
)
;;

FreeBSD)
FreeBSD\ x86_64)
STDLIB_DEPLOYMENT_TARGETS=(
"freebsd-x86_64"
)
Expand Down