On Fri, 17 Jan 2025 at 15:32:22 +0000, Wookey wrote:
> Can you explain why this:
> -Wl,--push-flags,--as-needed,-latomic,--pop-flags
> is better than
> -as-needed,-latomic
> I thought --as-needed on its own is sufficicent to avoid dpkg-shlibdeps 
> warnings
> about unnecessary linking (because it only links the things that are needed), 
> so
> I don't understand the need for the psuh/pop sequence (I must admit that I 
> never
> knew that existed until your message recently).

Two things, depending which difference between your two command lines
you are thinking about:

1. -Wl,--as-needed normally sets global state for the entire linker
   invocation. If the package you're building is one that has a
   functional requirement to *not* use -Wl,--as-needed for other library
   dependencies, the push/pop guards ensure that the -Wl,--as-needed
   only affects how libatomic is linked, without having the side-effects
   of linking every other library dependency (not just libatomic!) in
   "as needed" mode.

   For example GLib explicitly pulls in libpthread, which is (or at least
   was in the past) functionally necessary: if that wasn't done,
   dlopen()ing modules that indirectly depend on libpthread would not
   be safe, because internal locks in glibc were already initialized
   in a non-thread-safe way before libpthread was in memory, and cannot
   (or at least could not in 2009) be re-initialized with the thread-safe
   equivalent after libpthread arrived. (Reference:
   https://mail.gnome.org/archives/gtk-devel-list/2009-November/msg00096.html)

2. -Wl is necessary to tell the compiler driver (gcc or clang)
   "it's OK that you don't understand this, just pass it through to the
   linker". --as-needed is a ld option, not a gcc option; but $LDFLAGS
   are passed to gcc, not ld.

    smcv

Reply via email to