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

[SR-16017] [Regression] Compiler generates invalid binaries for 32-bit ARM when compiled with -O #58278

Closed
colemancda opened this issue Mar 18, 2022 · 5 comments
Assignees
Labels
armv7 Architecture: ARMv7 bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software not a bug Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error run-time crash Bug → crash: Swift code crashed during execution

Comments

@colemancda
Copy link
Contributor

Previous ID SR-16017
Radar None
Original Reporter @colemancda
Type Bug
Status Reopened
Resolution

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @colemancda
Priority Medium

md5: 43897ff6042081648c068eda1fd62752

Issue Description:

A simple hello world program that cross compiled in Swift 5.5.3 now produces invalid binaries in 5.6 with `bus error`.

@colemancda
Copy link
Contributor Author

Buildroot patch:

https://gist.github.com/colemancda/e2d7923b51697edec61c0004dfece150

Buildroot config for Armv7:

https://gist.github.com/colemancda/9d8a9a6dcef9f6ae500be5ec31cb1f7c

Just change SWIFT_VERSION = 5.5.3 in Swift.mk for SWIFT_VERSION = 5.6 and it will successfully build a Armv7 binary, however this binary crashes both in QEMU and on real hardware.

@finagolfin
Copy link
Contributor

I am unable to reproduce with my Android armv7 SDK when cross-compiling with a prebuilt Swift 5.6 for linux x86_64 by using a modified version of the command from the compiler's Android doc:

./swift-5.6-RELEASE-ubuntu20.04/usr/bin/swiftc -tools-directory /home/butta/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/ -target armv7-unknown-linux-androideabi24 -sdk android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/ -resource-dir swift-5.6-android-armv7-24-sdk/usr/lib/swift swift/test/Interpreter/hello_toplevel.swift

The async hello world swift/test/Interpreter/async.swift also works, if I add the -parse-as-library flag when cross-compiling. I can also cross-compile Swift packages for Android armv7 using SPM and run the tests for packages like swift-argument-parser, swift-crypto, and swift-nio by using the instructions in my SDK doc.

This suggests the problem is not with armv7 but with the particular way you are building, which may have worked with Swift 5.5 but not 5.6.

@colemancda
Copy link
Contributor Author

@buttaface I was able to cross compile the Swift stdlib for Debian 11 (armhf), so this must be an issue with the Swift Buildroot package.

https://github.com/colemancda/swift-armv7

@colemancda
Copy link
Contributor Author

@buttaface After some digging and diffing the cmake cache files, I discovered that the culprit was the default Swift flags.

//Swift Compiler Flags during all build types.
CMAKE_Swift_FLAGS:STRING=
CMAKE_Swift_FLAGS_DEBUG:STRING=-g
CMAKE_Swift_FLAGS_MINSIZEREL:STRING=-Osize
CMAKE_Swift_FLAGS_RELEASE:STRING=-O
CMAKE_Swift_FLAGS_RELWITHDEBINFO:STRING=-O -g

And was able to get a valid binary with the following flags
-DCMAKE_Swift_FLAGS="" \
-DCMAKE_Swift_FLAGS_RELEASE="" \
-DCMAKE_Swift_FLAGS_RELWITHDEBINFO="" \

@colemancda
Copy link
Contributor Author

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added run-time crash Bug → crash: Swift code crashed during execution armv7 Architecture: ARMv7 not a bug Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error and removed bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. labels Nov 7, 2022
@AnthonyLatsis AnthonyLatsis added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Nov 14, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
armv7 Architecture: ARMv7 bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software not a bug Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

3 participants