-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
backends: Use raw_link_args to check for the need of RPATH #4324
base: master
Are you sure you want to change the base?
backends: Use raw_link_args to check for the need of RPATH #4324
Conversation
Ping ... It is a one-line patch which fixes a lot of build problems, at least in JHBuild environments. What can I do to get it reviewed sooner? It seems to me that patches related to library paths usually takes a few weeks before getting the first review. I know it is too late to provide a regression fix for meson 0.47, and I am often slow on providing patches for issues which take hours, or even days, to debug. But I still hope we can get it merged soon so it is less likely for us to have to carry meson patches in FreeBSD ports and FreeBSD CI machines for the next meson release. |
I am not sure if this fix is actually correct. If we're linking to a library with an absolute path, how does setting the RPATH to that location break things? What does it break and how? |
I described the problem in #4270. The reason that it becomes a problem is that meson 0.47 and later versions convert -L -l arguments returned by pkg-config to absolute paths, so absolute paths can come from any .pc files. If we have |
Hum, so perhaps a better fix is to set the order of the |
I am not sure what is the most correct or expected way for users to specify library path order in meson. It doesn't seem to be documented so I always assume if autotools can work in an environment, meson should work in it, too. This means in order to get things to build and run in a two-or-more-prefix setup, these environment variables should be set in correct orders:
In my test environment, they are all handled by JHBuild. Since we already have
Yes if we specify all libraries with -L and -l arguments like what we did in the GNOME module. No if we have converted -L and -l to absolute paths because we also have to consider what these absolute paths originally represent. Even if we treat absolute paths like -L -l pairs and put -L parts into RPATH, it will still require more work to make it really work. For example, this is what meson with the current patch applied generates for atk:
My If we simply follow the order of -L and absolute path arguments here, it will become |
This is where a lot of people disagree. The argument is that you should not need to specify Also on macOS,
Note that those are not read while resolving pkg-config libraries because the pkg-config file is supposed to be the canonical source of information for where to find a library.
This is easy to fix: just ensure that paths pointing to the builddir are specified first. |
I don't object to the idea of adding more RPATH as long as it works properly. If we add paths which can be easily handled by
Do you mean the 'binary should run without LD_LIBRARY_PATH' case here?
Yes, -L flags in LDFLAGS are only used to find
Yes, it should be easily resolved by tracking where these flags come from like the GNOME module. |
068f0b3
to
501ed5f
Compare
501ed5f
to
1f433fc
Compare
1f433fc
to
db1892b
Compare
@nirbheek What should I do in order to move forward on this issue? Add more |
b24c7fa
to
d8ded78
Compare
@jpakkane @nirbheek Ping! Please tell me what should I do here. Adding unnecessary Since the pull request is now opened for one year and it is required for JHBuild to work properly, I am going to submit this patch for inclusion in JHBuild. It is annoying to have to remember to apply patches every time Meson is updated. |
Meson 0.47 changes the way to handle external dependencies on shared libraries significantly. Instead of just putting arguments provided by pkg-config on the linker command line, meson tries to convert -L and -l arguments into absolute paths to .so files by itself. This should make library handling more reliable because an absolute path is less likely to go wrong than an ordered list of search paths. However, due to the big change, a few regressions is still introduced, causing modules to fail to build in a JHBuild environment from time to time. Ideally regressions should be fixed in a few weeks and made available in subsequent releases. Unfortunately, I can't get my patches merged upstream in one year, and I have to remember to patch meson manually every time JHBuild updates meson. This is annoying because there are always modules failing to build because of these known bugs if I forget to patch it. Therefore, I think it is time to submit these patches to JHBuild, so it can be applied automatically. These patches have been added to FreeBSD ports since Meson 0.48. The CI runner currently used to test GLib on FreeBSD also uses it. Given that they has been used for one year without issues, it should be safe to use them to JHBuild as well. mesonbuild/meson#4270 mesonbuild/meson#4324 mesonbuild/meson#4271 mesonbuild/meson#4325
Meson 0.47 changes the way to handle external dependencies on shared libraries significantly. Instead of just putting arguments provided by pkg-config on the linker command line, meson tries to convert -L and -l arguments into absolute paths to .so files by itself. This should make library handling more reliable because an absolute path is less likely to go wrong than an ordered list of search paths. However, due to the big change, a few regressions is still introduced, causing modules to fail to build in a JHBuild environment from time to time. Ideally regressions should be fixed in a few weeks and made available in subsequent releases. Unfortunately, I can't get my patches merged upstream in one year, and I have to remember to patch meson manually every time JHBuild updates meson. This is annoying because there are always modules failing to build because of these known bugs if I forget to patch it. Therefore, I think it is time to submit these patches to JHBuild, so it can be applied automatically. The above patches have been added to FreeBSD ports since Meson 0.48. The CI runner currently used to test GLib on FreeBSD also uses it. Given that they has been used for one year without issues, it should be safe to use them to JHBuild as well. mesonbuild/meson#4270 mesonbuild/meson#4324 mesonbuild/meson#4271 mesonbuild/meson#4325 Meson 0.52 introduces a new library path regression. It now tries to add -Wl,-rpath-link when pkg-config --static returns more -L arguments than the default pkg-config call. The intention is to tell GNU ld.bfd where it can find dependencies of shared libraries, but the implementation does it in a wrong order and creates more undefined reference errors than it fixes in JHBuild environments. Since JHBuild always does native builds and LD_LIBRARY_PATH is set, -Wl,-rpath-link arguments pointing to installation prefixes are unnecessary in JHBuild environments. Therefore, it is safe to work around the issue by reverting the commit introducing the feature temporarily. mesonbuild/meson#5647 mesonbuild/meson#6027 mesonbuild/meson#6031 Meson 0.52 also changes the way to handle static libraries. It is known to break builds for dconf and gnome-builder. Unfortunately, these two projects don't fix them in a week and we are going to update meson without fixing them first. We backport a patch to remove duplicates from the linker command line to resolve 'argument list too long' error when building gnome-builder. This doesn't fix the build failure, but it should make it easier to debug the link_whole issue. mesonbuild/meson#5936 mesonbuild/meson#6030 https://gitlab.gnome.org/GNOME/dconf/issues/59 https://gitlab.gnome.org/GNOME/gnome-builder/issues/1057
Meson 0.47 changes the way to handle external dependencies on shared libraries significantly. Instead of just putting arguments provided by pkg-config on the linker command line, meson tries to convert -L and -l arguments into absolute paths to .so files by itself. This should make library handling more reliable because an absolute path is less likely to go wrong than an ordered list of search paths. However, due to the big change, a few regressions is still introduced, causing modules to fail to build in a JHBuild environment from time to time. Ideally regressions should be fixed in a few weeks and made available in subsequent releases. Unfortunately, I can't get my patches merged upstream in one year, and I have to remember to patch meson manually every time JHBuild updates meson. This is annoying because there are always modules failing to build because of these known bugs if I forget to patch it. Therefore, I think it is time to submit these patches to JHBuild, so it can be applied automatically. The above patches have been added to FreeBSD ports since Meson 0.48. The CI runner currently used to test GLib on FreeBSD also uses it. Given that they has been used for one year without issues, it should be safe to use them to JHBuild as well. mesonbuild/meson#4270 mesonbuild/meson#4324 mesonbuild/meson#4271 mesonbuild/meson#4325 Meson 0.52 introduces a new library path regression. It now tries to add -Wl,-rpath-link when pkg-config --static returns more -L arguments than the default pkg-config call. The intention is to tell GNU ld.bfd where it can find dependencies of shared libraries, but the implementation does it in a wrong order and creates more undefined reference errors than it fixes in JHBuild environments. Since JHBuild always does native builds and LD_LIBRARY_PATH is set, -Wl,-rpath-link arguments pointing to installation prefixes are unnecessary in JHBuild environments. Therefore, it is safe to work around the issue by reverting the commit introducing the feature temporarily. mesonbuild/meson#5647 mesonbuild/meson#6027 mesonbuild/meson#6031 Meson 0.52 also changes the way to handle static libraries. It is known to break builds for dconf and gnome-builder. Unfortunately, these two projects don't fix them in a week and we are going to update meson without fixing them first. We backport a patch to remove duplicates from the linker command line to resolve 'argument list too long' error when building gnome-builder. This doesn't fix the build failure, but it should make it easier to debug the link_whole issue. mesonbuild/meson#5936 mesonbuild/meson#6030 https://gitlab.gnome.org/GNOME/dconf/issues/59 https://gitlab.gnome.org/GNOME/gnome-builder/issues/1057
d8ded78
to
69e66ee
Compare
Rebased on the master branch. Let's hope someone is willing to accept it or provide a different fix. |
I don't know enough about the backend and even less about the magic of RPATHs to comment on whether this is correct or not. But seeing that five pings were ignored, I would suggest asking on the #mesonbuild IRC to get this either rereviewed, merged or closed. |
Did #7103 address any of these concerns? |
69e66ee
to
4467663
Compare
4377f33
to
7aed084
Compare
706efdf
to
dbc06d6
Compare
dbc06d6
to
b88e59d
Compare
Codecov Report
@@ Coverage Diff @@
## master #4324 +/- ##
==========================================
- Coverage 66.73% 63.54% -3.19%
==========================================
Files 378 189 -189
Lines 84597 42236 -42361
Branches 17501 8738 -8763
==========================================
- Hits 56455 26840 -29615
+ Misses 23352 13043 -10309
+ Partials 4790 2353 -2437
Continue to review full report at Codecov.
|
b88e59d
to
aed03b9
Compare
Function rpaths_for_bundled_shared_libraries assumes it needs RPATH when linking arguments of an external dependency has exactly one argument and the only argument is an absolute path to a library file. This was mostly fine because almost all .pc files use a -L -l pair instead of the full path of the library, which means pkg-config dependencies almost always have at least two arguments. However, there are patches landed in the meson 0.47 cycle which convert -L -l pair returned by pkg-config to the absolute path of library. If the output of pkg-config includes exactly one -L argument and one -l argument, it will be converted to exactly one absolute path by meson and rpaths_for_bundled_shared_libraries will assume it needs RPATH. Since meson passes both -rpath and -rpath-link to the linker and -rpath-link has precedence over LD_LIBRARY_PATH, it changes the search order of dependent libraries in an unexpected way and it causes a lot of linking troubles in JHBuild environments on FreeBSD. To make the method behave like the old way of using -L -l pairs and avoid library path order problems, we use raw_link_args instead of link_args here. raw_link_args stores the unmodified output of pkg-config and it is much less likely to accidentally match the rule currently used by the method. Works around mesonbuild#4270.
aed03b9
to
c59e5d1
Compare
Rebased to the latest commit and ping again. |
Function rpaths_for_bundled_shared_libraries assumes it needs RPATH when
linking arguments of an external dependency has exactly one argument and
the only argument is an absolute path to a library file. This was mostly
fine because almost all .pc files use a -L -l pair instead of the full
path of the library, which means pkg-config dependencies almost always
have at least two arguments. However, there are patches landed in the
meson 0.47 cycle which convert -L -l pair returned by pkg-config to the
absolute path of library. If the output of pkg-config includes exactly
one -L argument and one -l argument, it will be converted to exactly one
absolute path by meson and rpaths_for_bundled_shared_libraries will
assume it needs RPATH. Since meson passes both -rpath and -rpath-link to
the linker and -rpath-link has precedence over LD_LIBRARY_PATH, it
changes the search order of dependent libraries in an unexpected way and
it causes a lot of linking troubles in JHBuild environments on FreeBSD.
To make the method behave like the old way of using -L -l pairs and
avoid library path order problems, we use raw_link_args instead of
link_args here. raw_link_args stores the unmodified output of pkg-config
and it is much less likely to accidentally match the rule currently used
by the method.
Works around #4270.