Skip to content

Bitode fembed-bitcode-marker breaking iOS debug builds #301

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

Closed
kali opened this issue Mar 15, 2018 · 8 comments
Closed

Bitode fembed-bitcode-marker breaking iOS debug builds #301

kali opened this issue Mar 15, 2018 · 8 comments

Comments

@kali
Copy link
Contributor

kali commented Mar 15, 2018

Hi,

It looks like the -fembed-bitcode-marker breaks the debug builds (it is not set on release bug).

To be honest, I'm not 100% sure where the actual issue is, but something looses track of the actually compiled symbols somewhere.

Here is a test-case. A rust wrapper library with a -sys underneath (with a void native_function() {} ), try to build test on the rusty wrapper.

First run: native, macos for reference.
Second run: test targetting ios, missing symbols while linking.
Third run: same with --release, disabling the fembed-bitcode-marker as a side effect, it compiles.

Forcing cc back to 1.0.5 make the probelm disappear. Or Using a patched cc-rs that do not put the bintcode-marker.

S 15/03 9:42 ~/dev/snips/tc-init-bitcode-marker% cargo test
   Compiling cc v1.0.7
   Compiling tc-init-bitcode-marker-sys v0.1.0 (file:///Users/kali/dev/snips/tc-init-bitcode-marker/tc-init-bitcode-marker-sys)
   Compiling tc-init-bitcode-marker v0.1.0 (file:///Users/kali/dev/snips/tc-init-bitcode-marker)
    Finished dev [unoptimized + debuginfo] target(s) in 2.73 secs
     Running target/debug/deps/tc_init_bitcode_marker-c331333640f6d205

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests tc-init-bitcode-marker

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

S 15/03 9:42 ~/dev/snips/tc-init-bitcode-marker% TARGET_SYSROOT=`xcrun -sdk iphoneos --show-sdk-path` cargo test --target aarch64-apple-ios
   Compiling tc-init-bitcode-marker-sys v0.1.0 (file:///Users/kali/dev/snips/tc-init-bitcode-marker/tc-init-bitcode-marker-sys)
   Compiling tc-init-bitcode-marker v0.1.0 (file:///Users/kali/dev/snips/tc-init-bitcode-marker)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-arch" "arm64" "-Wl,-syslibroot" "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk" "-L" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/deps/tc_init_bitcode_marker-5b76daec38646eb8.1bi40wzgjfa2z8fe.rcgu.o" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/deps/tc_init_bitcode_marker-5b76daec38646eb8.1y16o1qfye96o7m0.rcgu.o" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/deps/tc_init_bitcode_marker-5b76daec38646eb8.2k322vp0xntl1vb2.rcgu.o" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/deps/tc_init_bitcode_marker-5b76daec38646eb8.3rngp6bm2u2q5z0y.rcgu.o" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/deps/tc_init_bitcode_marker-5b76daec38646eb8.twro57p54np36np.rcgu.o" "-o" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/deps/tc_init_bitcode_marker-5b76daec38646eb8" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/deps/tc_init_bitcode_marker-5b76daec38646eb8.crate.allocator.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/deps" "-L" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/debug/deps" "-L" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/build/tc-init-bitcode-marker-sys-bcd7b7491fb82c24/out" "-L" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib" "/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/debug/deps/libtc_init_bitcode_marker_sys-f1d44cb505be7d46.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/libtest-24fa6627a68aaf09.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/libterm-18625f57bc60e498.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/libgetopts-85228cbd7e544789.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/libstd-df91e356061f8ac8.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/libpanic_unwind-1086e1d0e6cd90ef.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/libunwind-ce923fc11d74f968.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/liballoc_system-e87ca03f4215e4ef.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/liblibc-e959e9c0d1548c0e.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/liballoc-37638280ec40d743.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/libstd_unicode-0766335b25639e9e.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/libcore-e1a6bc6fd1c79bbc.rlib" "/Users/kali/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-ios/lib/libcompiler_builtins-c410c86b18328824.rlib" "-l" "System" "-l" "objc" "-framework" "Security" "-framework" "Foundation" "-l" "resolv" "-l" "c" "-l" "m"
  = note: Undefined symbols for architecture arm64:
            "_native_function", referenced from:
                tc_init_bitcode_marker::call_it::h8098132b2999850c in tc_init_bitcode_marker-5b76daec38646eb8.1bi40wzgjfa2z8fe.rcgu.o
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: aborting due to previous error

error: Could not compile `tc-init-bitcode-marker`.

To learn more, run the command again with --verbose.
[1]    55263 exit 101   TARGET_SYSROOT=`xcrun -sdk iphoneos --show-sdk-path` cargo test --target
S 15/03 9:42 ~/dev/snips/tc-init-bitcode-marker% TARGET_SYSROOT=`xcrun -sdk iphoneos --show-sdk-path` cargo test --target aarch64-apple-ios  --release
   Compiling cc v1.0.7
   Compiling tc-init-bitcode-marker-sys v0.1.0 (file:///Users/kali/dev/snips/tc-init-bitcode-marker/tc-init-bitcode-marker-sys)
   Compiling tc-init-bitcode-marker v0.1.0 (file:///Users/kali/dev/snips/tc-init-bitcode-marker)
    Finished release [optimized] target(s) in 5.20 secs
     Running target/aarch64-apple-ios/release/deps/tc_init_bitcode_marker-5701cd311fc4ffc2
error: could not execute process `/Users/kali/dev/snips/tc-init-bitcode-marker/target/aarch64-apple-ios/release/deps/tc_init_bitcode_marker-5701cd311fc4ffc2` (never executed)

Caused by:
  Bad CPU type in executable (os error 86)
[1]    55299 exit 101   TARGET_SYSROOT=`xcrun -sdk iphoneos --show-sdk-path` cargo test --target
@kali
Copy link
Contributor Author

kali commented Mar 15, 2018

@kali
Copy link
Contributor Author

kali commented Mar 15, 2018

I was able to do a few more tests while investigating the issue. Specifically, nm do not see any symbol in both static libraries formed when the option is set (the .a and the .rlib)

S 15/03 9:53 ~/dev/snips/tc-init-bitcode-marker% nm target/aarch64-apple-ios/debug/build/tc-init-bitcode-marker-sys-10a81f0c360f171f/out/libfoo.a
S 15/03 9:53 ~/dev/snips/tc-init-bitcode-marker% nm target/aarch64-apple-ios/debug/deps/libtc_init_bitcode_marker_sys-1c0d20b841b3adaa.rlib

target/aarch64-apple-ios/debug/deps/libtc_init_bitcode_marker_sys-1c0d20b841b3adaa.rlib(tc_init_bitcode_marker_sys-1c0d20b841b3adaa.1y16o1qfye96o7m0.rcgu.o):
0000000000000000 t ltmp0
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: target/aarch64-apple-ios/debug/deps/libtc_init_bitcode_marker_sys-1c0d20b841b3adaa.rlib(rust.metadata.bin) The end of the file was unexpectedly encountered

S 15/03 9:53 ~/dev/snips/tc-init-bitcode-marker% nm target/aarch64-apple-ios/debug/deps/libtc_init_bitcode_marker-270d3cfb64419d79.rlib

target/aarch64-apple-ios/debug/deps/libtc_init_bitcode_marker-270d3cfb64419d79.rlib(tc_init_bitcode_marker-270d3cfb64419d79.1bi40wzgjfa2z8fe.rcgu.o):
0000000000000000 T __ZN22tc_init_bitcode_marker7call_it17h3e65230248e881c3E
                 U _native_function
0000000000000000 t ltmp0
0000000000000258 s ltmp1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: target/aarch64-apple-ios/debug/deps/libtc_init_bitcode_marker-270d3cfb64419d79.rlib(rust.metadata.bin) The end of the file was unexpectedly encountered

[1]    56122 exit 1     nm
S 15/03 9:53 ~/dev/snips/tc-init-bitcode-marker% nm target/aarch64-apple-ios/debug/build/tc-init-bitcode-marker-sys-10a81f0c360f171f/out/libfoo.a

@kali
Copy link
Contributor Author

kali commented Mar 15, 2018

I think we should probably not put this second option automatically. The --enable-bitcode do not look like a problem.

@alexcrichton
Copy link
Member

cc @comex and @michaeleiselsc, would y'all be able to help diagnose what's going on here?

FWIW @kali the change here was spurred on by discussion in rust-lang/rust#35968, but I'm very unfamiliar with iOS myself :(

@michaeleiselsc
Copy link

i thought bitcode support would be disabled by default? if so, can't we just use the previous behavior unless the user has added that -Z flag for bitcode?

@alexcrichton
Copy link
Member

@michaeleiselsc it was in Rust yeah but that was after I made this change. How would you expect to enable this for the cc crate?

@comex
Copy link

comex commented Mar 15, 2018

Looks like the same LLVM bug I mentioned in rust-lang/rust#48896 (comment). As I said there,

For now, as a workaround for the LLVM bug, I think the best approach is to avoid -fembed-bitcode-marker or equivalent, in both this PR and cc-rs.

I guess I should have filed an issue in this repository too…

@alexcrichton
Copy link
Member

Ah right thanks for the heads up @comex!

This was fixed by @kali in #305 (thanks!)

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

No branches or pull requests

4 participants