https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109389
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Note Debian (and Ubuntu) has a patch to their GCC which does cause the default arguments to ld to include --as-needed . That is why you are seeing a difference between gcc and clang. Note if you build GCC from source, you would not have seen a difference here. Also note this is not a bug in GCC nor in debian's gcc; just you misunderstanding the how linking works too.