Skip to content
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

Beginning support for ARMv7 hosts (RasPi, etc.) #439

Merged
merged 1 commit into from Dec 13, 2015
Merged

Beginning support for ARMv7 hosts (RasPi, etc.) #439

merged 1 commit into from Dec 13, 2015

Conversation

hpux735
Copy link
Contributor

@hpux735 hpux735 commented Dec 11, 2015

I'm almost finished with enabling native compilation on ARMv7 hosts such as the Raspberry Pi, BeagleBone, Nvidia Tegras, etc...

The build of the swift compiler and standard library complete. The compiler is also capable of generating executables, though there is a remaining linker problem. I'm not sure where to move from here, so I'm hoping that this work can be a starting point for some. The error is: unexpected reloc type 0x03

I've tested this patch in attempt to determine whether it negatively effects building on MacOS or Ubuntu 15.10 on x68_64. In MacOS, the test suite completes with 2 unexpected failures, 2350 expected passes, 5 expected failures, and 33 unsupported tests. The x86_64 linux build completes with 1682 expected passes, 92 expected failures, 575 unsupported failures (apparently no unexpected failures). Finally, the linux arm port completes the testing suite with 1456 expected passes, 81 expected failures, 639 unsupported tests, and 155 unexpected failures.

I'm happy to make any changes to requested, and I'd be overjoyed if anyone had a crumb trail I could follow to address the linking issued.

Any comments are very appreciated!

@gribozavr gribozavr self-assigned this Dec 11, 2015
set(SWIFT_PRIMARY_VARIANT_SDK_default "LINUX")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")

if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please leave a comment here that this only works for building a host compiler, and won't work for building cross-compilers.

@gribozavr
Copy link
Collaborator

There are soft float and hard float variants of armv7 ABI (and even multiple variants of those, IIRC). To ensure that the arm port is future-proof, the architecture name here needs to be something like armv7-gnueabihf to allow other variants. This is not necessarily something you need to worry about right now, but could you file an issue about taking care of that in future, when the port is in a better shape?

@@ -1115,8 +1115,13 @@ 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"));
#if defined(__arm__)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Swift is a cross-compiler, we don't do #ifs in the C++ sources. Please query the target and use the correct path. getTriple().getArchName(), I think, but it should also include the gnueabihf suffix, so please leave a fixme for that.

@gribozavr
Copy link
Collaborator

In general this looks good to me, please fix those issues and I'll merge.

@hpux735
Copy link
Contributor Author

hpux735 commented Dec 11, 2015

With this comment: "There are soft float and hard float variants of armv7 ABI (and even multiple variants of those, IIRC). To ensure that the arm port is future-proof, the architecture name here needs to be something like armv7-gnueabihf to allow other variants. This is not necessarily something you need to worry about right now, but could you file an issue about taking care of that in future, when the port is in a better shape?"

It's not clear with block of code you're referring to. You're absolutely correct that I have made no attempt to correctly handle soft-float versions, or any other abis, for that matter. I'd like to learn more about how the target triples are passed through the build scripts so that these are correctly handled, as well as eventual hope for cross-compiling.

I've implemented all of your suggestions (thank you for them!), and I'll let you know when I finish testing it all again.

@gribozavr
Copy link
Collaborator

It's not clear with block of code you're referring to.

I'm referring to the code in general, where it uses armv7 to identify the architecture.

I'd like to learn more about how the target triples are passed through the build scripts so that these are correctly handled, as well as eventual hope for cross-compiling.

Currently we don't have anything like hard/soft variants for any of the supported architectures, so there isn't anything you can look at. The first approximation would be to just use armv7-gnueabihf as the architecture name, I think. That will require some modifications to the compiler where we pass that name directly to LLVM.

// FIXME: This should also query the abi type (i.e. gnueabihf)
if (getTriple().getArch() == llvm::Triple::arm) {
Arguments.push_back(
context.Args.MakeArgString(Twine(RuntimeLibPath) + "/armv7/swift.ld"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just concatenate in getTriple().getArchName()? Or does it return something strange? If that's the case, convert the if chain to switch.

@gribozavr
Copy link
Collaborator

The patch LGTM with those few issues fixed. May I also ask you to squash the commits?

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")
else()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you make an explicit branch based on the CMAKE_SYSTEM_PROCESSOR value? This will simplify adding further ports.

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 believe that I've done this, but it's not clear from the pull request (apple:master hpux735:master) that it has been completed. Let me know if I need to try again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for being unclear, I meant instead of else() assuming armv7 using an explicit value here.

@gribozavr
Copy link
Collaborator

Thank you, merging!

gribozavr added a commit that referenced this pull request Dec 13, 2015
Beginning support for ARMv7 hosts (RasPi, etc.)
@gribozavr gribozavr merged commit f28d348 into apple:master Dec 13, 2015
@PopFlamingo
Copy link

Does this mean that now, we will be able to program in Swift on Raspberry Pi?

@hpux735
Copy link
Contributor Author

hpux735 commented Dec 13, 2015

Thanks Dmitri! I appreciate all of your comments!

We're getting close, Trevor. Swiftc can make executable files, but there is a remaining problem in the linker part of the process, so they can't run just yet.

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
Collaborator

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
Collaborator

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
Collaborator

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
Collaborator

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. :)

@hpux735
Copy link
Contributor Author

hpux735 commented Dec 20, 2015

@petevine I've finally finished a downloadable package for a working (but still very alpha) swift compiler and Foundation for ARM: http://www.housedillon.com/?p=2287

@MagaTailor
Copy link

Thanks, I'll give it a try on my Odroid.

EDIT:
Nope, doesn't work from an arbitrary directory:

swiftc hello.swift
<unknown>:0: error: opening import file for module 'SwiftShims': No such file or directory

What variables can be set to provide (presumably) the correct search paths?

@hpux735
Copy link
Contributor Author

hpux735 commented Dec 21, 2015

I didn't get the exact same error message, but it doesn't work for me, either.
Would you mind creating a bug report on bugs.swift.org?

@MagaTailor
Copy link

No problem if it's a bug and not user error. Depending on the absence/presence of -module-cache-path
SwiftShims was being created in some directory inside of, for example:

/tmp/org.llvm.clang.odroid/

after unpacking your distro in /tmp

@hpux735
Copy link
Contributor Author

hpux735 commented Dec 22, 2015

I think it’s just as likely that I don’t know how to make the distribution package correctly.

Joe Bell is looking into making a debian repository for publishing this. Hopefully he’s able to make that work a little better.

I definitely like having things in the issue tracker. Even if it ends up being user error, no worries, it can just be closed. Otherwise, I’m very likely to forget all the different little issues that people mention to me. The latter is a much worse outcome! :)

On Dec 21, 2015, at 12:01 PM, petevine notifications@github.com wrote:

No problem if it's a bug and not user error. Depending on the absence/presence of -module-cache-path
SwiftShims was being created in some directory inside of, for example:

/tmp/org.llvm.clang.odroid/

after unpacking your distro in /tmp


Reply to this email directly or view it on GitHub #439 (comment).

@iachievedit
Copy link
Contributor

@petevine Try out the package just posted at http://dev.iachieved.it/iachievedit/debian-packages-for-swift-on-arm/, both snippets of Swift code at the bottom of the post work on BeagleBone Black and BeagleBoard X15. I need to run out and get me a RaspPi 2, oddly enough I don't own one yet.

@MagaTailor
Copy link

I'll need a direct link as I'm not interested in installing system-wide. Thx.

@iachievedit
Copy link
Contributor

You can use apt-get download and dpkg -x:

root@beaglebone:~# cd /tmp
root@beaglebone:/tmp# apt-get download swift-2.2
Get:1 http://iachievedit-repos.s3.amazonaws.com/ jessie/main swift-2.2 armhf 1:2.2-0ubuntu7 [63.0 MB]
Fetched 63.0 MB in 14s (4,330 kB/s)                                                                                                                          
root@beaglebone:/tmp# dpkg -x swift-2.2_1%3a2.2-0ubuntu7_armhf.deb ./swift-2.2
root@beaglebone:/tmp# cd swift-2.2/
root@beaglebone:/tmp/swift-2.2# ls
usr
root@beaglebone:/tmp/swift-2.2# ./usr/bin/swiftc -v
Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 30f90dc111)
Target: armv7-unknown-linux-gnueabihf

@MagaTailor
Copy link

Thx, that's exactly what I had in mind. I'll let you know as soon as I've tried it out.
(and you don't need root just to do apt-get download BTW)

EDIT:
Nope, I'm getting the same error as before. From the strace it seems it's failing in an external process (clang?) so there's probably a problem with clang's configuration which fails to generate the object file.

https://bugs.swift.org/browse/SR-333

@hpux735
Copy link
Contributor Author

hpux735 commented Dec 22, 2015

Yah, I’m very confused. I can’t reproduce this bug. On my fresh install (are you using Ubuntu or Debian?), it works fine when I install at /opt/apple. The file you’re seeing in /tmp is generated by the build process. A huge part of the swift build process is clang. Can you paste in your source code, just in case?

On Dec 22, 2015, at 12:06 PM, petevine notifications@github.com wrote:

Nope, I'm getting the same error as before. From the strace it seems it's failing in an external process (clang?) so there's probably a problem with clang's configuration which fails to generate the object file.


Reply to this email directly or view it on GitHub #439 (comment).

@MagaTailor
Copy link

It's Ubuntu 14.04 so that probably means clang is not getting installed correctly. Code is just one line:
print("Hello, world!")

Could you paste your ls -l /usr/bin/clang*?

Mine looks like this:

lrwxrwxrwx 1 root root 23 Dec 22 10:42 /usr/bin/clang -> /etc/alternatives/clang
lrwxrwxrwx 1 root root 25 Dec 22 09:58 /usr/bin/clang++ -> /etc/alternatives/clang++
lrwxrwxrwx 1 root root 25 Apr 28  2015 /usr/bin/clang-3.6 -> ../lib/llvm-3.6/bin/clang
lrwxrwxrwx 1 root root 27 Apr 28  2015 /usr/bin/clang++-3.6 -> ../lib/llvm-3.6/bin/clang++
lrwxrwxrwx 1 root root 44 Apr 28  2015 /usr/bin/clang-apply-replacements-3.6 -> ../lib/llvm-3.6/bin/clang-apply-replacements
lrwxrwxrwx 1 root root 31 Apr 28  2015 /usr/bin/clang-check-3.6 -> ../lib/llvm-3.6/bin/clang-check
lrwxrwxrwx 1 root root 31 Apr 28  2015 /usr/bin/clang-query-3.6 -> ../lib/llvm-3.6/bin/clang-query
lrwxrwxrwx 1 root root 32 Apr 28  2015 /usr/bin/clang-rename-3.6 -> ../lib/llvm-3.6/bin/clang-rename
lrwxrwxrwx 1 root root 32 Apr 28  2015 /usr/bin/clang-tblgen-3.6 -> ../lib/llvm-3.6/bin/clang-tblgen
lrwxrwxrwx 1 root root 30 Apr 28  2015 /usr/bin/clang-tidy-3.6 -> ../lib/llvm-3.6/bin/clang-tidy

@iachievedit
Copy link
Contributor

@petevine I am on Ubuntu 14.04 as well, here is my version of Clang and /usr/bin listing:

root@arm:/usr/bin# dpkg -l|grep clang
ii  clang-3.6                           1:3.6-2ubuntu1~trusty1                    armhf        C, C++ and Objective-C compiler (LLVM based)
ii  libclang-common-3.6-dev             1:3.6-2ubuntu1~trusty1                    armhf        clang library - Common development package
ii  libclang1-3.6:armhf                 1:3.6-2ubuntu1~trusty1                    armhf        C interface to the clang library
root@arm:/usr/bin# ls -l clang*
lrwxrwxrwx 1 root root 23 Dec 18 13:59 clang -> /etc/alternatives/clang
lrwxrwxrwx 1 root root 25 Dec 18 13:59 clang++ -> /etc/alternatives/clang++
lrwxrwxrwx 1 root root 25 Apr 28  2015 clang-3.6 -> ../lib/llvm-3.6/bin/clang
lrwxrwxrwx 1 root root 27 Apr 28  2015 clang++-3.6 -> ../lib/llvm-3.6/bin/clang++
lrwxrwxrwx 1 root root 44 Apr 28  2015 clang-apply-replacements-3.6 -> ../lib/llvm-3.6/bin/clang-apply-replacements
lrwxrwxrwx 1 root root 31 Apr 28  2015 clang-check-3.6 -> ../lib/llvm-3.6/bin/clang-check
lrwxrwxrwx 1 root root 31 Apr 28  2015 clang-query-3.6 -> ../lib/llvm-3.6/bin/clang-query
lrwxrwxrwx 1 root root 32 Apr 28  2015 clang-rename-3.6 -> ../lib/llvm-3.6/bin/clang-rename
lrwxrwxrwx 1 root root 32 Apr 28  2015 clang-tblgen-3.6 -> ../lib/llvm-3.6/bin/clang-tblgen
lrwxrwxrwx 1 root root 30 Apr 28  2015 clang-tidy-3.6 -> ../lib/llvm-3.6/bin/clang-tidy
root@arm:/usr/bin# clang -v
Ubuntu clang version 3.6.0-2ubuntu1~trusty1 (tags/RELEASE_360/final) (based on LLVM 3.6.0)
Target: arm-unknown-linux-gnueabihf
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/arm-linux-gnueabihf/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/arm-linux-gnueabihf/4.8.4
Found candidate GCC installation: /usr/bin/../lib/gcc/arm-linux-gnueabihf/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/arm-linux-gnueabihf/4.9.1
Found candidate GCC installation: /usr/lib/gcc/arm-linux-gnueabihf/4.8
Found candidate GCC installation: /usr/lib/gcc/arm-linux-gnueabihf/4.8.4
Found candidate GCC installation: /usr/lib/gcc/arm-linux-gnueabihf/4.9
Found candidate GCC installation: /usr/lib/gcc/arm-linux-gnueabihf/4.9.1
Selected GCC installation: /usr/bin/../lib/gcc/arm-linux-gnueabihf/4.8
Candidate multilib: .;@m32
Selected multilib: .;@m32

Of course I can't reproduce your issue either, and I've installed the package on 3 different ARM systems, all armv7l based.

@MagaTailor
Copy link

The only apparent difference is gcc 4.9 on my system. Could you attach a strace from a successful compilation?

@hpux735
Copy link
Contributor Author

hpux735 commented Dec 23, 2015

Yep, sure thing: http://ramone.coas.oregonstate.edu/hello.trace

@hpux735
Copy link
Contributor Author

hpux735 commented Dec 23, 2015

I'm fairly certain that this is a duplicate of this bug: https://bugs.swift.org/browse/SR-23 and is not an Arm specific thing.

@MagaTailor
Copy link

@hpux735 That's definitely not a successful compilation! (source file didn't exist)

If the issue is not ARM-specific, never mind - I'll have a go at swift when it's ready.

@hpux735
Copy link
Contributor Author

hpux735 commented Dec 23, 2015

Oops. I updated it. Also note that I don’t think that it’s tracing the clang invocation. That’s likely where the issue really is.

On Dec 23, 2015, at 1:45 AM, petevine notifications@github.com wrote:

@hpux735 https://github.com/hpux735 That's definitely not a successful compilation! (source file didn't exist)


Reply to this email directly or view it on GitHub #439 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants