On Tue, Jan 03, 2023 at 12:15:23PM +0100, Florian Weimer wrote: > --- a/gcc/debug.h > +++ b/gcc/debug.h > @@ -245,7 +245,18 @@ extern const struct gcc_debug_hooks vmsdbg_debug_hooks; > > /* Dwarf2 frame information. */ > > -extern int dwarf_reg_sizes_constant (); > +/* Query size information about DWARF registers. */ > +struct dwarf_single_register_size > +{ > + dwarf_single_register_size();
Formatting, space before ( > @@ -334,27 +333,39 @@ generate_dwarf_reg_sizes (poly_uint16 *sizes) > targetm.init_dwarf_reg_sizes_extra (sizes); > } > > -/* Return 0 if the DWARF register sizes are not constant, otherwise > - return the size constant. */ > - > -int > -dwarf_reg_sizes_constant () > +dwarf_single_register_size::dwarf_single_register_size() Likewise. > + for (int i = DWARF_FRAME_REGISTERS; i >= 0; --i) > + { > + unsigned short value; > + if (!sizes[i].is_constant (&value) || value != 0) if (!known_eq (sizes[i], 0)) ? Though, I still wonder, because all of this is a hack for a single target - x86_64-linux -m64 - I think no other target has similar constant sizes, whether it wouldn't be better to revert all this compiler side stuff and handle it purely on the libgcc side - allow target headers to specify a simple expression how to compute dwarf_reg_size + don't define dwarf_reg_size_table array in that case and instead in a testcase verify that __builtin_init_dwarf_reg_size_table initializes an array to the exact same values as the libgcc/config/**/*.h overridden dwarf_reg_size version. That way, for x86_64-linux we can use ((index) <= __LIBGCC_DWARF_FRAME_REGISTERS__ ? 8 : 0) but could provide something reasonable even for other targets if it improves the unwinder sufficiently. Say s390x-linux -m64 is ((index) <= 32 ? 8 : (index) == 33 ? 4 : 0) etc. Or, if you want to do it on the compiler side, instead of predefining __LIBGCC_DWARF_REG_SIZES_CONSTANT__ and __LIBGCC_DWARF_REG_MAXIMUM__ register conditionally a new builtin, __builtin_dwarf_reg_size, which would be defined only if -fbuilding-libgcc and the compiler determines dwarf_reg_size is desirable to be computed inline without a table and would fold the builtin to say that index <= 16U ? 8 : 0 on x86_64 -m64, index <= 9U ? 4 : index - 11U <= 5U ? 12 : 0 on x86_64 -m32 etc. and if the expression is too large/complex, wouldn't predefine the builtin. Then you can #if __has_builtin(__builtin_dwarf_reg_size) use the builtin and don't provide the table + initialize it, otherwise initialize + use the table. Or, is it actually the use of table that is bad on the unwinder side, or lack of a small upper bound for what you get from the table? In that case you could predefine upper bound on the sizes instead (if constant) and simply add if (size > __LIBGCC_DWARF_REG_SIZE_MAX__) __builtin_unreachable ()). Jakub