From patchwork Tue Mar 1 05:41:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HAO CHEN GUI X-Patchwork-Id: 1599242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Eh8dw3RL; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K7FDx39mbz9sDX for ; Tue, 1 Mar 2022 22:21:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A2593858423 for ; Tue, 1 Mar 2022 05:42:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A2593858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1646113326; bh=6aD5dtim26mPR3443TeZR2gEC+5YJMuQYU5JYz9w/pc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Eh8dw3RLT6guOAnuT4l8mvvqgjpUAygxmld/FkJ57N8N/YGE9hgHG7uNUM4NY645X I7YArmbTOwUGwz80JH8zzHWAeSwuz+y/Okazgwe9sT5vODAxEaiG1Cc7gISJ0J7i5e sNYe1sQwh9/IE+KHFT5aRfDSXlc/jtEgNeD9I2hA= 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 53CCA3858D20 for ; Tue, 1 Mar 2022 05:41:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 53CCA3858D20 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 2215BY8w013179; Tue, 1 Mar 2022 05:41:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ehd4b8hxw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Mar 2022 05:41:21 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 2215cetg010516; Tue, 1 Mar 2022 05:41:21 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ehd4b8hx0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Mar 2022 05:41:21 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2215bUni007162; Tue, 1 Mar 2022 05:41:19 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3egbj15nyw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Mar 2022 05:41:18 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2215fGIO56623432 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Mar 2022 05:41:16 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9FE3452051; Tue, 1 Mar 2022 05:41:16 +0000 (GMT) Received: from [9.200.37.199] (unknown [9.200.37.199]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2C8215204E; Tue, 1 Mar 2022 05:41:14 +0000 (GMT) Message-ID: <3cfd526a-174b-5d09-6683-20a7fb002e04@linux.ibm.com> Date: Tue, 1 Mar 2022 13:41:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: gcc-patches Subject: [PATCH v3, rs6000] Enable absolute jump table for PPC AIX and Linux X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KiWbQozVwJE8cReFqAFc2KgVpQz7_oCd X-Proofpoint-ORIG-GUID: WMu9MeyYw-A7W8TMSvVlP2JuwGXHEPen X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-02-28_10,2022-02-26_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 impostorscore=0 bulkscore=0 spamscore=0 priorityscore=1501 clxscore=1015 malwarescore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2203010026 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: HAO CHEN GUI via Gcc-patches From: HAO CHEN GUI Reply-To: HAO CHEN GUI Cc: Peter Bergner , David , Segher Boessenkool Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch enables absolute jump tables on PPC AIX and Linux. For AIX, the jump table is placed in data section. For Linux, it is placed in RELRO section when relocation is needed. Bootstrapped and tested on AIX,Linux BE and LE with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot. ChangeLog 2022-03-01 Haochen Gui gcc/ * config/rs6000/aix.h (JUMP_TABLES_IN_TEXT_SECTION): Define. * config/rs6000/linux64.h (JUMP_TABLES_IN_TEXT_SECTION): Likewise. * config/rs6000/rs6000.cc (rs6000_option_override_internal): Enable absolute jump tables for AIX and Linux. (rs6000_xcoff_function_rodata_section): Implement. * config/rs6000/xcoff.h (TARGET_ASM_FUNCTION_RODATA_SECTION): Define. gcc/testsuite * gcc.target/powerpc/absolute-jump-table-section.c: New. patch.diff diff --git a/gcc/config/rs6000/aix.h b/gcc/config/rs6000/aix.h index ad3238bf09a..cf0708aa08b 100644 --- a/gcc/config/rs6000/aix.h +++ b/gcc/config/rs6000/aix.h @@ -251,9 +251,9 @@ #define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \ (!(FIRST) ? PAD_UPWARD : targetm.calls.function_arg_padding (MODE, TYPE)) -/* Indicate that jump tables go in the text section. */ +/* Indicate that jump tables go in the data section. */ -#define JUMP_TABLES_IN_TEXT_SECTION 1 +#define JUMP_TABLES_IN_TEXT_SECTION 0 /* Define any extra SPECS that the compiler needs to generate. */ #undef SUBTARGET_EXTRA_SPECS diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h index b2a7afabc73..440e0fde52b 100644 --- a/gcc/config/rs6000/linux64.h +++ b/gcc/config/rs6000/linux64.h @@ -237,9 +237,9 @@ extern int dot_symbols; #define TARGET_ALIGN_NATURAL 1 #endif -/* Indicate that jump tables go in the text section. */ +/* Indicate that jump tables go in the rodata or RELRO section. */ #undef JUMP_TABLES_IN_TEXT_SECTION -#define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT +#define JUMP_TABLES_IN_TEXT_SECTION 0 /* The linux ppc64 ABI isn't explicit on whether aggregates smaller than a doubleword should be padded upward or downward. You could diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index bc3ef0721a4..07f78d3a05b 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -4954,6 +4954,10 @@ rs6000_option_override_internal (bool global_init_p) warning (0, "%qs is deprecated and not recommended in any circumstances", "-mno-speculate-indirect-jumps"); + /* Enable absolute jump tables for AIX and Linux. */ + if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) + rs6000_relative_jumptables = 0; + return ret; } @@ -21419,6 +21423,16 @@ rs6000_xcoff_visibility (tree decl) enum symbol_visibility vis = DECL_VISIBILITY (decl); return visibility_types[vis]; } + +static section * +rs6000_xcoff_function_rodata_section (tree decl ATTRIBUTE_UNUSED, + bool relocatable) +{ + if (relocatable) + return data_section; + else + return readonly_data_section; +} #endif diff --git a/gcc/config/rs6000/xcoff.h b/gcc/config/rs6000/xcoff.h index cd0f99cb9c6..0dacd86eed9 100644 --- a/gcc/config/rs6000/xcoff.h +++ b/gcc/config/rs6000/xcoff.h @@ -98,7 +98,7 @@ #define TARGET_ASM_SELECT_SECTION rs6000_xcoff_select_section #define TARGET_ASM_SELECT_RTX_SECTION rs6000_xcoff_select_rtx_section #define TARGET_ASM_UNIQUE_SECTION rs6000_xcoff_unique_section -#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section +#define TARGET_ASM_FUNCTION_RODATA_SECTION rs6000_xcoff_function_rodata_section #define TARGET_STRIP_NAME_ENCODING rs6000_xcoff_strip_name_encoding #define TARGET_SECTION_TYPE_FLAGS rs6000_xcoff_section_type_flags #ifdef HAVE_AS_TLS diff --git a/gcc/testsuite/gcc.target/powerpc/absolute-jump-table-section.c b/gcc/testsuite/gcc.target/powerpc/absolute-jump-table-section.c new file mode 100644 index 00000000000..688a6f42836 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/absolute-jump-table-section.c @@ -0,0 +1,29 @@ +/* { dg-do compile { target { *-*-aix* || *-*-linux* } } } */ +/* { dg-options "-O2 -fPIC" } */ + +/* For Linux, the absolute jump tables are placed in .data.rel.ro.local. + For AIX, they're placed in data section. */ + +int a; + +int foo (char c) +{ + switch (c) { + case 'C': + return a; + case 'D': + return 3; + case 'A': + return 1; + case '%': + return -2; + case '#': + return a+4; + default: + return 100; + } +} + +/* { dg-final { scan-assembler "\\.section\[ \t\]\\.data\\.rel\\.ro\\.local" { target *-*-linux* } } } */ +/* { dg-final { scan-assembler-times "\\.csect \\.data" 2 { target *-*-aix* } } } */ +/* { dg-final { scan-assembler-times "\\.csect \\.text" 5 { target *-*-aix* } } } */