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

Respect LIBS environment variable #10621

Open
matoro opened this issue Jul 21, 2022 · 6 comments
Open

Respect LIBS environment variable #10621

matoro opened this issue Jul 21, 2022 · 6 comments

Comments

@matoro
Copy link

matoro commented Jul 21, 2022

GNU autoconf uses the LIBS environment variable to specify additional libraries to link.. This variable is distinct from LDFLAGS. The latter is for flags that affect the behavior of the linker, while the former is for libraries to link. This means that LDFLAGS is free to be placed before the object files in the command line, while LIBS must be placed after the object files. The manual is very explicit about this in the description for LDFLAGS:

Don’t use this variable to pass library names (-l) to the linker; use LIBS instead.

There is a use-case for this. On some architectures, like riscv, i386, and 32-bit sparc and mips, the GCC __atomic intrinsics are implemented in software via the libatomic library. This means that packages using those intrinsics must link with with -latomic, but only on certain platforms. On such platforms, the user will often need to set LIBS="-latomic" to successfully link. This is easy to do with autotools-based projects, but meson does not know about this environment variable.

@eli-schwartz
Copy link
Member

Wasn't there some GCC discussion about adding --push-state --as-needed -latomic --pop-state to the builtin spec on those platforms? This seems like a considerably more robust approach.

@matoro
Copy link
Author

matoro commented Jul 21, 2022

Wasn't there some GCC discussion about adding --push-state --as-needed -latomic --pop-state to the builtin spec on those platforms? This seems like a considerably more robust approach.

Perhaps, and I can definitely look into this if you have a link. However this isn't necessarily only the use case - just the particular one that prompted this issue. A change to the gcc specs would take quite a long time before trickling down across the ecosystem. A meson patch would be much faster.

@eli-schwartz
Copy link
Member

Found some discussion:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358
but mostly riscvarchive/riscv-gcc#12

I'm referring to option 4. It apparently was originally implemented, but later limited to whenever -pthread was passed, leading to the confusing situation where programs that use both threads and atomics worked, but programs that use only atomics did not work.

Also you're suggesting Meson implement a feature request to enable option 5. ;)

@matoro
Copy link
Author

matoro commented Jul 21, 2022

Found some discussion:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358 but mostly riscv-collab/riscv-gcc#12

I'm referring to option 4. It apparently was originally implemented, but later limited to whenever -pthread was passed, leading to the confusing situation where programs that use both threads and atomics worked, but programs that use only atomics did not work.

Also you're suggesting Meson implement a feature request to enable option 5. ;)

Yes. Here's my justification:

  • autotools supports it. I think this is the biggest point in favor. I think cmake might support it with https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_STANDARD_LIBRARIES.html
  • adding at the build system layer makes the most sense, as it allows distros to work around it without requiring upstream involvement or support for each individual package (not saying there can't be, but that is a much higher hurdle to clear for large distro repos)
  • adding at the gcc level adds a gcc lower bound dependency to projects that wouldn't have one otherwise, and takes significantly longer to filter down to distros

@dcbaker
Copy link
Member

dcbaker commented Jul 21, 2022

We handle a atomics in mesa and it’s a pain. Regardless of what we do with LIBS I think a built in dependency for atomics might be in order

@thesamesam
Copy link
Collaborator

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

No branches or pull requests

4 participants