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

fix: prevent link-time openssl symbols conflicts #10

Merged
merged 13 commits into from
Sep 10, 2024

Conversation

Rjected
Copy link
Contributor

@Rjected Rjected commented Sep 10, 2024

Renames the symbols by preprocessing, to prevent conflicts when both sha3-asm are used as a dependency. Previously the symbols would conflict, for example by running:

RUSTC_LOG=rustc_codegen_ssa::back::link=info RUSTFLAGS="-C link-arg=-Wl,-warn_duplicate_libraries,-why_load,-all_load" cargo build --features asm-keccak

on a repo with both alloy-primitives with the keccak feature enabled, and an openssl dependency. Previously we would get symbol conflicts:

          duplicate symbol '_SHA3_absorb_cext' in:
              /Users/dan/projects/test-repro-keccak/target/debug/deps/libsha3_asm-62b37d0448a71d41.rlib[4](99b77fa459c7b68d-keccak1600-armv8.o)
              /Users/dan/projects/test-repro-keccak/target/debug/deps/libopenssl_sys-ce87998bbf8dc503.rlib[716](libcrypto-lib-keccak1600-armv8.o)
          duplicate symbol '_SHA3_squeeze_cext' in:
              /Users/dan/projects/test-repro-keccak/target/debug/deps/libsha3_asm-62b37d0448a71d41.rlib[4](99b77fa459c7b68d-keccak1600-armv8.o)
              /Users/dan/projects/test-repro-keccak/target/debug/deps/libopenssl_sys-ce87998bbf8dc503.rlib[716](libcrypto-lib-keccak1600-armv8.o)
          duplicate symbol '_SHA3_squeeze' in:
              /Users/dan/projects/test-repro-keccak/target/debug/deps/libsha3_asm-62b37d0448a71d41.rlib[4](99b77fa459c7b68d-keccak1600-armv8.o)
              /Users/dan/projects/test-repro-keccak/target/debug/deps/libopenssl_sys-ce87998bbf8dc503.rlib[716](libcrypto-lib-keccak1600-armv8.o)
          duplicate symbol '_SHA3_absorb' in:
              /Users/dan/projects/test-repro-keccak/target/debug/deps/libsha3_asm-62b37d0448a71d41.rlib[4](99b77fa459c7b68d-keccak1600-armv8.o)
              /Users/dan/projects/test-repro-keccak/target/debug/deps/libopenssl_sys-ce87998bbf8dc503.rlib[716](libcrypto-lib-keccak1600-armv8.o)
          ld: 4 duplicate symbols
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

With this, the previous command passes, see the renamed symbols here:

dan@Dans-MacBook-Pro-4 ~/p/keccak-asm (dan/rename-functions)> nm --debug-syms target/debug/build/sha3-asm-8f6b07d072c05e01/out/libkeccak.a

dd311508d4385923-keccak1600-armv8.o:
0000000000000340 t KeccakF1600
00000000000006e0 t KeccakF1600_ce
0000000000000800 t KeccakF1600_cext
0000000000000100 t KeccakF1600_int
0000000000000420 T _KECCAK_ASM_SHA3_absorb
00000000000008c0 T _KECCAK_ASM_SHA3_absorb_cext
0000000000000600 T _KECCAK_ASM_SHA3_squeeze
0000000000000a20 T _KECCAK_ASM_SHA3_squeeze_cext
0000000000000040 t iotas
0000000000000000 t ltmp0
0000000000000d64 s ltmp1

on non-darwin, we have to add macros for no leading underscores:

ubuntu@reth3:~/keccak-asm dan/rename-functions $ nm --debug-syms target/debug/build/sha3-asm-1fbd5b7ac64af10f/out/libkeccak.a

fd027825897661df-keccak1600-x86_64.o:
0000000000000000 N .debug_abbrev
0000000000000000 N .debug_info
0000000000000000 N .debug_line
0000000000000000 N .debug_str
0000000000000000 t .text
0000000000000380 T KECCAK_ASM_SHA3_absorb
0000000000000460 T KECCAK_ASM_SHA3_squeeze
00000000000002e0 T KeccakF1600
0000000000000000 t __KeccakF1600
0000000000000540 t iotas

Closes #9

@Rjected Rjected force-pushed the dan/rename-functions branch 16 times, most recently from 5e7e090 to 934aa1f Compare September 10, 2024 21:35
@Rjected Rjected force-pushed the dan/rename-functions branch from 934aa1f to 7fefdd4 Compare September 10, 2024 21:35
Copy link
Owner

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

🫡

@DaniPopes DaniPopes merged commit d9aa89b into DaniPopes:master Sep 10, 2024
21 checks passed
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.

Symbol conflicts with vendored openssl can cause invalid outputs
2 participants