From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa30.google.com (mail-vk1-xa30.google.com [IPv6:2607:f8b0:4864:20::a30]) by sourceware.org (Postfix) with ESMTPS id DEAD63858D37 for ; Wed, 2 Mar 2022 00:39:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DEAD63858D37 Received: by mail-vk1-xa30.google.com with SMTP id j12so108006vkr.0 for ; Tue, 01 Mar 2022 16:39:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1fWARE4/l44zFvEWIUfKpkHsNcPADQ9sX2h9qVAcfrk=; b=q08AwJrByC7fnua/T3deVru/jFulB9JiVkaTzTwKIBBPuXVwOeKkE8uxpwZgya6ukW Pjhi9l2ruhguBrEUexdopEGwmMtCfDCqaF4jldSB2Jxi+RRcIzqWj3HFq3xTmA8zWzla KE10CknRNyvBPOOR1b2YhvTqC+3ixw42Ed2X1RyF1NAaYSG1AxXGvpEfIhmjEoxV2Kpr z//1ytKYC2tWNKUw8o0v1qb8EZuNc65QqMKHLH98ZFnXYV4sPGzdZFy6K0XqtULE8wV5 k/83KObp7FRTCGEvQgF+pjqwMayBvhMdBEE1CGBZR8kG/6jVp8azGLHiua3UkKDmFXwu ZBzA== X-Gm-Message-State: AOAM53137n1/oNNP4kUtY5PE/9M3Hr47YeoJU20m0JhXNX0mcxzZYPMC wfujFbxDcUM7Wm1oLV90pmyPnqzUxPjudz/Qkqg2TEQYM44= X-Google-Smtp-Source: ABdhPJxb+5mpmhg3SNstPbK7QJg6IgMbmrAlXzxKr+6sgqhqWyAvp1lx0BoordE57royguO+/3TvxTV1Sfj6mm+3Vu4= X-Received: by 2002:a05:6122:985:b0:32d:a8d5:7b12 with SMTP id g5-20020a056122098500b0032da8d57b12mr11758591vkd.3.1646181547246; Tue, 01 Mar 2022 16:39:07 -0800 (PST) MIME-Version: 1.0 References: <3cfd526a-174b-5d09-6683-20a7fb002e04@linux.ibm.com> In-Reply-To: <3cfd526a-174b-5d09-6683-20a7fb002e04@linux.ibm.com> From: David Edelsohn Date: Tue, 1 Mar 2022 19:38:55 -0500 Message-ID: Subject: Re: [PATCH v3, rs6000] Enable absolute jump table for PPC AIX and Linux To: HAO CHEN GUI Cc: gcc-patches , Segher Boessenkool , Peter Bergner Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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-List-Received-Date: Wed, 02 Mar 2022 00:39:09 -0000 On Tue, Mar 1, 2022 at 12:41 AM HAO CHEN GUI wrote: > > 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. Hi, Haochen Thanks for working on this patch and for revising it. The patch looks okay now, but it is not appropriate for the current bug fixing stage in GCC development -- it needs to wait for GCC Stage 1 later this Spring. Also the current code uses the default readonly data section for the jump table. The new rs6000_xcoff_function_rodata_section follows the existing simple behavior, which is correct, but it should support named data sections instead of placing everything in the default ".data" section, similar to the default ELF code. I will work on that. Thanks, David > > 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* } } } */