https://gcc.gnu.org/g:5212086d0aa901ffa8e92c001e825767b8fd9f83
commit r16-6419-g5212086d0aa901ffa8e92c001e825767b8fd9f83 Author: Rainer Orth <[email protected]> Date: Sun Dec 28 11:32:37 2025 +0100 Support Solaris CTF generation The Solaris Compact C Type Format, CTF, was introduced back in Solaris 9. It is the precursor to current GNU CTF, meant primarily for tools like the low-level debugger mdb or DTrace that would like to avoid the overhead of full DWARF-2 debugging information. However, for a long time creation required separate steps to convert DWARF information (version 2 only) to CTF in the input objects and later merge this into the final objects. The tools to do so were available, but they were barely documented and their use restricted to the core OS because of this difficulty. There's recently been a massive effort to simplify this and allow for wider adoption. The native linker has been extended to take GNU CTF info in the input objects and convert that to Solaris CTF itself. At the same time, the massively enhanced tools and the format itself are fully documented. To make this even simpler to use, this patch introduces a new -gsctf option to hide the details from users. At compile time, it just passes -gctf to the compiler, and at link time it invokes ld with -z ctf. Bootstrapped without regressions on i386-pc-solaris2.11 and sparc-sun-solaris2.11. 2025-11-23 Rainer Orth <[email protected]> gcc: * configure.ac (gcc_cv_ld_ctf): New check. (gcc_cv_have_ctfmerge): Likewise. * configure: Regenerate. * config.in: Regenerate. * config/sol2.h (SCTF_CC1_SPEC): Define. (LINK_SCTF_SPEC): Define. (LINK_SPEC): Add LINK_SCTF_SPEC. * config/i386/sol2.h (CC1_SPEC): Add SCTF_CC1_SPEC. * config/sparc/sol2.h: Likewise. * config/sol2.opt (gsctf): Declare. * config/sol2.opt.urls: Regenerate. * doc/invoke.texi (Option Summary): Add -gsctf. (Solaris 2 Options): Document it. Diff: --- gcc/config.in | 6 ++++++ gcc/config/i386/sol2.h | 2 +- gcc/config/sol2.h | 18 +++++++++++++++++- gcc/config/sol2.opt | 4 ++++ gcc/config/sol2.opt.urls | 3 +++ gcc/config/sparc/sol2.h | 4 ++-- gcc/configure | 15 +++++++++++++++ gcc/configure.ac | 11 +++++++++++ gcc/doc/invoke.texi | 8 +++++++- 9 files changed, 66 insertions(+), 5 deletions(-) diff --git a/gcc/config.in b/gcc/config.in index f60704fbba4b..a424df5a1602 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -1797,6 +1797,12 @@ #endif +/* Define if your linker supports -z ctf. */ +#ifndef USED_FOR_TARGET +#undef HAVE_LD_CTF +#endif + + /* Define if your linker supports --demangle option. */ #ifndef USED_FOR_TARGET #undef HAVE_LD_DEMANGLE diff --git a/gcc/config/i386/sol2.h b/gcc/config/i386/sol2.h index e5942266d33a..294803497469 100644 --- a/gcc/config/i386/sol2.h +++ b/gcc/config/i386/sol2.h @@ -55,7 +55,7 @@ along with GCC; see the file COPYING3. If not see #define CPP_SPEC "%(cpp_subtarget)" #undef CC1_SPEC -#define CC1_SPEC "%(cc1_cpu) " ASAN_CC1_SPEC \ +#define CC1_SPEC "%(cc1_cpu) " ASAN_CC1_SPEC SCTF_CC1_SPEC \ " %{mx32:%e-mx32 is not supported on Solaris}" /* GNU as understands --32 and --64, but the native Solaris diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h index 026d363ff6bb..acf7518b8463 100644 --- a/gcc/config/sol2.h +++ b/gcc/config/sol2.h @@ -357,13 +357,29 @@ along with GCC; see the file COPYING3. If not see #define LINK_CLEARCAP_SPEC "" #endif +/* Convenience alias for Solaris CTF generation. */ +#ifdef HAVE_LD_CTF +#define SCTF_CC1_SPEC " %{gsctf:-gctf} %<gsctf" +#else +#define SCTF_CC1_SPEC " %{gsctf:%e-gsctf is not supported in this configuration}" +#endif + +/* How to generate Solaris CTF. */ +#ifdef HAVE_LD_CTF +/* Direct linker support. */ +#define LINK_SCTF_SPEC " %{gsctf:-z ctf}" +#else +#define LINK_SCTF_SPEC \ + " %{gsctf:%e-gsctf is not supported in this configuration}" +#endif + #undef LINK_SPEC #define LINK_SPEC \ "%{h*} %{v:-V} \ %{!shared:%{!static:%{rdynamic: " RDYNAMIC_SPEC "}}} \ %{static:-dn -Bstatic} \ %{shared:-G -dy %{!mimpure-text:-z text}} " \ - LINK_LIBGCC_MAPFILE_SPEC LINK_CLEARCAP_SPEC " \ + LINK_LIBGCC_MAPFILE_SPEC LINK_CLEARCAP_SPEC LINK_SCTF_SPEC " \ %{symbolic:-Bsymbolic -G -dy -z text} \ %(link_arch) \ %{Qy:} %{!Qn:-Qy}" diff --git a/gcc/config/sol2.opt b/gcc/config/sol2.opt index d1bfad8fdf6f..0f9429efabf1 100644 --- a/gcc/config/sol2.opt +++ b/gcc/config/sol2.opt @@ -27,6 +27,10 @@ Driver Joined Ym, Driver Joined +gsctf +Driver RejectNegative +Generate Solaris CTF. + mclear-hwcap Target Clear hardware capabilities when linking. diff --git a/gcc/config/sol2.opt.urls b/gcc/config/sol2.opt.urls index ef64d47d65ee..16f87ebb29cc 100644 --- a/gcc/config/sol2.opt.urls +++ b/gcc/config/sol2.opt.urls @@ -3,6 +3,9 @@ G UrlSuffix(gcc/System-V-Options.html#index-G-5) +gsctf +UrlSuffix(gcc/Solaris-2-Options.html#index-gsctf) + mclear-hwcap UrlSuffix(gcc/Solaris-2-Options.html#index-mclear-hwcap) diff --git a/gcc/config/sparc/sol2.h b/gcc/config/sparc/sol2.h index 8db85c235429..f466f2cb9956 100644 --- a/gcc/config/sparc/sol2.h +++ b/gcc/config/sparc/sol2.h @@ -240,7 +240,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); %{m64:%{m32:%emay not use both -m32 and -m64}} \ %{m64:-mptr64 -mstack-bias -mno-v8plus \ %{!mcpu*:-%{!mv8plus:mcpu=v9}}} \ -" ASAN_CC1_SPEC +" ASAN_CC1_SPEC SCTF_CC1_SPEC #else #define CC1_SPEC "\ %{m32:%{m64:%emay not use both -m32 and -m64}} \ @@ -248,7 +248,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); %{!mcpu*:%{!mv8plus:-mcpu=v9}}} \ %{mv8plus:-m32 -mptr32 -mno-stack-bias \ %{!mcpu*:-mcpu=v9}} \ -" ASAN_CC1_SPEC +" ASAN_CC1_SPEC SCTF_CC1_SPEC #endif /* Support for a compile-time default CPU, et cetera. The rules are: diff --git a/gcc/configure b/gcc/configure index 0d3e0fe5b905..f4665e85103e 100755 --- a/gcc/configure +++ b/gcc/configure @@ -33154,6 +33154,21 @@ _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_compress_debug" >&5 $as_echo "$gcc_cv_ld_compress_debug" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking linker support for -z ctf" >&5 +$as_echo_n "checking linker support for -z ctf... " >&6; } +gcc_cv_ld_ctf=no +# Check for Solaris ld 1.3315 introduced in Solaris 11.4 SRU 84. ld -z ctf +# already went in in SRU 81, but lacked GNU CTF to Solaris CTF conversion. +if $gcc_cv_ld --help 2>&1 | grep -- '-z ctf' > /dev/null \ + && test x$gnu_ld = xno && test "$ld_vers_minor" -ge 3315; then + gcc_cv_ld_ctf=yes + +$as_echo "#define HAVE_LD_CTF 1" >>confdefs.h + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_ctf" >&5 +$as_echo "$gcc_cv_ld_ctf" >&6; } + if test x"$ld64_flag" = x"yes"; then # Set defaults for possibly untestable items. diff --git a/gcc/configure.ac b/gcc/configure.ac index c0244dc85040..6777200dc93a 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -6435,6 +6435,17 @@ AC_DEFINE_UNQUOTED(LD_COMPRESS_DEBUG_OPTION, "$gcc_cv_ld_compress_debug_option", [Define to the linker option to enable compressed debug sections.]) AC_MSG_RESULT($gcc_cv_ld_compress_debug) +AC_MSG_CHECKING(linker support for -z ctf) +gcc_cv_ld_ctf=no +# Check for Solaris ld 1.3315 introduced in Solaris 11.4 SRU 84. ld -z ctf +# already went in in SRU 81, but lacked GNU CTF to Solaris CTF conversion. +if $gcc_cv_ld --help 2>&1 | grep -- '-z ctf' > /dev/null \ + && test x$gnu_ld = xno && test "$ld_vers_minor" -ge 3315; then + gcc_cv_ld_ctf=yes + AC_DEFINE(HAVE_LD_CTF, 1, [Define if your linker supports -z ctf.]) +fi +AC_MSG_RESULT($gcc_cv_ld_ctf) + if test x"$ld64_flag" = x"yes"; then # Set defaults for possibly untestable items. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index f6acc54846c5..01c3dedbae78 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1445,7 +1445,7 @@ See RS/6000 and PowerPC Options. @emph{Solaris 2 Options} (@ref{Solaris 2 Options}) @gccoptlist{-mclear-hwcap -mno-clear-hwcap -mimpure-text -mno-impure-text --pthreads} +-gsctf -pthreads} @emph{SPARC Options} (@ref{SPARC Options}) @gccoptlist{-mcpu=@var{cpu-type} @@ -34574,6 +34574,12 @@ using @option{-mimpure-text}, you should compile all source code with These switches are supported in addition to the above on Solaris 2: @table @gcctabopt +@opindex gsctf +@item -gsctf +Generate Solaris CTF. Needs to be used both for compilation and +linking. See @command{ctf(7)} for more information. This is only +supported since Solaris 11.4 SRU 84 where the necessary toolchain +support was added. @opindex pthreads @item -pthreads This is a synonym for @option{-pthread}.
