From patchwork Thu Mar 23 03:12:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 66782 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 207373854811 for ; Thu, 23 Mar 2023 03:13:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 207373854811 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679541186; bh=6LEyR+xiNR7BZovZOsjRDsmHOMnCqARns8aP4C9Niv4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=GBnxVLg/gz0GArDDbVzf0gblUGANzKDfK6OhqCCQw6/j2CVdRIPy+SGW1DOeEpASB 4g8yJYhhMo2Z61nRYVzLX06q8ZBjToRKEff7xNELds5cP6eIXdcRwiXLpUwzxaMzmj oKhD0tGPjArV0Z/FHeqPZDCAfxtH7Ug6h5265HCo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTPS id C56DB385843D for ; Thu, 23 Mar 2023 03:12:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C56DB385843D Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 6BD5A116407; Wed, 22 Mar 2023 23:12:37 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "From" Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id lumA7wbcCMaM; Wed, 22 Mar 2023 23:12:37 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 130AB116403; Wed, 22 Mar 2023 23:12:36 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 32N3CRNa1266324 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 23 Mar 2023 00:12:28 -0300 To: gcc-patches@gcc.gnu.org Cc: Tom Tromey , Jason Merrill , Cary Coutant , Jakub Jelinek Subject: [PATCH v2 #1/2] enable adjustment of return_pc debug attrs Organization: Free thinker, does not speak for AdaCore Date: Thu, 23 Mar 2023 00:12:27 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_MAILSPLOIT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: oliva--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: oliva@adacore.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch introduces infrastructure for targets to add an offset to the label issued after the call_insn to set the call_return_pc attribute. This will be used on rs6000, that sometimes issues another instruction after the call proper as part of a call insn. Regstrapped on x86_64-linux-gnu and ppc64-linux-gnu. Ok to install? for gcc/ChangeLog * target.def (call_offset_return_label): New hook. * gcc/doc/tm.texi.in (TARGET_CALL_OFFSET_RETURN_LABEL): Add placeholder. * gcc/doc/tm.texi: Rebuild. * dwarf2out.cc (struct call_arg_loc_node): Record call_insn instad of call_arg_loc_note. (add_AT_lbl_id): Add optional offset argument. (gen_call_site_die): Compute and pass on a return pc offset. (gen_subprogram_die): Move call_arg_loc_note computation... (dwarf2out_var_location): ... from here. Set call_insn. --- gcc/doc/tm.texi | 7 +++++++ gcc/doc/tm.texi.in | 2 ++ gcc/dwarf2out.cc | 26 +++++++++++++++++--------- gcc/target.def | 9 +++++++++ 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index c4a92a5ebee90..44e4c18ad5c0a 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -5426,6 +5426,13 @@ except the last are treated as named. You need not define this hook if it always returns @code{false}. @end deftypefn +@deftypefn {Target Hook} int TARGET_CALL_OFFSET_RETURN_LABEL (rtx_insn *@var{call_insn}) +While generating call-site debug info for a CALL insn, or a SEQUENCE +insn starting with a CALL, this target hook is invoked to compute the +offset to be added to the debug label emitted after the call to obtain +the return address that should be recorded as the return PC. +@end deftypefn + @deftypefn {Target Hook} void TARGET_CALL_ARGS (rtx, @var{tree}) While generating RTL for a function call, this target hook is invoked once for each argument passed to the function, either a register returned by diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 4075e71624c04..68856978fe364 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -3785,6 +3785,8 @@ These machine description macros help implement varargs: @hook TARGET_STRICT_ARGUMENT_NAMING +@hook TARGET_CALL_OFFSET_RETURN_LABEL + @hook TARGET_CALL_ARGS @hook TARGET_END_CALL_ARGS diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 1711ad2c2da31..d1db918c43900 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -3584,7 +3584,7 @@ typedef struct var_loc_list_def var_loc_list; /* Call argument location list. */ struct GTY ((chain_next ("%h.next"))) call_arg_loc_node { - rtx GTY (()) call_arg_loc_note; + rtx_insn * GTY (()) call_insn; const char * GTY (()) label; tree GTY (()) block; bool tail_call_p; @@ -3768,7 +3768,8 @@ static void remove_addr_table_entry (addr_table_entry *); static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool); static inline rtx AT_addr (dw_attr_node *); static void add_AT_symview (dw_die_ref, enum dwarf_attribute, const char *); -static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *); +static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *, + int = 0); static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *); static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *); static void add_AT_range_list (dw_die_ref, enum dwarf_attribute, @@ -5327,14 +5328,17 @@ add_AT_symview (dw_die_ref die, enum dwarf_attribute attr_kind, static inline void add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, - const char *lbl_id) + const char *lbl_id, int offset) { dw_attr_node attr; attr.dw_attr = attr_kind; attr.dw_attr_val.val_class = dw_val_class_lbl_id; attr.dw_attr_val.val_entry = NULL; - attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); + if (!offset) + attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); + else + attr.dw_attr_val.v.val_lbl_id = xasprintf ("%s%+i", lbl_id, offset); if (dwarf_split_debug_info) attr.dw_attr_val.val_entry = add_addr_table_entry (attr.dw_attr_val.v.val_lbl_id, @@ -23405,7 +23409,9 @@ gen_call_site_die (tree decl, dw_die_ref subr_die, if (stmt_die == NULL) stmt_die = subr_die; die = new_die (dwarf_TAG (DW_TAG_call_site), stmt_die, NULL_TREE); - add_AT_lbl_id (die, dwarf_AT (DW_AT_call_return_pc), ca_loc->label); + add_AT_lbl_id (die, dwarf_AT (DW_AT_call_return_pc), + ca_loc->label, + targetm.calls.call_offset_return_label (ca_loc->call_insn)); if (ca_loc->tail_call_p) add_AT_flag (die, dwarf_AT (DW_AT_call_tail_call), 1); if (ca_loc->symbol_ref) @@ -24092,11 +24098,14 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) { dw_die_ref die = NULL; rtx tloc = NULL_RTX, tlocc = NULL_RTX; + rtx call_arg_loc_note + = find_reg_note (ca_loc->call_insn, + REG_CALL_ARG_LOCATION, NULL_RTX); rtx arg, next_arg; tree arg_decl = NULL_TREE; - for (arg = (ca_loc->call_arg_loc_note != NULL_RTX - ? XEXP (ca_loc->call_arg_loc_note, 0) + for (arg = (call_arg_loc_note != NULL_RTX + ? XEXP (call_arg_loc_note, 0) : NULL_RTX); arg; arg = next_arg) { @@ -28125,8 +28134,7 @@ create_label: = ggc_cleared_alloc (); rtx_insn *prev = call_insn; - ca_loc->call_arg_loc_note - = find_reg_note (call_insn, REG_CALL_ARG_LOCATION, NULL_RTX); + ca_loc->call_insn = call_insn; ca_loc->next = NULL; ca_loc->label = last_label; gcc_assert (prev diff --git a/gcc/target.def b/gcc/target.def index f401fe148ee2d..94c0e22819687 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -4731,6 +4731,15 @@ not generate any instructions in this case.", int *pretend_args_size, int second_time), default_setup_incoming_varargs) +DEFHOOK +(call_offset_return_label, + "While generating call-site debug info for a CALL insn, or a SEQUENCE\n\ +insn starting with a CALL, this target hook is invoked to compute the\n\ +offset to be added to the debug label emitted after the call to obtain\n\ +the return address that should be recorded as the return PC.", + int, (rtx_insn *call_insn), + hook_int_rtx_insn_0) + DEFHOOK (call_args, "While generating RTL for a function call, this target hook is invoked once\n\ From patchwork Thu Mar 23 03:15:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 66783 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE16A385B506 for ; Thu, 23 Mar 2023 03:15:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE16A385B506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679541359; bh=hnEgd74IbEX5CcXct3nJKn4t1TWyKMwjwDm5kZKCrlg=; h=To:Cc:Subject:References:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=o0vsx1wbVzBN9zBvPeAorTcIR1iTyrOQobnWhxFzbrjNDevRm40UXAsYkQRc2b5Rt 15l6WDtaBjqDhavqZ4r8JRGjP90ltG0ofJoCUh9eoYgwFwRa+BjHAccnSeZu9QeODn GKMKQ9+NaOuWngssMB7U2foeVedOrAEHSGKXh5aE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTPS id C2AB3385843D; Thu, 23 Mar 2023 03:15:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2AB3385843D Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 91773116407; Wed, 22 Mar 2023 23:15:30 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id nmLcIgM41wcm; Wed, 22 Mar 2023 23:15:30 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 5C335116403; Wed, 22 Mar 2023 23:15:30 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 32N3FMiD1266382 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 23 Mar 2023 00:15:23 -0300 To: gcc-patches@gcc.gnu.org Cc: Tom Tromey , David Edelsohn , Segher Boessenkool , Kewen Lin Subject: [PATCH v2 #2/2] [rs6000] adjust return_pc debug attrs Organization: Free thinker, does not speak for AdaCore References: Date: Thu, 23 Mar 2023 00:15:22 -0300 In-Reply-To: (Alexandre Oliva's message of "Thu, 23 Mar 2023 00:12:27 -0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alexandre Oliva via Gcc-patches From: Alexandre Oliva Reply-To: Alexandre Oliva Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. Regstrapped on x86_64-linux-gnu and ppc64-linux-gnu. Ok to install? for gcc/ChangeLog * config/rs6000/rs6000.cc (TARGET_CALL_OFFSET_RETURN_LABEL): Override. (rs6000_call_offset_return_label): New. --- 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 8e0b0d022db2f..e55117159b270 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. */ @@ -14593,6 +14596,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. */