ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: [Wireshark-dev] Why are we linking with --as-needed?

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Thu, 21 Jan 2016 19:17:43 -0800
The GNU linker documentation says of the --as-needed flag

--as-needed
--no-as-needed
	This option affects ELF DT_NEEDED tags for dynamic libraries mentioned on the command line after the --as-needed option. Normally the linker will add a DT_NEEDED tag for each dynamic library mentioned on the command line, regardless of whether the library is actually needed or not.  --as-needed causes a DT_NEEDED tag to only be emitted for a library that at that point in the link satisfies a non-weak undefined symbol reference from a regular object file or, if the library is not found in the DT_NEEDED lists of other needed libraries, a non-weak undefined symbol reference from another needed dynamic library. Object files or libraries appearing on the command line after the library in question do not affect whether the library is seen as needed. This is similar to the rules for extraction of object files from archives.  --no-as-needed restores the default behaviour.

--as-needed was added in this change:

	commit b6cffe405019da8259413cfcb829339712a098a7
	Author: Jörg Mayer <jmayer@xxxxxxxxx>
	Date:   Fri Aug 7 18:49:24 2009 +0000

	    - Add an AC macro to test linker flags.
	    - Test whether the linker supports --as-needed and if so,
	      adds it to LDFLAGS

About all I could find for a reason were bugs such as

	https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=1677

complaining that Wireshark didn't build with --as-needed.

So why is it useful that it be built - or, at least, buildable - with --as-needed?  (It's obviously not *necessary* as not all platform support that capability.)