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

cmake: Add --no-undefined linker option #1559

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

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Jun 28, 2024

This PR adds the --no-undefined option to a linker, which supports it.

From the GNU ld docs:

--no-undefined

Report unresolved symbol references from regular object files. This is done even if the linker is creating a non-symbolic shared library.

Closes #1556.

Looking for Concept (N)ACKs. Once ACKed, I'll add the same functionality to the Autotools-based build system.

@theuni
Copy link
Contributor

theuni commented Jun 28, 2024

Concept ACK.

I think we might be after -Wl,--no-allow-shlib-undefined, though, and only for the shared lib as that's what we care about. --no-undefined is strictly stronger, I guess, and should also be satisfied for the binaries. So I suppose the sledgehammer approach here should be fine.

@hebasto
Copy link
Member Author

hebasto commented Jun 28, 2024

I think we might be after -Wl,--no-allow-shlib-undefined...

From my experience, it fails to catch an issue like one I demoed in #1556.

@real-or-random
Copy link
Contributor

I think we might be after -Wl,--no-allow-shlib-undefined, though, and only for the shared lib as that's what we care about. --no-undefined is strictly stronger, I guess, and should also be satisfied for the binaries. So I suppose the sledgehammer approach here should be fine.

If https://stackoverflow.com/a/2356407 is right, then --no-undefined covers objects created by the linker and --no-allow-shlib-undefined covers shared libraries consumed by the linker.

@real-or-random
Copy link
Contributor

Concept ACK

@hebasto
Copy link
Member Author

hebasto commented Jun 28, 2024

Looking for Concept (N)ACKs. Once ACKed, I'll add the same functionality to the Autotools-based build system.

Added a commit for the Autotools-based build system.

CMakeLists.txt Outdated Show resolved Hide resolved
@hebasto hebasto marked this pull request as draft June 28, 2024 18:16
Copy link
Contributor

@real-or-random real-or-random left a comment

Choose a reason for hiding this comment

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

I think we need to make add an exception to this if external default callbacks are enabled because the entire point of this option is that the user provides the callbacks at link time.

@hebasto
Copy link
Member Author

hebasto commented Jun 29, 2024

I think we need to make add an exception to this if external default callbacks are enabled because the entire point of this option is that the user provides the callbacks at link time.

Right. I did it in CMake, but forgot about it in Autotools. Fixed.

@hebasto hebasto marked this pull request as ready for review June 29, 2024 10:27
@hebasto hebasto marked this pull request as draft June 29, 2024 10:58
Comment on lines +12 to +15
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
string(APPEND " -Wl,-fatal_warnings")
else()
string(APPEND " -Wl,--fatal-warnings")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this depend on the linker and not on the OS?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it can be implemented in a simple way; see https://gitlab.kitware.com/cmake/cmake/-/issues/18209.

However, we can just check each variant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I think checking CMAKE_SYSTEM_NAME is good enough and pragmatic. GNU ld doesn't even support the creation of macOS binaries, and even clang's macOS linker ld64.lld uses -fatal_warnings...

But shouldn't we append -Wl,-fatal_warnings or -Wl,--fatal-warnings also for the autotools build?

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.

Is default -Wl,--no-undefined desired?
3 participants