From patchwork Tue Jan 2 19:41:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 1881719 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=h4fb2eq1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T4Nd74pLSz23dJ for ; Wed, 3 Jan 2024 06:46:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5AEA33857C52 for ; Tue, 2 Jan 2024 19:46:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id C4CBD385840F; Tue, 2 Jan 2024 19:45:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4CBD385840F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4CBD385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704224729; cv=none; b=xVWAZ2kCydnhDodNkerFpJym3QlVKFBA+g4lQGy4thmOsRkZAh2AwU12yowFM8R8uiJJP6tXP1GkFLYURI0TejuTrur1h3e/Khvfx8nWGJALsCKoZORatha4zNNcsmZmVI2xwfQI+We4JK830+ibNUaB0b1VXXJcRiHMzCwkldE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704224729; c=relaxed/simple; bh=k67CNP7FvWSfdg3Hy29IBk0TJ3kuTM81GPQnhAm6nlg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mrtdz9taWrhOJ+3hmruh4kcW8f0wJQzd9jl6ce/qvKRpjEKg6ziW+/XelfSY2KS0zsVlRTr45EJNjM9mXNfXdCnudU0NH9Eyl+/GB4akdjqeOwRPSB7bPgNr97g/zXfXGzfXhzdURWz04e6vxh9+u9WklM1NxTrVlgFlOPCy1PY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 402JRcPk031298; Tue, 2 Jan 2024 19:45:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=pG4KmX7s8T980hjvVWCX08++NEPtgfOnESp6V08um8M=; b=h4fb2eq18gR2eipbuoQ0JaEsbBpCS73Y2mpcvCxkifMNm38k0aS0TsE8M0JFPAymFYaP SoFiOAYGMHSLH9WDfFzyxjneNazgpeT8Jwcw77Fkxy6mKBWhnxKeYeLEH4RTGS835iV9 7riLokUc52y2IrwL0Xy386HV2RPcYz9vJvRbdHtFZvemdQFA//ndFTuQkXin7qzmieZH Wme+duc4meP456Ah2Ni4kgKICwtbtiZlE0uKJAlvzThCwQMtY8Oa3/AICLAKm9YD/ECm RQtBcIJrxPaSdGa+j5WUTTBotItlilStLzxYlAUnIl77SBBqX/LNligrx2KY5RCqVzqX +Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vcrnf8923-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 19:45:22 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 402JVBLF008608; Tue, 2 Jan 2024 19:45:22 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vcrnf891v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 19:45:22 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 402IRoql024554; Tue, 2 Jan 2024 19:45:21 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vb0826cus-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 19:45:21 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 402JjIeW22610646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 2 Jan 2024 19:45:18 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 689BE2004B; Tue, 2 Jan 2024 19:45:18 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6B7520040; Tue, 2 Jan 2024 19:45:17 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.70.156]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 2 Jan 2024 19:45:17 +0000 (GMT) From: Ilya Leoshkevich To: Jakub Jelinek , Jeff Law , Richard Sandiford Cc: Andreas Krebbel , gcc-patches@gcc.gnu.org, Segher Boessenkool , Stefan Schulze Frielinghaus , Ilya Leoshkevich Subject: [PATCH v2 1/2] Implement ASM_DECLARE_FUNCTION_NAME using ASM_OUTPUT_FUNCTION_LABEL Date: Tue, 2 Jan 2024 20:41:37 +0100 Message-ID: <20240102194511.3171559-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240102194511.3171559-1-iii@linux.ibm.com> References: <20240102194511.3171559-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: iHUjtk5zLYaM-qZ5wm3BeVX0MyfitfyH X-Proofpoint-GUID: KKRc39nCCF2DwiGPn-UyGWn8nUlDtPSh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-02_07,2024-01-02_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 phishscore=0 suspectscore=0 mlxscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 impostorscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401020148 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gccint recommends using ASM_OUTPUT_FUNCTION_LABEL in ASM_DECLARE_FUNCTION_NAME, but many implementations use ASM_OUTPUT_LABEL instead. It's inconsistent and prevents changes to ASM_OUTPUT_FUNCTION_LABEL from affecting the respective targets. --- gcc/config/aarch64/aarch64.cc | 2 +- gcc/config/alpha/alpha.cc | 5 ++--- gcc/config/arm/aout.h | 2 +- gcc/config/arm/arm.cc | 2 +- gcc/config/bfin/bfin.h | 16 ++++++++-------- gcc/config/c6x/c6x.h | 2 +- gcc/config/gcn/gcn.cc | 5 ++--- gcc/config/h8300/h8300.h | 2 +- gcc/config/ia64/ia64.cc | 5 ++--- gcc/config/mcore/mcore-elf.h | 2 +- gcc/config/microblaze/microblaze.cc | 3 +-- gcc/config/mips/mips.cc | 19 ++++++++++--------- gcc/config/pa/pa.cc | 3 ++- gcc/config/riscv/riscv.cc | 2 +- gcc/config/rs6000/rs6000.cc | 4 ++-- 15 files changed, 36 insertions(+), 38 deletions(-) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 298477d88bb..e3c72f60d4e 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -24207,7 +24207,7 @@ aarch64_declare_function_name (FILE *stream, const char* name, /* Don't forget the type directive for ELF. */ ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function"); - ASM_OUTPUT_LABEL (stream, name); + ASM_OUTPUT_FUNCTION_LABEL (stream, name, fndecl); cfun->machine->label_is_assembled = true; } diff --git a/gcc/config/alpha/alpha.cc b/gcc/config/alpha/alpha.cc index 6aa93783226..8118255e737 100644 --- a/gcc/config/alpha/alpha.cc +++ b/gcc/config/alpha/alpha.cc @@ -7986,8 +7986,7 @@ int num_source_filenames = 0; /* Output the textual info surrounding the prologue. */ void -alpha_start_function (FILE *file, const char *fnname, - tree decl ATTRIBUTE_UNUSED) +alpha_start_function (FILE *file, const char *fnname, tree decl) { unsigned long imask, fmask; /* Complete stack size needed. */ @@ -8052,7 +8051,7 @@ alpha_start_function (FILE *file, const char *fnname, if (TARGET_ABI_OPEN_VMS) strcat (entry_label, "..en"); - ASM_OUTPUT_LABEL (file, entry_label); + ASM_OUTPUT_FUNCTION_LABEL (file, entry_label, decl); inside_function = TRUE; if (TARGET_ABI_OPEN_VMS) diff --git a/gcc/config/arm/aout.h b/gcc/config/arm/aout.h index 49896bb9620..380147aed7d 100644 --- a/gcc/config/arm/aout.h +++ b/gcc/config/arm/aout.h @@ -152,7 +152,7 @@ do \ { \ ARM_DECLARE_FUNCTION_NAME (STREAM, NAME, DECL); \ - ASM_OUTPUT_LABEL (STREAM, NAME); \ + ASM_OUTPUT_FUNCTION_LABEL (STREAM, NAME, DECL); \ } \ while (0) #endif diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index 0c0cb14a8a4..7ca607b3de1 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -21800,7 +21800,7 @@ arm_asm_declare_function_name (FILE *file, const char *name, tree decl) ARM_DECLARE_FUNCTION_NAME (file, name, decl); ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function"); ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); - ASM_OUTPUT_LABEL (file, name); + ASM_OUTPUT_FUNCTION_LABEL (file, name, decl); if (cmse_name) ASM_OUTPUT_LABEL (file, cmse_name); diff --git a/gcc/config/bfin/bfin.h b/gcc/config/bfin/bfin.h index c25f41f6839..60a8d716819 100644 --- a/gcc/config/bfin/bfin.h +++ b/gcc/config/bfin/bfin.h @@ -995,14 +995,14 @@ typedef enum directives { fputc ('\n',FILE); \ } while (0) -#define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL) \ - do { \ - fputs (".type ", FILE); \ - assemble_name (FILE, NAME); \ - fputs (", STT_FUNC", FILE); \ - fputc (';',FILE); \ - fputc ('\n',FILE); \ - ASM_OUTPUT_LABEL(FILE, NAME); \ +#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ + do { \ + fputs (".type ", FILE); \ + assemble_name (FILE, NAME); \ + fputs (", STT_FUNC", FILE); \ + fputc (';', FILE); \ + fputc ('\n', FILE); \ + ASM_OUTPUT_FUNCTION_LABEL (FILE, NAME, DECL); \ } while (0) #define ASM_OUTPUT_LABEL(FILE, NAME) \ diff --git a/gcc/config/c6x/c6x.h b/gcc/config/c6x/c6x.h index 26b2f2f0700..790b9627ebe 100644 --- a/gcc/config/c6x/c6x.h +++ b/gcc/config/c6x/c6x.h @@ -459,7 +459,7 @@ struct GTY(()) machine_function c6x_output_file_unwind (FILE); \ ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \ ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \ - ASM_OUTPUT_LABEL (FILE, NAME); \ + ASM_OUTPUT_FUNCTION_LABEL (FILE, NAME, DECL); \ } \ while (0) diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc index b67551a2e8e..b2528d49de4 100644 --- a/gcc/config/gcn/gcn.cc +++ b/gcc/config/gcn/gcn.cc @@ -6555,7 +6555,7 @@ output_file_start (void) comments that pass information to mkoffload. */ void -gcn_hsa_declare_function_name (FILE *file, const char *name, tree) +gcn_hsa_declare_function_name (FILE *file, const char *name, tree decl) { int sgpr, vgpr, avgpr; bool xnack_enabled = TARGET_XNACK; @@ -6716,8 +6716,7 @@ gcn_hsa_declare_function_name (FILE *file, const char *name, tree) fputs ("\t.type\t", file); assemble_name (file, name); fputs (",@function\n", file); - assemble_name (file, name); - fputs (":\n", file); + ASM_OUTPUT_FUNCTION_LABEL (file, name, decl); /* This comment is read by mkoffload. */ if (flag_openacc) diff --git a/gcc/config/h8300/h8300.h b/gcc/config/h8300/h8300.h index 311e4023dfd..b62779a9273 100644 --- a/gcc/config/h8300/h8300.h +++ b/gcc/config/h8300/h8300.h @@ -650,7 +650,7 @@ struct cum_arg #define GLOBAL_ASM_OP "\t.global " #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ - ASM_OUTPUT_LABEL (FILE, NAME) + ASM_OUTPUT_FUNCTION_LABEL (FILE, NAME, DECL) /* This is how to store into the string LABEL the symbol_ref name of an internal numbered label where diff --git a/gcc/config/ia64/ia64.cc b/gcc/config/ia64/ia64.cc index ac566efcf19..92d00bf922f 100644 --- a/gcc/config/ia64/ia64.cc +++ b/gcc/config/ia64/ia64.cc @@ -3886,8 +3886,7 @@ ia64_expand_prologue (void) /* Output the textual info surrounding the prologue. */ void -ia64_start_function (FILE *file, const char *fnname, - tree decl ATTRIBUTE_UNUSED) +ia64_start_function (FILE *file, const char *fnname, tree decl) { #if TARGET_ABI_OPEN_VMS vms_start_function (fnname); @@ -3896,7 +3895,7 @@ ia64_start_function (FILE *file, const char *fnname, fputs ("\t.proc ", file); assemble_name (file, fnname); fputc ('\n', file); - ASM_OUTPUT_LABEL (file, fnname); + ASM_OUTPUT_FUNCTION_LABEL (file, fnname, decl); } /* Called after register allocation to add any instructions needed for the diff --git a/gcc/config/mcore/mcore-elf.h b/gcc/config/mcore/mcore-elf.h index bf1b093d327..3e0b903727b 100644 --- a/gcc/config/mcore/mcore-elf.h +++ b/gcc/config/mcore/mcore-elf.h @@ -51,7 +51,7 @@ along with GCC; see the file COPYING3. If not see } \ ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \ ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \ - ASM_OUTPUT_LABEL (FILE, NAME); \ + ASM_OUTPUT_FUNCTION_LABEL (FILE, NAME, DECL); \ } \ while (0) diff --git a/gcc/config/microblaze/microblaze.cc b/gcc/config/microblaze/microblaze.cc index 3ea177b835e..79405a32dc1 100644 --- a/gcc/config/microblaze/microblaze.cc +++ b/gcc/config/microblaze/microblaze.cc @@ -2792,8 +2792,7 @@ microblaze_function_prologue (FILE * file) ASM_OUTPUT_TYPE_DIRECTIVE (file, fnname, "function"); } - assemble_name (file, fnname); - fputs (":\n", file); + ASM_OUTPUT_FUNCTION_LABEL (file, fnname, current_function_decl); if (interrupt_handler && strcmp (INTERRUPT_HANDLER_NAME, fnname)) fputs ("_interrupt_handler:\n", file); diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index 9180dbbf843..be5302b0b7f 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -7269,7 +7269,7 @@ mips_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, /* Declare a unique, locally-binding function called NAME, then start its definition. */ -static void +static tree mips_start_unique_function (const char *name) { tree decl; @@ -7291,13 +7291,15 @@ mips_start_unique_function (const char *name) fputs ("\t.hidden\t", asm_out_file); assemble_name (asm_out_file, name); putc ('\n', asm_out_file); + + return decl; } /* Start a definition of function NAME. MIPS16_P indicates whether the function contains MIPS16 code. */ static void -mips_start_function_definition (const char *name, bool mips16_p) +mips_start_function_definition (const char *name, bool mips16_p, tree decl) { if (mips16_p) fprintf (asm_out_file, "\t.set\tmips16\n"); @@ -7321,8 +7323,7 @@ mips_start_function_definition (const char *name, bool mips16_p) ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, name, "function"); /* Start the definition proper. */ - assemble_name (asm_out_file, name); - fputs (":\n", asm_out_file); + ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, name, decl); } /* End a function definition started by mips_start_function_definition. */ @@ -7349,8 +7350,8 @@ mips_finish_stub (mips_one_only_stub **stub_ptr) return; const char *name = stub->get_name (); - mips_start_unique_function (name); - mips_start_function_definition (name, false); + tree decl = mips_start_unique_function (name); + mips_start_function_definition (name, false, decl); stub->output_body (); mips_end_function_definition (name); delete stub; @@ -7604,7 +7605,7 @@ mips16_build_function_stub (void) /* Start the function definition. */ assemble_start_function (stubdecl, stubname); - mips_start_function_definition (stubname, false); + mips_start_function_definition (stubname, false, stubdecl); /* If generating pic2 code, either set up the global pointer or switch to pic0. */ @@ -7864,7 +7865,7 @@ mips16_build_call_stub (rtx retval, rtx *fn_ptr, rtx args_size, int fp_code) /* Start the function definition. */ assemble_start_function (stubdecl, stubname); - mips_start_function_definition (stubname, false); + mips_start_function_definition (stubname, false, stubdecl); if (fp_ret_p) { @@ -12064,7 +12065,7 @@ mips_output_function_prologue (FILE *file) assemble_start_function. This is needed so that the name used here exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */ fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); - mips_start_function_definition (fnname, TARGET_MIPS16); + mips_start_function_definition (fnname, TARGET_MIPS16, current_function_decl); /* Output MIPS-specific frame information. */ if (!flag_inhibit_size_directive) diff --git a/gcc/config/pa/pa.cc b/gcc/config/pa/pa.cc index 2ee987796f6..cd9210a3ff9 100644 --- a/gcc/config/pa/pa.cc +++ b/gcc/config/pa/pa.cc @@ -3991,7 +3991,8 @@ pa_output_function_label (FILE *file) /* The function's label and associated .PROC must never be separated and must be output *after* any profiling declarations to avoid changing spaces/subspaces within a procedure. */ - ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); + const char *name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); + ASM_OUTPUT_FUNCTION_LABEL (file, name, current_function_decl); fputs ("\t.PROC\n", file); /* pa_expand_prologue does the dirty work now. We just need diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 0d1cbc5cb5f..974f6d5f917 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -8486,7 +8486,7 @@ riscv_declare_function_name (FILE *stream, const char *name, tree fndecl) { riscv_asm_output_variant_cc (stream, fndecl, name); ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function"); - ASM_OUTPUT_LABEL (stream, name); + ASM_OUTPUT_FUNCTION_LABEL (stream, name, fndecl); if (DECL_FUNCTION_SPECIFIC_TARGET (fndecl)) { fprintf (stream, "\t.option push\n"); diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 6b9a40fcc66..6c9f99c6e87 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -21419,7 +21419,7 @@ rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl) fputs ("\t.long 0\n", file); fprintf (file, "\t.previous\n"); } - ASM_OUTPUT_LABEL (file, name); + ASM_OUTPUT_FUNCTION_LABEL (file, name, decl); } static void rs6000_elf_file_end (void) ATTRIBUTE_UNUSED; @@ -21992,7 +21992,7 @@ rs6000_xcoff_declare_function_name (FILE *file, const char *name, tree decl) assemble_name (file, buffer); fputs (TARGET_32BIT ? "\n" : ",3\n", file); - ASM_OUTPUT_LABEL (file, buffer); + ASM_OUTPUT_FUNCTION_LABEL (file, buffer, decl); symtab_node::get (decl)->call_for_symbol_and_aliases (rs6000_declare_alias, &data, true); From patchwork Tue Jan 2 19:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 1881718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=F6DIOuis; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T4Nd65xSFz23dW for ; Wed, 3 Jan 2024 06:46:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B31F63857C6B for ; Tue, 2 Jan 2024 19:46:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 4B4163858281; Tue, 2 Jan 2024 19:45:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B4163858281 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4B4163858281 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704224729; cv=none; b=Ovv2ruZVPmnT4pMILtdvgdL4pZy0v9rWwPWpxYdDn2BHs/uPDMjZfX2z5nK0amTq0V7hsm+Xj/36c3tzlnXz+dMCCvjt1T5MkJp6ETSXmu/M+BXH3xheKTB8nlJBRv9Fmqy5Yp+cRgMVZQxHNx0RvRln5bt/1xzwcewL1frRDYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704224729; c=relaxed/simple; bh=D4TOyMnd7P9zpOCSZTcb20wI/mfB2UJVSbAxjj8PUcU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YEt9SZVKgrOCnDsc/+2z8OULzYBeChE4b2xLT+gbebtc5EnXnXibFMA2bg9aAtr3mBMt+w+mhfy9692kjXE1ep8w4BaHu6KUzuKxRKgqP4AOA3nw1q5yU8pnF6LfcFnwUvuIs2xbMeoVp2FZ32ks1QI4/wTEjfYeFqIURyeTk3U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 402JLRpZ014985; Tue, 2 Jan 2024 19:45:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=I6QZ1QcrvqWbbMqEdLLTeO4bXGXWMTLCJnuiOrBPNC8=; b=F6DIOuisQcAGgrVCsUmlDgSb7YEu398HTqb9d546m2YDzI09kjc0FTyKLgqelT5+Sfmm T/aj/Oc+ZH3zCtfSzoyHKQYYM2wmHM03Gsf9oZm8C3g+8c6Ht3bwc+4awYuiPey2skFb RJMK8w84yk39j1ZIHa4XHyoSA3IJIlT1Ssbo1+FoYysUNcQAVpjxACiysUAeW7aIRdnC Ff4O39lLSTExXJmH4SMMqH6sm3dn4gwdwXGFcOcj5xxm8LFxvspyFYJB1DCJllWMRqeC UROIy2QxQ+ETrK/SnF+y+Qcgh42anMQmZ2FviEo38gBBKseS3b/wtPQ4LdyscyyCFIdA tA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vcr7trtx4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 19:45:23 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 402JM1D3017126; Tue, 2 Jan 2024 19:45:23 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vcr7trtwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 19:45:23 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 402HjnDd017981; Tue, 2 Jan 2024 19:45:22 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vayrkekhm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 19:45:22 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 402JjJ3a26935712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 2 Jan 2024 19:45:19 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 77C8C20040; Tue, 2 Jan 2024 19:45:19 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0328F20043; Tue, 2 Jan 2024 19:45:19 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.70.156]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 2 Jan 2024 19:45:18 +0000 (GMT) From: Ilya Leoshkevich To: Jakub Jelinek , Jeff Law , Richard Sandiford Cc: Andreas Krebbel , gcc-patches@gcc.gnu.org, Segher Boessenkool , Stefan Schulze Frielinghaus , Ilya Leoshkevich Subject: [PATCH v2 2/2] asan: Align .LASANPC on function boundary Date: Tue, 2 Jan 2024 20:41:38 +0100 Message-ID: <20240102194511.3171559-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240102194511.3171559-1-iii@linux.ibm.com> References: <20240102194511.3171559-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: mtwufcPHcfOl930VaXDtlLedCtWuqPK5 X-Proofpoint-ORIG-GUID: 0oiOLgfq7haWvb2AxhQ1BJ_bzS0gvPCS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-02_07,2024-01-02_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxscore=0 impostorscore=0 phishscore=0 spamscore=0 clxscore=1015 priorityscore=1501 suspectscore=0 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401020148 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org GCC can emit code between the function label and the .LASANPC label, making the latter unaligned. Some architectures cannot load unaligned labels directly and require literal pool entries, which is inefficient. Move the invocation of asan_function_start to ASM_OUTPUT_FUNCTION_LABEL, which guarantees that no additional code is emitted. This allows setting the .LASANPC label alignment to the respective function alignment. --- gcc/asan.cc | 6 ++---- gcc/config/i386/i386.cc | 2 +- gcc/config/s390/s390.cc | 2 +- gcc/defaults.h | 2 +- gcc/final.cc | 3 --- gcc/output.h | 4 ++++ gcc/varasm.cc | 14 ++++++++++++++ 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/gcc/asan.cc b/gcc/asan.cc index 8d0ffb497cc..48738244aba 100644 --- a/gcc/asan.cc +++ b/gcc/asan.cc @@ -1481,10 +1481,7 @@ asan_clear_shadow (rtx shadow_mem, HOST_WIDE_INT len) void asan_function_start (void) { - section *fnsec = function_section (current_function_decl); - switch_to_section (fnsec); - ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LASANPC", - current_function_funcdef_no); + ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LASANPC", current_function_funcdef_no); } /* Return number of shadow bytes that are occupied by a local variable @@ -2006,6 +2003,7 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb, DECL_INITIAL (decl) = decl; TREE_ASM_WRITTEN (decl) = 1; TREE_ASM_WRITTEN (id) = 1; + DECL_ALIGN_RAW (decl) = DECL_ALIGN_RAW (current_function_decl); emit_move_insn (mem, expand_normal (build_fold_addr_expr (decl))); shadow_base = expand_binop (Pmode, lshr_optab, base, gen_int_shift_amount (Pmode, ASAN_SHADOW_SHIFT), diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 38d515dac04..09fc2b63ee3 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -1640,7 +1640,7 @@ ix86_asm_output_function_label (FILE *out_file, const char *fname, SUBTARGET_ASM_UNWIND_INIT (out_file); #endif - ASM_OUTPUT_LABEL (out_file, fname); + assemble_function_label_raw (out_file, fname); /* Output magic byte marker, if hot-patch attribute is set. */ if (is_ms_hook) diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc index a5c36b43972..c871a10506a 100644 --- a/gcc/config/s390/s390.cc +++ b/gcc/config/s390/s390.cc @@ -8323,7 +8323,7 @@ s390_asm_output_function_label (FILE *out_file, const char *fname, asm_fprintf (out_file, "\t# fn:%s wd%d\n", fname, s390_warn_dynamicstack_p); } - ASM_OUTPUT_LABEL (out_file, fname); + assemble_function_label_raw (out_file, fname); if (hw_after > 0) asm_fprintf (out_file, "\t# post-label NOPs for hotpatch (%d halfwords)\n", diff --git a/gcc/defaults.h b/gcc/defaults.h index 6f095969410..b76734908cd 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -150,7 +150,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #ifndef ASM_OUTPUT_FUNCTION_LABEL #define ASM_OUTPUT_FUNCTION_LABEL(FILE, NAME, DECL) \ - ASM_OUTPUT_LABEL ((FILE), (NAME)) + assemble_function_label_raw ((FILE), (NAME)) #endif /* Output the definition of a compiler-generated label named NAME. */ diff --git a/gcc/final.cc b/gcc/final.cc index e6f1b1e166b..5e21aedf8ed 100644 --- a/gcc/final.cc +++ b/gcc/final.cc @@ -1686,9 +1686,6 @@ final_start_function_1 (rtx_insn **firstp, FILE *file, int *seen, high_block_linenum = high_function_linenum = last_linenum; - if (flag_sanitize & SANITIZE_ADDRESS) - asan_function_start (); - rtx_insn *first = *firstp; if (in_initial_view_p (first)) { diff --git a/gcc/output.h b/gcc/output.h index 76cfd58c1e6..bfdecc5ea74 100644 --- a/gcc/output.h +++ b/gcc/output.h @@ -178,6 +178,10 @@ extern void assemble_asm (tree); /* Get the function's name from a decl, as described by its RTL. */ extern const char *get_fnname_from_decl (tree); +/* Output function label, possibly with accompanying metadata. No additional + code or data is output after the label. */ +extern void assemble_function_label_raw (FILE *, const char *); + /* Output assembler code for the constant pool of a function and associated with defining the name of the function. DECL describes the function. NAME is the function's name. For the constant pool, we use the current diff --git a/gcc/varasm.cc b/gcc/varasm.cc index 69f8f8ee018..d0d670d009c 100644 --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -61,6 +61,7 @@ along with GCC; see the file COPYING3. If not see #include "alloc-pool.h" #include "toplev.h" #include "opts.h" +#include "asan.h" /* The (assembler) name of the first globally-visible object output. */ extern GTY(()) const char *first_global_object_name; @@ -1835,6 +1836,19 @@ get_fnname_from_decl (tree decl) return XSTR (x, 0); } +/* Output function label, possibly with accompanying metadata. No additional + code or data is output after the label. */ + +void +assemble_function_label_raw (FILE *file, const char *name) +{ + ASM_OUTPUT_LABEL (file, name); + if ((flag_sanitize & SANITIZE_ADDRESS) + /* Notify ASAN only about the first function label. */ + && (in_cold_section_p == first_function_block_is_cold)) + asan_function_start (); +} + /* Output assembler code for the constant pool of a function and associated with defining the name of the function. DECL describes the function. NAME is the function's name. For the constant pool, we use the current