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

fixed duplicate symbol with another lib #4093

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ahaladok
Copy link
Contributor

@ahaladok ahaladok commented Nov 2, 2024

Description

This fix addresses the duplicate symbol issue related to the blake2b function, which occurred when linking both libTrezorCrypto and libQt6Core. The duplication involved symbols such as '_blake2b' and '_blake2b_init_param'.

duplicate symbol '_blake2b' in: /Users/andrei.haladok/Desktop/work_folder/Libraries/local/Qt-6.2.9/lib/libQt6Core_debug.a[x86_64][123](qcryptographichash.cpp.o) /Users/andrei.haladok/Desktop/work_folder/Libraries/local/lib/libTrezorCrypto.a[43](blake2b.c.o) duplicate symbol '_blake2b_init_param' in: /Users/andrei.haladok/Desktop/work_folder/Libraries/local/Qt-6.2.9/lib/libQt6Core_debug.a[x86_64][123](qcryptographichash.cpp.o) /Usersandrei.haladokDesktop/work_folder/Libraries/local/lib/libTrezorCrypto.a[43](blake2b.c.o) ld: 2 duplicate symbols clang++: error: linker command failed with exit code 1 (use -v to see invocation)

What was changed:

In the blake2b.h header file of the libTrezorCrypto library, a tc_ prefix was added to blake2b-related function names to avoid symbol conflicts:

  • blake2b_Init -> tc_blake2b_Init
  • blake2b_InitKey -> tc_blake2b_InitKey
  • blake2b_InitPersonal -> tc_blake2b_InitPersonal
  • blake2b_Update -> tc_blake2b_Update
  • blake2b_Final -> tc_blake2b_Final
  • blake2b -> tc_blake2b
  • blake2b_Personal -> tc_blake2b_Personal
  • blake2b_Key -> tc_blake2b_Key

These changes were applied throughout the code to ensure the functions align with the updated naming, thus preventing compilation conflicts.

Why this approach is better:

In my opinion, this change is a cleaner solution compared to using "dirty hacks" that might lead to undefined behavior, security vulnerabilities, or maintenance issues. Alternative workarounds, such as using the following linker flags and hacks, can often obscure the underlying problem and introduce other risks:

  • -unexported_symbols_list
  • -Xlinker -multiply_defined -Xlinker suppress
  • -allow_multiply_defined_symbols
  • -Wl,-dead_strip
  • -Wl,-force_load

With this fix, we can avoid manipulating symbols and hiding them at the linking stage, which ensures a more stable and maintainable codebase.

How to test

  1. Navigate to samples/cpp/CMakeLists.txt, which is a sample project configuration.
  2. Add libQt6Core_debug as a dependency in the CMake configuration to replicate the setup where libQt6Core and libTrezorCrypto are linked together.
  3. Build the project and check for any linker errors related to duplicate symbols.
  4. Ensure that the project compiles successfully without duplicate symbol errors, confirming that the tc_ prefixes in libTrezorCrypto resolve the conflict with libQt6Core.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Create pull request as draft initially, unless it's complete.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • If there is a related Issue, mention it in the description.

If you're adding a new blockchain

  • I have read the guidelines for adding a new blockchain.

Copy link
Collaborator

@satoshiotomakan satoshiotomakan left a comment

Choose a reason for hiding this comment

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

Hi @ahaladok, thank you for opening the PR
LGTM, let's wait for an approval from @Milerius

@@ -109,8 +109,8 @@ int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
}


/* Sequential blake2b initialization */
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to change the comment

@Ruyeduardo
Copy link

Ruyeduardo commented Nov 4, 2024 via email

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.

3 participants