Skip to content

Conversation

@thesamesam
Copy link
Member

@thesamesam thesamesam commented Oct 17, 2025

Always check if found libraries are linkable

We don't always check if a library is actually linkable because of concerns
that a library may not be standalone, so linking against it may still have
unresolved references. We can workaround that by building a shared library
as a test rather than an executable, and in fact we already do that in a
bunch of cases since bb5f2ca.

This comes up in particular with Fedora and dependency('atomic') because
on x86_64, they provide a libatomic.so linker script (so our file existence
check passes), but trying to use it later on will fail if the backing package
isn't installed.

The _test_all_naming unittest has been tweaked because we were using a
blank file rather than an actual shared library, which (as expected),
now fails.

I've also added a test for dependency('atomic') providing a result that
can actually be linked against. I've not made it check generally whether
dependency('atomic') finds something when we expect to (at least for now)
as it'll involve some CI whack-a-mole.

_get_file_from_list has not been deleted because the Ninja backend's
guess_library_absolute_path uses it. We might be able to change it to
also use a link test but I've left that alone.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=2352531
Bug: #14946
Closes: #10936

@thesamesam thesamesam marked this pull request as draft October 17, 2025 17:11
@thesamesam thesamesam force-pushed the sam-libatomic branch 2 times, most recently from 7fc99ba to c31a10f Compare October 17, 2025 19:52
@dcbaker
Copy link
Member

dcbaker commented Oct 17, 2025

This seems like the right approach to me.

In an Ubuntu Bionic container with Python 3.7.5:
```
$ python3 -c 'import tempfile; print(tempfile.mkdtemp(dir=""))'
tmpycdjfo6m
$ python3 -c 'import tempfile; print(tempfile.mkdtemp(dir=None))'
/tmp/tmpy6dlpv0r
```

Pass dir as None to get the behaviour we need - which is how newer Pythons
act, as otherwise we aren't running in the cwd for the compile test
that we expect.

This shows up as a failure in _test_all_naming when _find_library_real is
modified to use links().
We don't always check if a library is actually linkable because of concerns
that a library may not be standalone, so linking against it may still have
unresolved references. We can workaround that by building a shared library
as a test rather than an executable, and in fact we already do that in a
bunch of cases since bb5f2ca.

This comes up in particular with Fedora and dependency('atomic') because
on x86_64, they provide a libatomic.so linker script (so our file existence
check passes), but trying to use it later on will fail if the backing package
isn't installed.

_get_file_from_list has not been deleted because the Ninja backend's
guess_library_absolute_path uses it. We might be able to change it to
also use a link test but I've left that alone.

Test notes:
* The _test_all_naming unittest has been tweaked because we were using a
  blank file rather than an actual shared library, which (as expected),
  now fails.

* I've also added a test for dependency('atomic') providing a result that
  can actually be linked against. I've not made it check generally whether
  dependency('atomic') finds something when we expect to (at least for now)
  as it'll involve some CI whack-a-mole.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=2352531
Bug: mesonbuild#14946
Closes: mesonbuild#10936
@thesamesam thesamesam marked this pull request as ready for review October 17, 2025 21:13
@dcbaker
Copy link
Member

dcbaker commented Oct 21, 2025

@eli-schwartz, this looks right to me, and like it would fix a lot issues. I think you're more qualified to review this than I am though, so, do you want to have a look or just trust Sam and I?

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.

compiler.find_library() function considers unusable libraries to be found

2 participants