Skip to content

cmake: Drop Libtool's option - #243

Merged
hebasto merged 1 commit into
cmake-stagingfrom
240627-cmake-GK
Jun 29, 2024
Merged

hebasto merged 1 commit into
cmake-stagingfrom
240627-cmake-GK

Conversation

@hebasto

@hebasto hebasto commented Jun 27, 2024

Copy link
Copy Markdown
Owner

The -no-undefined is not a linker flag, rather a Libtool flag, which we do not care about.

The `-no-undefined` is not a linker flag, rather a Libtool flag, which
we do not care about.
@hebasto

hebasto commented Jun 27, 2024

Copy link
Copy Markdown
Owner Author

Thanks to @m3dwards who reported this bug offline.

Friendly ping @TheCharlatan :)

@hebasto hebasto added the bug Something isn't working label Jun 27, 2024
@hebasto hebasto added this to the Ready for master milestone Jun 27, 2024
@theuni

theuni commented Jun 27, 2024

Copy link
Copy Markdown

Mmm, we still want this behavior for shared libs though.

A quick google says we want: string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--no-undefined")

Or perhaps we could/should do it per-target.

@hebasto

hebasto commented Jun 27, 2024

Copy link
Copy Markdown
Owner Author

Mmm, we still want this behavior for shared libs though.

A quick google says we want: string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--no-undefined")

Or perhaps we could/should do it per-target.

I was thinking something very similar while working on this PR.

Indeed, it might seem that Libtool's -no-undefined option is converted to the linker's -Wl,--no-undefined. However, that is not the case on the master branch. So I wonder, do we want to change behaviour at this point by adding a new linker option?

@theuni

theuni commented Jun 27, 2024

Copy link
Copy Markdown

Hmm, I'm seeing the same. Not sure why. It definitely worked at some point in the past.

Yes, I think we should be using the flag when possible. I'll investigate why libtool isn't adding it on master.

@hebasto

hebasto commented Jun 28, 2024

Copy link
Copy Markdown
Owner Author

Indeed, it might seem that Libtool's -no-undefined option is converted to the linker's -Wl,--no-undefined. However, that is not the case on the master branch.

Same here: bitcoin-core/secp256k1#1556.

@real-or-random

real-or-random commented Jun 28, 2024 •

Copy link
Copy Markdown

Indeed, it might seem that Libtool's -no-undefined option is converted to the linker's -Wl,--no-undefined. However, that is not the case on the master branch.

I checked the libtool and AFAIU -no-undefined has always been a no-op on Linux with GCC. I think -no-undefined was introduced in libtool to enable building shared libraries on some platforms where you need to pass a corresponding parameter to the linker (e.g., --Wl,no-undefined on Windows/GCC). libtool can't pass the linker parameter always because this would, e.g., exclude building static libraries with undefined symbols. That's why they needed this -no-undefined hack to let the developer declare explicitly that there won't be any undefined symbols. So the primary goal of -no-undefined was to make shared library builds work on these platforms, and not to err on the side of caution and make the linker verify that there are no undefined symbols.

Still, people have asked for this on Linux, but it was apparently never implemented. Here's some (Bitcoin-)prehistoric conversation about this: https://gcc.gnu.org/legacy-ml/gcc-patches/2001-02/msg00305.html. See in particular this one: https://gcc.gnu.org/legacy-ml/gcc-patches/2001-02/msg00376.html

I do think it is a reasonably important issue, because some platforms
require no undefined symbols when building shared libraries, but lots
of development is done on GNU/Linux, and so if `--no-undefined' doesn't
work on GNU/Linux, then shared libraries on AIX/Windows/Beos will
continually be broken by developers on GNU/Linux,

Agreed! That's precisely our issue here...


So I wonder, do we want to change behaviour at this point by adding a new linker option?

I think it's desirable to have the flag. The referenced thread mentions some issues when not linking to ld-linux explicitly, but I can't find recent mentions of this (this is >23 years ago). Gentoo also recommends it: https://wiki.gentoo.org/wiki/Project:Quality_Assurance/-Wl,-z,defs_and_-Wl,--no-allow-shlib-undefined If it really breaks something, we could still revert.

edit: But I don't know what the general strategy of the CMake migration is. If the plan is to switch to CMake first while trying to touch the actual build as little as possible, then the change should be postponed.

@hebasto

hebasto commented Jun 28, 2024

Copy link
Copy Markdown
Owner Author

@theuni

Yes, I think we should be using the flag when possible.

I do agree with you. But I cannot see any compelling reasons to mix it with the CMake migration. Shouldn't a new linker option be introduced in the master branch?

@theuni

theuni commented Jun 28, 2024

Copy link
Copy Markdown

Thanks for the deep-dive @real-or-random!

libtool can't pass the linker parameter always because this would, e.g., exclude building static libraries with undefined symbols.

The linker/ldflags aren't used for static libs, rather ar/arflags :)

Still, I'm sure this has been used/needed at some point in the past. Is it possible it's wired up for gcc+mingw?

@hebasto

hebasto commented Jun 28, 2024

Copy link
Copy Markdown
Owner Author

Still, I'm sure this has been used/needed at some point in the past. Is it possible it's wired up for gcc+mingw?

The Libtool's -no-undefined option is a Libtool's requirement to build a DLL. However, the linker options are not affected.

@theuni

theuni commented Jun 28, 2024

Copy link
Copy Markdown

Still, I'm sure this has been used/needed at some point in the past. Is it possible it's wired up for gcc+mingw?

The Libtool's -no-undefined option is a Libtool's requirement to build a DLL. However, the linker options are not affected.

Ok, maybe that's it then. I guess I just assumed it did the obvious thing (adding the linker flag). But that would explain why I remembered it doing "something".

@theuni theuni left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

utACK 414bdee.

I think we want this behavior, but as it's not present in master, we should start there.

@real-or-random

Copy link
Copy Markdown

I think we want this behavior, but as it's not present in master, we should start there.

What about creating a milestone here for things you want to do after CMake has been merged into master?

@fanquake

Copy link
Copy Markdown

Unless it's something drastic, I'd rather not delay things, where possible, until after CMake, because that's just going to widen the gap in functionality between the builds. If it's just the case of adding a new linker flag to the build, we can just do that now.

@m3dwards

Copy link
Copy Markdown

ACK 414bdee

Without this PR I would get:

ld: unknown options: -no-undefined
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[3]: *** [src/kernel/CMakeFiles/bitcoinkernel.dir/build.make:1241: src/kernel/libbitcoinkernel.dylib] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:1867: src/kernel/CMakeFiles/bitcoinkernel.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:1651: src/CMakeFiles/bitcoin-chainstate.dir/rule] Error 2
gmake: *** [Makefile:803: bitcoin-chainstate] Error 2

@hebasto

hebasto commented Jun 28, 2024

Copy link
Copy Markdown
Owner Author

Unless it's something drastic, I'd rather not delay things, where possible, until after CMake, because that's just going to widen the gap in functionality between the builds.

There is no gap in functionality between the builds with this PR, unless I missed something.

If it's just the case of adding a new linker flag to the build, we can just do that now.

Yes, we can. FWIW, I opened a related PR in the secp256k1 repo.

@theuni theuni left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

utACK 414bdee

@hebasto
hebasto merged commit e05358e into cmake-staging Jun 29, 2024
hebasto pushed a commit that referenced this pull request Jul 7, 2026
….makePool` method

6b0a907 Squashed 'src/ipc/libmultiprocess/' changes from 3edbe8f..16bf05d (Ryan Ofsky)

Pull request description:

  The changes can be verified by running `test/lint/git-subtree-check.sh src/ipc/libmultiprocess` as described in [developer notes](https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#subtrees) and [lint instructions](https://github.com/bitcoin/bitcoin/tree/master/test/lint#git-subtree-checksh).

  Changes since last subtree update (bitcoin#34977):

  - Adds `makePool` method on `ThreadMap` to support thread pool routing, allowing requests without a specific client thread to be dispatched to a pool using a shortest-queue strategy ([#283](bitcoin-core/libmultiprocess#283)).
  - Adds `std::unordered_set` support, a `BuildList` helper, and a `ReadList` helper to reduce duplication in list build and read handlers ([#277](bitcoin-core/libmultiprocess#277), [#285](bitcoin-core/libmultiprocess#285)).
  - Adds support for translating C++ `std::optional<T>` struct fields to pairs of `T` + `hasT :Bool` Cap'n Proto struct fields, allowing unset optional primitive fields to be represented ([#243](bitcoin-core/libmultiprocess#243)).
  - Produces more readable log output for Proxy object lifecycle events and IPC server-side failures ([#218](bitcoin-core/libmultiprocess#218)).
  - Handles exceptions thrown by `destroy` methods by logging instead of aborting ([#273](bitcoin-core/libmultiprocess#273)). This can prevent server crashes when non-libmultiprocess clients disconnect without destroying objects, in the case where a server object owns client objects and the server destructor tries to call the disconnected client to free them ([#219](bitcoin-core/libmultiprocess#219)).
  - Handles unexpected exceptions thrown by callbacks (that should never happen) by logging errors instead of deadlocking ([#260](bitcoin-core/libmultiprocess#260)).
  - Fixes a rare mptest hang on musl builds caused by a lost wakeup bug in `Waiter` ([#295](bitcoin-core/libmultiprocess#295)).
  - Fixes a race condition in a log print detected by TSan ([#286](bitcoin-core/libmultiprocess#286)).
  - Build improvements: makes `target_capnp_sources` work correctly when libmultiprocess is used as a CMake subproject ([#289](bitcoin-core/libmultiprocess#289)), adds `mp_headers` target for better lint tool support ([#291](bitcoin-core/libmultiprocess#291)), and fixes compatibility with recent Nix and CMake 4.0 ([#238](bitcoin-core/libmultiprocess#238)).
  - Test, CI, documentation, and minor code improvements: design document corrections ([#278](bitcoin-core/libmultiprocess#278)), field constant comments ([#279](bitcoin-core/libmultiprocess#279)), clang-tidy fix ([#292](bitcoin-core/libmultiprocess#292)), new smoke test for double-precision float values ([#294](bitcoin-core/libmultiprocess#294)), new test for recursive async IPC calls ([#301](bitcoin-core/libmultiprocess#301)), removal of libevent from Core CI builds ([#299](bitcoin-core/libmultiprocess#299)), and rename of `EventLoop::m_num_clients` to `m_num_refs` ([#302](bitcoin-core/libmultiprocess#302)).

ACKs for top commit:
  fanquake:
    ACK 02afa66
  hebasto:
    ACK 02afa66.

Tree-SHA512: ef81a951c971f328a0a98436030467eeea30925eb6016eafd9bc7a25726c87628a852bbb1d84b88bce340aeea2bed25c65bc55db1168ebcb850628cd18808883
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants