On Fri, Jul 9, 2021 at 12:23 AM Indu Bhagat via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hello, > > It was brought up when discussing PR debug/101283 (Several tests fail on > Darwin with -gctf/gbtf) that it will be good to provide means for targets to > opt out of CTF/BTF support. > > By and large, it seems to me that CTF/BTF debug formats can be safely enabled > for all ELF-based targets by default in GCC. > > So, at a high level: > - By default, CTF/BTF formats can be enabled for all ELF-based targets. > - By default, CTF/BTF formats can be disabled for all non ELF-based targets. > - If the user passed a -gctf but CTF is not enabled for the target, GCC > issues an error to the user (as is done currently with other debug formats) > - > "target system does not support the 'ctf' debug format". > > This is a makeshift patch which fulfills the above requirements and is based > on > the approach taken for DWARF via DWARF2_DEBUGGING_INFO (I still have to see if > I need some specific handling in common_handle_option in opts.c). On minimal > testing, the patch works as desired on x86_64-pc-linux-gnu and a darwin-based > target. > > My question is - Looking around in config.gcc etc., it seems defining in > elfos.h > gives targets/platforms means to override it by virtue of the recommended > order > of # includes in $tm_file. What I cannot say for certain is if this is true in > practice ? On first look, I believe this could work fine. What do you think ? > > If you think this approach could work, I will continue on this track and > test/refine the patch.
I think it looks reasonable. Note that target macros need to be documented in tm.texi - I think while we generally do not want new target macros but hooks this case can be an exception for consistency purposes (unless somebody else strongly disagrees). Thanks, Richard. > Thanks > Indu > > ------------- > > gcc/ChangeLog: > > * config/elfos.h (CTF_DEBUGGING_INFO): New definition. > (BTF_DEBUGGING_INFO): Likewise. > * toplev.c: Guard initialization of debug hooks. > > gcc/testsuite/ChangeLog: > > * gcc.dg/debug/btf/btf.exp: Do not run BTF testsuite if target does > not > support BTF format. > * gcc.dg/debug/ctf/ctf.exp: Do not run CTF testsuite if target does > not > support CTF format. > --- > gcc/config/elfos.h | 8 ++++++++ > gcc/testsuite/gcc.dg/debug/btf/btf.exp | 11 +++++++++-- > gcc/testsuite/gcc.dg/debug/ctf/ctf.exp | 11 +++++++++-- > gcc/toplev.c | 11 +++++++++-- > 4 files changed, 35 insertions(+), 6 deletions(-) > > diff --git a/gcc/config/elfos.h b/gcc/config/elfos.h > index 7a736cc..e5cb487 100644 > --- a/gcc/config/elfos.h > +++ b/gcc/config/elfos.h > @@ -68,6 +68,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively. > If not, see > > #define DWARF2_DEBUGGING_INFO 1 > > +/* All ELF targets can support CTF. */ > + > +#define CTF_DEBUGGING_INFO 1 > + > +/* All ELF targets can support BTF. */ > + > +#define BTF_DEBUGGING_INFO 1 > + > /* The GNU tools operate better with dwarf2, and it is required by some > psABI's. Since we don't have any native tools to be compatible with, > default to dwarf2. */ > diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf.exp > b/gcc/testsuite/gcc.dg/debug/btf/btf.exp > index e173515..a3e680c 100644 > --- a/gcc/testsuite/gcc.dg/debug/btf/btf.exp > +++ b/gcc/testsuite/gcc.dg/debug/btf/btf.exp > @@ -39,8 +39,15 @@ if ![info exists DEFAULT_CFLAGS] then { > dg-init > > # Main loop. > -dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\] ]] \ > - "" $DEFAULT_CFLAGS > +set comp_output [gcc_target_compile \ > + "$srcdir/$subdir/../trivial.c" "trivial.S" assembly \ > + "additional_flags=-gbtf"] > +if { ! [string match "*: target system does not support the * debug format*" > \ > + $comp_output] } { > + remove-build-file "trivial.S" > + dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\] ]] \ > + "" $DEFAULT_CFLAGS > +} > > # All done. > dg-finish > diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf.exp > b/gcc/testsuite/gcc.dg/debug/ctf/ctf.exp > index 0b650ed..c53cd8b 100644 > --- a/gcc/testsuite/gcc.dg/debug/ctf/ctf.exp > +++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf.exp > @@ -39,8 +39,15 @@ if ![info exists DEFAULT_CFLAGS] then { > dg-init > > # Main loop. > -dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\] ]] \ > - "" $DEFAULT_CFLAGS > +set comp_output [gcc_target_compile \ > + "$srcdir/$subdir/../trivial.c" "trivial.S" assembly \ > + "additional_flags=-gctf"] > +if { ! [string match "*: target system does not support the * debug format*" > \ > + $comp_output] } { > + remove-build-file "trivial.S" > + dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\] ]] \ > + "" $DEFAULT_CFLAGS > +} > > # All done. > dg-finish > diff --git a/gcc/toplev.c b/gcc/toplev.c > index 43f1f7d..8103812 100644 > --- a/gcc/toplev.c > +++ b/gcc/toplev.c > @@ -1463,8 +1463,15 @@ process_options (void) > debug_hooks = &xcoff_debug_hooks; > #endif > #ifdef DWARF2_DEBUGGING_INFO > - else if (dwarf_debuginfo_p () > - || dwarf_based_debuginfo_p ()) > + else if (dwarf_debuginfo_p ()) > + debug_hooks = &dwarf2_debug_hooks; > +#endif > +#ifdef CTF_DEBUGGING_INFO > + else if (write_symbols & CTF_DEBUG) > + debug_hooks = &dwarf2_debug_hooks; > +#endif > +#ifdef BTF_DEBUGGING_INFO > + else if (btf_debuginfo_p ()) > debug_hooks = &dwarf2_debug_hooks; > #endif > #ifdef VMS_DEBUGGING_INFO > -- > 1.8.3.1 >