Skip to content

Build a shared library for find_library link tests#15613

Open
thesamesam wants to merge 1 commit intomesonbuild:masterfrom
thesamesam:link-test-lib
Open

Build a shared library for find_library link tests#15613
thesamesam wants to merge 1 commit intomesonbuild:masterfrom
thesamesam:link-test-lib

Conversation

@thesamesam
Copy link
Member

In 4f43a40 I claimed that we were building a shared library for the new find_library link test, but I changed my mind while working on it [0] and went for a cute trick instead:

I should say as a correction to the commit message:

We can workaround that by building a shared library as a test rather than an executable,
We're not doing that, I thought we were going to have to, and I had it to begin with, but in the end, we have a nicer solution where we just pass the right flags.

In the end, the cute trick didn't work (#15601) for static libraries where -Wl,--allow-shlib-undefined doesn't help. Now, we could try -Wl-z,defs, but we want something portable to all linkers. Relying on the ELF behaviour of shared libraries seems best here, so do that.

So, build a shared library as I originally promised to do instead, so undefined references are tolerated.

Only do this if get_std_shared_lib_link_args gives us some non-empty argument because some platforms only support static linking.

We may still want to add a toggle for people to override this for a toolchain, possibly for non-ELF targets where I'm not sure the shared library behaviour is always the same.

[0] #15134 (comment)

Fixes: #15601

@thesamesam thesamesam requested a review from dcbaker as a code owner March 11, 2026 06:05
@bonzini bonzini added this to the 1.10.2 milestone Mar 11, 2026
@bonzini bonzini added regression dynamic linkers Dynamic linkers (ld, link, lld-link, etc) labels Mar 11, 2026
@thesamesam thesamesam requested a review from jpakkane as a code owner March 11, 2026 08:38
@thesamesam thesamesam force-pushed the link-test-lib branch 2 times, most recently from 7b6aa4f to 44d9722 Compare March 11, 2026 09:28
@thesamesam thesamesam marked this pull request as draft March 11, 2026 10:10
@thesamesam thesamesam force-pushed the link-test-lib branch 2 times, most recently from aeae58f to 287aff9 Compare March 11, 2026 11:55
In 4f43a40 I claimed that we were
building a shared library for the new find_library link test, but
I changed my mind while working on it [0] and went for a cute trick
instead:
> I should say as a correction to the commit message:
>> We can workaround that by building a shared library as a test rather than an executable,
> We're not doing that, I thought we were going to have to, and I had it to begin with, but in the end, we have a nicer solution where we just pass the right flags.

In the end, the cute trick didn't work (mesonbuild#15601) for static libraries
where -Wl,--allow-shlib-undefined doesn't help. Now, we could try
-Wl-z,defs, but we want something portable to all linkers. Relying on
the ELF behaviour of shared libraries seems best here, so do that.

So, build a shared library as I originally promised to do instead, so
undefined references are tolerated. Only do this if get_std_shared_lib_link_args
gives us some non-empty argument because some platforms only support static linking,
and don't do this when `static` is passed to `find_library`.

We may still want to add a toggle for people to override this for a toolchain,
possibly for non-ELF targets where I'm not sure the shared library behaviour
is always the same.

[0] mesonbuild#15134 (comment)

Fixes: mesonbuild#15601
Fixes: 4f43a40
Signed-off-by: Sam James <sam@gentoo.org>
@thesamesam thesamesam marked this pull request as ready for review March 13, 2026 15:04
@nirbheek nirbheek modified the milestones: 1.10.2, 1.11 Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dynamic linkers Dynamic linkers (ld, link, lld-link, etc) regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

find_library linkable check is too strict for RTEMS

3 participants