I noticed that gcc/config/sol2.h uses USE_GNU_LD as a guard in one
place only.  This is a cross of USE_GLD and HAVE_GNU_LD which doesn't
exist so the gld variant is never used.

This went unnoticed since the wrong versions of LD_WHOLE_ARCHIVE_OPTION
and LD_NO_WHOLE_ARCHIVE_OPTION are only ever used in LIBASAN_EARLY_SPEC
and only effective when -static-libasan is used.  gld would only warn
about the unsupported -z options here.

The issue wasn't noticed before since the only testcase using
-static-libasan isn't run on Solaris, which this patch also corrects.

Bootstrapped without regressions on i386-pc-solaris2.11 and
sparc-sun-solaris2.11 (both as/ld and gas/gld).

Committed to trunk.


It's highly unfortunate that there are two different macros to
distinguish between gld and non-gld (USE_GLD vs. HAVE_GNU_LD).  Since
the former is almost exclusively in Solaris-specific code, I'll switch
over to the HAVE_GNU_* form in a followup.

        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2025-11-18  Rainer Orth  <[email protected]>

        gcc:
        * config/sol2.h: Check USE_GLD instead of USE_GNU_LD.

        gcc/testsuite:
        * c-c++-common/asan/pr59063-2.c: Enable on Solaris.

# HG changeset patch
# Parent  a2df109e1601ee37035c616341e94dd89c83da79
solaris: Use USE_GLD in sol2.h

diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -229,7 +229,7 @@ along with GCC; see the file COPYING3.  
    in that case, and for executable link with --{,no-}whole-archive around
    it to force everything into the executable.  */
 
-#ifndef USE_GNU_LD
+#ifndef USE_GLD
 #define LD_WHOLE_ARCHIVE_OPTION "-z allextract"
 #define LD_NO_WHOLE_ARCHIVE_OPTION "-z defaultextract"
 #else
diff --git a/gcc/testsuite/c-c++-common/asan/pr59063-2.c b/gcc/testsuite/c-c++-common/asan/pr59063-2.c
--- a/gcc/testsuite/c-c++-common/asan/pr59063-2.c
+++ b/gcc/testsuite/c-c++-common/asan/pr59063-2.c
@@ -1,4 +1,4 @@
-/* { dg-do run { target { *-*-linux* *-*-freebsd* } } } */
+/* { dg-do run { target { *-*-linux* *-*-freebsd* *-*-solaris2* } } } */
 /* { dg-options "-static-libasan" } */
 
 #include <time.h>

Reply via email to