On Sat, May 25, 2024 at 09:13:12AM -0300, Alexandre Oliva wrote: > Some of the rs6000 call patterns, on some ABIs, issue multiple opcodes > out of a single call insn, but the call (bl) or jump (b) is not always > the last opcode in the sequence.
> This does not seem to be a problem for exception handling tables, but > the return_pc attribute in the call graph output in dwarf2+ debug > information, that takes the address of a label output right after the > call, does not match the value of the link register even for non-tail > calls. E.g., with ABI_AIX or ABI_ELFv2, such code as: > > foo (); > > outputs: > > bl foo > nop > LVL#: > [...] > .8byte .LVL# # DW_AT_call_return_pc > > but debug info consumers may rely on the return_pc address, and draw > incorrect conclusions from its off-by-4 value. > > This patch uses the infrastructure for targets to add an offset to the > label issued after the call_insn to set the call_return_pc attribute, > on rs6000, to account for opcodes issued after actual call opcode as > part of call insns output patterns. > for gcc/ChangeLog > > * config/rs6000/rs6000.cc (TARGET_CALL_OFFSET_RETURN_LABEL): > Override. Please don't (incorrectly!) line-wrap changelogs. Lines are 80 characters wide, not 60 or 72 or whatever. 80. Indents are tabs that take 8 columns. > +/* Return the offset to be added to the label output after CALL_INSN > + to compute the address to be placed in DW_AT_call_return_pc. */ > + > +static int > +rs6000_call_offset_return_label (rtx_insn *call_insn) > +{ > + /* All rs6000 CALL_INSN output patterns start with a b or bl, always This isn't true. There is a crlogical insn before the bcl for sysv for example. > + a 4-byte instruction, but some output patterns issue other > + opcodes afterwards. The return label is issued after the entire > + call insn, including any such post-call opcodes. Instead of > + figuring out which cases need adjustments, we compute the offset > + back to the address of the call opcode proper, then add the > + constant 4 bytes, to get the address after that opcode. */ > + return 4 - get_attr_length (call_insn); Please explain this magic, too -- in code preferably (so with a ? : maybe, but don't try to "optimise" that expression, let the compiler do that, it is much better at it anyway :-) ) > +} Is that correct for all ABIs we support? Even if so, it needs a lot more documentation than this. Segher