From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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 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 | 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 -- 2.43.0