]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Support Solaris CTF generation
authorRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Sun, 28 Dec 2025 10:32:37 +0000 (11:32 +0100)
committerRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Sun, 28 Dec 2025 10:32:37 +0000 (11:32 +0100)
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  <ro@CeBiTec.Uni-Bielefeld.DE>

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.

gcc/config.in
gcc/config/i386/sol2.h
gcc/config/sol2.h
gcc/config/sol2.opt
gcc/config/sol2.opt.urls
gcc/config/sparc/sol2.h
gcc/configure
gcc/configure.ac
gcc/doc/invoke.texi

index f60704fbba4bff946390fc96c388ecba39b4e821..a424df5a1602fdef173a0fb3e9b650c79f932241 100644 (file)
 #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
index e5942266d33a7c31f2ddb6a5ffffda61f15b2a8e..294803497469e01b80fa46cbb78151ced91ffaf9 100644 (file)
@@ -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
index 026d363ff6bbe1f325ca50d129400f86ef491fa1..acf7518b8463ec21240d30bbace3a516a1aff82b 100644 (file)
@@ -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}"
index d1bfad8fdf6fe014c935e15298ffe61054ec69b8..0f9429efabf1e5cd3e8b32b22226b763169717ea 100644 (file)
@@ -27,6 +27,10 @@ Driver Joined
 Ym,
 Driver Joined
 
+gsctf
+Driver RejectNegative
+Generate Solaris CTF.
+
 mclear-hwcap
 Target
 Clear hardware capabilities when linking.
index ef64d47d65eed960753a4abc000002b4a0fd0ec9..16f87ebb29cc81bd8eea2ef6fb6cedc5f5b6eea9 100644 (file)
@@ -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)
 
index 8db85c235429e16307110a22a229f2011463ab4c..f466f2cb995622fdeca04a619433b7a4762fd60e 100644 (file)
@@ -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:
index 0d3e0fe5b9051f408c7429030a449a49a61d071e..f4665e85103e8d73d71b95d7bd2cb340787c83f7 100755 (executable)
@@ -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.
index c0244dc8504062f84a4208c5f81c208e8263fed7..6777200dc93ab78cbec7a51fb3c1290b201fcef8 100644 (file)
@@ -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.
index f6acc54846c514d87c43bb1aeb3af4073151070c..01c3dedbae7860c0238bcf5545388622da76784c 100644 (file)
@@ -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}.