From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id B38CD3858023; Thu, 7 Dec 2023 12:10:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B38CD3858023 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 B38CD3858023 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701951034; cv=none; b=pbpPFCXD/CU0HohA7GYUCxuEwytU8iKcZAmBwMJUWQTWqC6wSSLdVJKaHMJJhIebt8gQ/qYHkg8pMyVdmxQZM4lRkA3XA+ftIe7O1TDO6Tf4rsz4+Ny0dsjlMV2N7Zp/xBLhYkk7xF8AwZdeB7QvJuYxlDG0KIwHsppirZjS7uM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701951034; c=relaxed/simple; bh=tpY7zperSKniJD9G+O/2smHDYqIin5zVZYf9fwxUDH0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KuzRGVq22PzY0rbTE8WRFht8cCaCCrFXBmcGBBUyw8ey2YC0CqcjD22E21ShpgbhEkedQvPNYBs23cMaYc8pFWrp2rdK11W4U/0PYrK7yRjBEqMeZZa/0zm4vwZqmKuRGP45y4nAkalp0cxSnhW+J7UizrlvYU4rUSJqBrPNpAA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B7C2q5a015576; Thu, 7 Dec 2023 12:10:16 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=7tj8afWic6bGQM9YvGCI49s+zMa6mWwBiCg4A4oZAqg=; b=G3sMnDm/yJcMzY5WfZAj+CJ0Su78yvyjh/t1XWwNP7PTK0JNZi8nTUVwo7GBotm0WBk9 hD8vP4RDxm9MqjKA+JzTQCLRn1ntYpRFQPcDvcpyvCY9rnhTp1qBzQNf0KFJPu9hyB6n 4k6BW0cg+LoBMDxLPmRpWRNq+SinjGg4obNtUCeKgkzgUZtQa/epvbsH7g/wpqG7d/0a 8juBKZId66GpVOu8P787yWyIn5zGVU3XeqMb8kUHaAyyYtDLvr3J2sDSStKcBcJ3a1yS M7UqAwru+MGkxOh9VnFvfWgj9i+LfFkvJWfIo4S3NTtVRO6RbjE+C/LK6bxKwnCJtMpP qA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3uudq7g950-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 12:10:16 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3B7C3mCC018375; Thu, 7 Dec 2023 12:10:15 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3uudq7g94q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 12:10:15 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3B7B6slA013747; Thu, 7 Dec 2023 12:10:15 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3utau4aybe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 12:10:14 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3B7CABcO20710120 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Dec 2023 12:10:12 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D7EFB2004D; Thu, 7 Dec 2023 12:10:11 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A153820043; Thu, 7 Dec 2023 12:10:11 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 7 Dec 2023 12:10:11 +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 2/2] asan: Align .LASANPC on function boundary Date: Thu, 7 Dec 2023 13:08:27 +0100 Message-ID: <20231207121005.3425208-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207121005.3425208-1-iii@linux.ibm.com> References: <20231207121005.3425208-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 66ZpMMqZzgMSfcVY6zXttTJqXeXian4S X-Proofpoint-GUID: mAX0FU_2s54SaMINpK5g3KzQRDUcsyB9 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=2023-12-07_09,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxlogscore=999 impostorscore=0 mlxscore=0 bulkscore=0 spamscore=0 priorityscore=1501 suspectscore=0 phishscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070098 X-Spam-Status: No, score=-11.8 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 List-Id: 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 | 10 ++++++++++ 7 files changed, 19 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 7c5cab4e2c6..a552a300b69 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 044de874590..a022db230db 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 dc6f09cacae..153d3cd32c0 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 167aea87091..28c29883df9 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,15 @@ get_fnname_from_decl (tree decl) return XSTR (x, 0); } +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 -- 2.43.0