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

Duplicate symbols produced in armv7-linux-androideabi staticlib targets starting with rustc 1.54 #93310

Closed
dcsommer opened this issue Jan 25, 2022 · 2 comments · Fixed by #93436

Comments

@dcsommer
Copy link
Contributor

dcsommer commented Jan 25, 2022

I see broken staticlib compilation when targeting armv7-linux-androideabi using any version of rustc >= 1.54, including 1.58.1. Specifically, there are a few symbols that are duplicated. Minimal repro below:

$ cat ~/test_c_abi.rs
#[allow(non_snake_case)]
pub unsafe extern "system" fn test_c_abi() {
    println!("Hello world, via C ABI");
}

# Works
$ rustup default 1.53.0
$ rustup target add armv7-linux-androideabi
$ rustc --edition 2018 --crate-type staticlib --target armv7-linux-androideabi ~/test_c_abi.rs
$ nm libtest_c_abi.a | grep __sync_fetch_and_xor_4
nm: sync_synchronize.o: no symbols
00000000 T __sync_fetch_and_xor_4

# Broken
$ rustup default 1.54.0
$ rustup target add armv7-linux-androideabi
$ rustc --edition 2018 --crate-type staticlib --target armv7-linux-androideabi ~/test_c_abi.rs
$ nm libtest_c_abi.a | grep __sync_fetch_and_xor_4
00000000 T __sync_fetch_and_xor_4
nm: sync_synchronize.o: no symbols
00000000 T __sync_fetch_and_xor_4

# Broken
$ rustup default stable
$ rustup target add armv7-linux-androideabi
$ rustc --edition 2018 --crate-type staticlib --target armv7-linux-androideabi ~/test_c_abi.rs && nm ~/libtest_c_abi.a | grep __sync_fetch_and_max_4
nm: rustc_std_workspace_alloc-6ce654723e7de624.rustc_std_workspace_alloc.2741db18-cgu.0.rcgu.o: no symbols
nm: cfg_if-ca080555ae93982b.cfg_if.454341be-cgu.0.rcgu.o: no symbols
00000000 T __sync_fetch_and_max_4
nm: sync_synchronize.o: no symbols
00000001 T __sync_fetch_and_max_4
nm: rustc_std_workspace_core-4ee656067d958762.rustc_std_workspace_core.d8c25046-cgu.0.rcgu.o: no symbols

An even easier way to confirm the issue is to directly look at the compiler builtins rlib for armv7-linux-androideabi:

$ cd ~/.rustup/toolchains
$ for x in */lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins*; do [ $(nm $x 2> /dev/null | grep -c __sync_fetch_and_xor_4) -gt 1 ] && echo "$x is broken" || echo "$x is okay"; done
1.53-x86_64-unknown-linux-gnu/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-51d05124e2182428.rlib is okay
1.54-x86_64-unknown-linux-gnu/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-b7a2613b4e9e1737.rlib is broken
stable-x86_64-unknown-linux-gnu/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-528fe7b1fd2894b6.rlib is broken

The regression may have happened in compiler_builtins between its version 0.1.39 and 0.1.45:

~/src/rust$ git show 1.53.0:Cargo.lock | grep -A 1 'name = "compiler_builtins"'
name = "compiler_builtins"
version = "0.1.39"
~/src/rust$ git show 1.54.0:Cargo.lock | grep -A 1 'name = "compiler_builtins"'
name = "compiler_builtins"
version = "0.1.45"

Linking this staticlib later results in duplicate symbol errors because of the above.

@dcsommer dcsommer changed the title Duplicate symbols produced in armv7-linux-androideabi staticlib targets starting with rustc 1.54 Duplicate symbols produced in armv7-linux-androideabi staticlib targets starting with rustc 1.54 Jan 25, 2022
@dcsommer
Copy link
Contributor Author

dcsommer commented Jan 26, 2022

Digging into the static libraries, I see the compiler_builtins-528fe7b1fd2894b6.compiler_builtins.11e6c744-cgu.174.rcgu.o object file now starts including the following duplicate __sync* symbols:

compiler_builtins-528fe7b1fd2894b6.compiler_builtins.11e6c744-cgu.174.rcgu.o:
       __sync_fetch_and_add_4
       __sync_fetch_and_and_4
       __sync_fetch_and_max_4
       __sync_fetch_and_min_4
       __sync_fetch_and_nand_4
       __sync_fetch_and_or_4
       __sync_fetch_and_sub_4
       __sync_fetch_and_umax_4
       __sync_fetch_and_umin_4
       __sync_fetch_and_xor_4

The above symbols are all already defined by separate single object files in all versions of rustc, resulting in duplicate symbols in 1.54+. They are contained in object files that look like this:

dcsommer@workP620:~$ nm ~/libtest_c_abi.a | grep -A 3 ^sync_fetch_.*4
sync_fetch_and_add_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_add_4

--
sync_fetch_and_and_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_and_4

--
sync_fetch_and_max_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_max_4

--
sync_fetch_and_min_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_min_4

--
sync_fetch_and_nand_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_nand_4

--
sync_fetch_and_or_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_or_4

--
sync_fetch_and_sub_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_sub_4

--
sync_fetch_and_umax_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_umax_4

--
sync_fetch_and_umin_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_umin_4

--
sync_fetch_and_xor_4.o:
00000000 t $a.0
00000001 T __sync_fetch_and_xor_4

Some of the symbols in compiler_builtins-528fe7b1fd2894b6.compiler_builtins.11e6c744-cgu.174.rcgu.o are new starting in 1.54 (not duplicates) and work fine:

00000000 T __sync_fetch_and_add_1
00000000 T __sync_fetch_and_add_2
00000000 T __sync_fetch_and_and_1
00000000 T __sync_fetch_and_and_2
00000000 T __sync_fetch_and_max_1
00000000 T __sync_fetch_and_max_2
00000000 T __sync_fetch_and_min_1
00000000 T __sync_fetch_and_min_2
00000000 T __sync_fetch_and_nand_1
00000000 T __sync_fetch_and_nand_2
00000000 T __sync_fetch_and_or_1
00000000 T __sync_fetch_and_or_2
00000000 T __sync_fetch_and_sub_1
00000000 T __sync_fetch_and_sub_2
00000000 T __sync_fetch_and_umax_1
00000000 T __sync_fetch_and_umax_2
00000000 T __sync_fetch_and_umin_1
00000000 T __sync_fetch_and_umin_2
00000000 T __sync_fetch_and_xor_1
00000000 T __sync_fetch_and_xor_2
00000000 T __sync_lock_test_and_set_1
00000000 T __sync_lock_test_and_set_2
00000000 T __sync_lock_test_and_set_4
00000000 T __sync_synchronize
00000000 T __sync_val_compare_and_swap_1
00000000 T __sync_val_compare_and_swap_2
00000000 T __sync_val_compare_and_swap_4

@dcsommer
Copy link
Contributor Author

dcsommer commented Jan 27, 2022

This might be related to rust-lang/compiler-builtins#420

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 1, 2022
Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib

I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes rust-lang#93310

See also rust-lang/compiler-builtins#449 and rust-lang/compiler-builtins#450
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 1, 2022
Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib

I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes rust-lang#93310

See also rust-lang/compiler-builtins#449 and rust-lang/compiler-builtins#450
@bors bors closed this as completed in 746b3d8 Feb 1, 2022
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Feb 22, 2022
…roideabi` rlib

I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes rust-lang#93310
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 a pull request may close this issue.

1 participant