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-14126] Regression: Cross-compile host to iPhoneOS stopped working #56507

Closed
swift-ci opened this issue Jan 29, 2021 · 11 comments
Closed

[SR-14126] Regression: Cross-compile host to iPhoneOS stopped working #56507

swift-ci opened this issue Jan 29, 2021 · 11 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. build-script Area → utils: The build script cmake compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14126
Radar rdar://problem/73770091
Original Reporter yoni (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

macOS 11.1

Swift cloned from https://github.com/apple/swift

Main branch.

Built with Ninja.

Clang version 12.0.0 (clang-1200.0.32.28)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, BuildScript, CMake
Assignee @CodaFi
Priority Medium

md5: 57805d3b9702704ea008460f92552183

Issue Description:

Cross-compiling Swift for iOS (using cross-compile-hosts=iphoneos-arm64) has recently stopped working.

I suspect the issue comes from deprecating min-version in this recent commit.

Seems min-version parameter might still be required by clang (using latest version 12.0.0 (clang-1200.0.32.28)).

On the first target (cmark-iphoneos-arm64), clang emits:
clang: warning: argument unused during compilation: '-arch arm64' [-Wunused-command-line-argument]
ld: warning: ignoring file CMakeFiles/cmTC_00702.dir/testCCompiler.c.o, building for iOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
{{ ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/lib/libSystem.tbd, missing required architecture x86_64 in file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/lib/libSystem.tbd (4 slices)}}
{{ Undefined symbols for architecture x86_64:}}
{{ "_main", referenced from:}}
{{ implicit entry/start for main executable}}
{{ ld: symbol(s) not found for architecture x86_64}}

For reference, the build flags for CMakeCCompilerId.o in latest code is:
;;-Wno-unknown-warning-option;-Werror=unguarded-availability-new;-arch;arm64;-target;arm64-apple-iphoneos14.0;-fno-stack-protector

which produce a wrong file type of:
ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), not stripped

And the build flags from before the commit, which works:
;;-Wno-unknown-warning-option;-Werror=unguarded-availability-new;-arch;arm64;;-miphoneos-version-min=14.0;-fno-stack-protector

And correctly produce a Mach-O 64-bit object arm64.

{{ }}

@swift-ci
Copy link
Collaborator Author

Comment by Jonathan Hemi (JIRA)

CodaFi (JIRA User) would really appreciate your eyes on this if you get a a chance.

@CodaFi
Copy link
Member

CodaFi commented Jan 29, 2021

Could you provide the link line being emitted by clang? If that doesn’t contain a suitable -platform_version it will fall back to the host’s platform which id what it seems to be doing here.

@swift-ci
Copy link
Collaborator Author

Comment by Jonathan Hemi (JIRA)

I think this is everything, also attached the entire folders since they're small.

– Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
– Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - broken
CMake Error at /usr/local/Cellar/cmake/3.19.3/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
{{ The C compiler}}

"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /Users/jonathan/try/sw/host-build/Ninja-Release/cmark-iphoneos-arm64/CMakeFiles/CMakeTmp

{{ Run Build Command(s):/usr/local/bin/ninja cmTC_51f01 && [1/2][ 50%][0.034s] Building C object CMakeFiles/cmTC_51f01.dir/testCCompiler.c.o}}
{{ [2/2][100%][0.093s] Linking C executable cmTC_51f01}}
{{ FAILED: cmTC_51f01 }}
{{ : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Wno-unknown-warning-option -Werror=unguarded-availability-new -arch arm64 -target arm64-apple-iphoneos14.0 -fno-stack-protector -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_51f01.dir/testCCompiler.c.o -o cmTC_51f01 && :}}
{{ clang: warning: argument unused during compilation: '-arch arm64' [-Wunused-command-line-argument]}}
{{ clang: warning: argument unused during compilation: '-arch arm64' [-Wunused-command-line-argument]}}
{{ ld: warning: ignoring file CMakeFiles/cmTC_51f01.dir/testCCompiler.c.o, building for iOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )}}
{{ ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/lib/libSystem.tbd, missing required architecture x86_64 in file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/lib/libSystem.tbd (4 slices)}}
{{ Undefined symbols for architecture x86_64:}}
{{ "_main", referenced from:}}
{{ implicit entry/start for main executable}}
{{ ld: symbol(s) not found for architecture x86_64}}
{{ clang: error: linker command failed with exit code 1 (use -v to see invocation)}}
{{ clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)}}
{{ ninja: build stopped: subcommand failed.}}

{{ }}

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
{{ CMakeLists.txt:2 (project)}}

– Configuring incomplete, errors occurred!
See also "/Users/jonathan/try/sw/host-build/Ninja-Release/cmark-iphoneos-arm64/CMakeFiles/CMakeOutput.log".
See also "/Users/jonathan/try/sw/host-build/Ninja-Release/cmark-iphoneos-arm64/CMakeFiles/CMakeError.log".
ERROR: command terminated with a non-zero exit status 1, aborting

ERROR: command terminated with a non-zero exit status 1, aborting

@swift-ci
Copy link
Collaborator Author

Comment by Jonathan Hemi (JIRA)

But the host is macOS, isn't the ELF a weird outcome?

@CodaFi
Copy link
Member

CodaFi commented Jan 29, 2021

Perhaps the issue is the old-style triple. Try `arm64-apple-ios14.0`. You may need to reconfigure your build.

@swift-ci
Copy link
Collaborator Author

Comment by Jonathan Hemi (JIRA)

No luck. It will not create the output folders, failing with:

[/Users/jonathan/try/sw/swift/utils/build-script] NOTE: Using toolchain default
+ /usr/libexec/PlistBuddy -c 'Print :SupportedTargets:macosx:Archs' /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/SDKSettings.plist
+ mkdir -p /Users/jonathan/try/sw/host-build/Ninja-Release
ERROR: unknown target: arm64-apple-ios14.0
ERROR: command terminated with a non-zero exit status 1, aborting

The error is coming from here and the expected triple format is parsed here (seems iphoneos-arm64 is the only valid option).

@swift-ci
Copy link
Collaborator Author

Comment by Jonathan Hemi (JIRA)

I think I can distill it to the simplest clang invocation of a 'return 0' c program:

~ clang -arch arm64 -target arm64-apple-iphoneos14.0 ./hello.c
ld: warning: ignoring file /var/folders/7f/tdyh3rw96rq2nf0w95btmb4h0000gn/T/hello-515e59.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
Undefined symbols for architecture x86_64:
{{ "_main", referenced from:}}
{{ implicit entry/start for main executable}}
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

vs.

~ clang -arch arm64 -miphoneos-version-min=14.0 ./hello.c
clang: warning: using sysroot for 'MacOSX' but targeting 'iPhone' [-Wincompatible-sysroot]
[... more warnings because I don't pass correct SDKs]

Get a Mach-O 64-bit executable arm64

@typesanitizer
Copy link

@swift-ci create

@CodaFi
Copy link
Member

CodaFi commented Jan 30, 2021

Okay, it's definitely the old-style triple being passed to clang (not to build script). Check out the difference here

clang -Wno-unknown-warning-option -Werror=unguarded-availability-new -arch arm64 -target arm64-apple-ios14.0 -fno-stack-protector -v -c /Users/rwidmann/Downloads/cmark-iphoneos-arm64/CMakeFiles/3.19.3/CompilerIdC/CMakeCCompilerId.c -o /Users/rwidmann/Downloads/cmark-iphoneos-arm64/CMakeFiles/3.19.3/CompilerIdC/CMakeCCompilerId.o

objdump --headers /Users/rwidmann/Downloads/cmark-iphoneos-arm64/CMakeFiles/3.19.3/CompilerIdC/CMakeCCompilerId.o | head -n 2

/Users/rwidmann/Downloads/cmark-iphoneos-arm64/CMakeFiles/3.19.3/CompilerIdC/CMakeCCompilerId.o:    file format mach-o arm64

versus

clang -Wno-unknown-warning-option -Werror=unguarded-availability-new -arch arm64 -target arm64-apple-iphoneos14.0 -fno-stack-protector -v -c /Users/rwidmann/Downloads/cmark-iphoneos-arm64/CMakeFiles/3.19.3/CompilerIdC/CMakeCCompilerId.c -o /Users/rwidmann/Downloads/cmark-iphoneos-arm64/CMakeFiles/3.19.3/CompilerIdC/CMakeCCompilerId.o 

objdump --headers /Users/rwidmann/Downloads/cmark-iphoneos-arm64/CMakeFiles/3.19.3/CompilerIdC/CMakeCCompilerId.o | head -n 2

/Users/rwidmann/Downloads/cmark-iphoneos-arm64/CMakeFiles/3.19.3/CompilerIdC/CMakeCCompilerId.o:    file format elf64-littleaarch64

@CodaFi
Copy link
Member

CodaFi commented Jan 30, 2021

Please ensure you have this patch applied to your checkout f9be289b9e04b3d7650a6c093e624ff321cf399b, then remove your build directory and rerun the build.

@swift-ci
Copy link
Collaborator Author

Comment by Jonathan Hemi (JIRA)

Just saw the patch. Indeed this solves the issue.

Thanks so much!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. build-script Area → utils: The build script cmake compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants