From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id AB8AF385B51D; Thu, 23 Mar 2023 03:48:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB8AF385B51D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679543293; bh=s6Ob94Qq8qCaFoAWQTBKBBUxU3gtGBChHyS1bZll3q8=; h=From:To:Subject:Date:From; b=ER/O6KOfVca72K5Owiy/jEeHvBF4DJNZJwr+1iTCcQqcicRgfnPXELX/2Vw5WiycQ 0y4MUMrUWuuvQbMbUCCzx4RBWGpvggKhsFvVjsVTtvFW2kQc5mesTG2GNXa/0n8bPj Z/Qj0tD7q23rylJYfj/VpvOGZHP0IETpi5gP0/6Y= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] [rs6000] adjust return_pc debug attrs X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: cec5a04e13d8c868a8231afa344f444187d7f8b4 X-Git-Newrev: 864f3e61227ea45dbf6c171156a8a3778e371cc3 Message-Id: <20230323034813.AB8AF385B51D@sourceware.org> Date: Thu, 23 Mar 2023 03:48:13 +0000 (GMT) List-Id: https://gcc.gnu.org/g:864f3e61227ea45dbf6c171156a8a3778e371cc3 commit 864f3e61227ea45dbf6c171156a8a3778e371cc3 Author: Alexandre Oliva Date: Thu Mar 23 00:45:00 2023 -0300 [rs6000] adjust return_pc debug attrs 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. (rs6000_call_offset_return_label): New. Diff: --- gcc/config/rs6000/rs6000.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index fa5f93a874f..385ef667d74 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -1760,6 +1760,9 @@ static const struct attribute_spec rs6000_attribute_table[] = #undef TARGET_UPDATE_IPA_FN_TARGET_INFO #define TARGET_UPDATE_IPA_FN_TARGET_INFO rs6000_update_ipa_fn_target_info + +#undef TARGET_CALL_OFFSET_RETURN_LABEL +#define TARGET_CALL_OFFSET_RETURN_LABEL rs6000_call_offset_return_label /* Processor table. */ @@ -14547,6 +14550,22 @@ rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p) return default_assemble_integer (x, size, aligned_p); } +/* 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 + 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); +} + /* Return a template string for assembly to emit when making an external call. FUNOP is the call mem argument operand number. */