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

build: Use SECP256K1_STATICLIB macro instead of warning suppressions #1346

Closed
wants to merge 1 commit into from

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Jun 13, 2023

The changes from #1209 has been described as:

Fixed declarations of API variables for MSVC (__declspec(dllimport)). This fixes MSVC builds of programs which link against a libsecp256k1 DLL dynamically and use API variables (and not only API functions). Unfortunately, the MSVC linker now will emit warning LNK4217 when trying to link against libsecp256k1 statically. Pass /ignore:4217 to the linker to suppress this warning.

Apparently, this description is not complete. When building Bitcoin Core, the other warning is raised as well:

LINK : warning LNK4217: symbol 'secp256k1_context_static' defined in 'libsecp256k1.lib(secp256k1.obj)' is imported by 'libbitcoin_consensus.lib(pubkey.obj)' in function '"public: static bool __cdecl CPubKey::CheckLowS(class std::vector<unsigned char,class std::allocator<unsigned char> > const &)" (?CheckLowS@CPubKey@@SA_NAEBV?$vector@EV?$allocator@E@std@@@std@@@Z)' [C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\build_msvc\test_bitcoin\test_bitcoin.vcxproj]
LINK : warning LNK4286: symbol 'secp256k1_context_static' defined in 'libsecp256k1.lib(secp256k1.obj)' is imported by 'libbitcoin_common.lib(key.obj)' [C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\build_msvc\test_bitcoin\test_bitcoin.vcxproj]

This PR provides to the user of a static libsecp256k1 library an option to define the SECP256K1_STATICLIB macro instead of ignoring MSVC linker warnings LNK4217 and LNK4286.

@hebasto hebasto marked this pull request as draft June 13, 2023 12:47
This change allows the user to define the `SECP256K1_STATICLIB` macro
instead of ignoring MSVC linker warnings LNK4217 and LNK4286.
@hebasto hebasto marked this pull request as ready for review June 13, 2023 13:07
@real-or-random
Copy link
Contributor

Concept ACK

The macro is cheap, and if it helps Core get a cleaner build, then we should just add it. Many hours of researching and experimenting went into that piece of code, so I'll probably follow up with a PR that adds extensive comments.


Apparently, this description is not complete. When building Bitcoin Core, the other warning is raised as well:

LINK : warning LNK4217: symbol 'secp256k1_nonce_function_rfc6979' defined in 'libsecp256k1.lib(secp256k1.obj)' is imported by 'libbitcoin_common.lib(key.obj)' in function '"public: bool __cdecl CKey::Sign(class uint256 const &,class std::vector<unsigned char,class std::allocator<unsigned char> > &,bool,unsigned int)const " (?Sign@CKey@@QEBA_NAEBVuint256@@AEAV?$vector@EV?$allocator@E@std@@@std@@_NI@Z)' [C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\build_msvc\test_bitcoin\test_bitcoin.vcxproj]

Do you mean the LNK4286 is also raised? I see that one in the logs.

@hebasto
Copy link
Member Author

hebasto commented Jun 14, 2023

Do you mean the LNK4286 is also raised? I see that one in the logs.

Yes. I put the wrong line into the PR description. Updated.

@hebasto
Copy link
Member Author

hebasto commented Jun 23, 2023

When building Bitcoin Core, the other warning is raised as well:

LINK : warning LNK4217: symbol 'secp256k1_context_static' defined in 'libsecp256k1.lib(secp256k1.obj)' is imported by 'libbitcoin_consensus.lib(pubkey.obj)' in function '"public: static bool __cdecl CPubKey::CheckLowS(class std::vector<unsigned char,class std::allocator<unsigned char> > const &)" (?CheckLowS@CPubKey@@SA_NAEBV?$vector@EV?$allocator@E@std@@@std@@@Z)' [C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\build_msvc\test_bitcoin\test_bitcoin.vcxproj]
LINK : warning LNK4286: symbol 'secp256k1_context_static' defined in 'libsecp256k1.lib(secp256k1.obj)' is imported by 'libbitcoin_common.lib(key.obj)' [C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\build_msvc\test_bitcoin\test_bitcoin.vcxproj]

This PR provides to the user of a static libsecp256k1 library an option to define the SECP256K1_STATICLIB macro instead of ignoring MSVC linker warnings LNK4217 and LNK4286.

@sipsorcery Friendly ping :)

As a Windows connoisseur, what do you think?

@sipsorcery
Copy link

As a Windows user I'm used to just ignoring crap from the OS so I would have stopped at adding an option to ignore the warnings.

This PR is a step further and makes it even cleaner so looks good to me.

ACK 6177b8a.

@hebasto
Copy link
Member Author

hebasto commented Jun 28, 2023

Closing in favor of #1362.

@hebasto hebasto closed this Jun 28, 2023
real-or-random added a commit that referenced this pull request Jul 3, 2023
…s (attempt 3)

c6cd2b1 ci: Add task for static library on Windows + CMake (Hennadii Stepanov)
020bf69 build: Add extensive docs on visibility issues (Tim Ruffing)
0196e8a build: Introduce `SECP256k1_DLL_EXPORT` macro (Hennadii Stepanov)
9f1b190 refactor: Replace `SECP256K1_API_VAR` with `SECP256K1_API` (Hennadii Stepanov)
ae9db95 build: Introduce `SECP256K1_STATIC` macro for Windows users (Hennadii Stepanov)

Pull request description:

  Previous attempts:
  - #1346
  - #1362

  The result is as follows:
  1. Simple, concise and extensively documented code.
  2. Explicitly documented use cases with no ambiguities.
  3. No workarounds for linker warnings.
  4. Solves one item in #1235.

ACKs for top commit:
  real-or-random:
    utACK c6cd2b1

Tree-SHA512: d58694452d630aefbd047916033249891bc726b7475433aaaa7c3ea2a07ded8f185a598385b67c2ee3440ec5904ff9d9452c97b0961d84dcb2eb2cf46caa171e
@hebasto hebasto deleted the 230613-static branch February 13, 2024 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants