From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106442 invoked by alias); 1 Aug 2016 09:42:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 106431 invoked by uid 89); 1 Aug 2016 09:42:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=1,26, 0x10000, AVR, Track X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.218) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 01 Aug 2016 09:42:38 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwR/bcHRirORRW3yMcVao= X-RZG-CLASS-ID: mo00 Received: from [192.168.0.123] (mail.hightec-rt.com [213.135.1.215]) by smtp.strato.de (RZmta 38.13 DYNA|AUTH) with ESMTPSA id j0b0e9s719gX8r5 (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 1 Aug 2016 11:42:33 +0200 (CEST) Subject: [avr,backported,6] Fix PR 71151 References: <87y46m1h3y.fsf@atmel.com> <5751B5EA.5000108@gjlay.de> <877fe1nrdy.fsf@atmel.com> <87lh258ufn.fsf@atmel.com> Cc: Denis Chertykov , Senthil Kumar Selvaraj To: gcc-patches@gcc.gnu.org From: Georg-Johann Lay Message-ID: <4331d3f4-2c59-8355-1e6f-d760830b4922@gjlay.de> Date: Mon, 01 Aug 2016 09:42:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------BAD6AC8CE3F83D5102789931" X-IsSubscribed: yes X-SW-Source: 2016-08/txt/msg00029.txt.bz2 This is a multi-part message in MIME format. --------------BAD6AC8CE3F83D5102789931 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1056 Applied the simple fix for PR71151: Set JUMP_TABLES_IN_TEXT_SECTION to 1. https://gcc.gnu.org/r238935 Johann gcc/ Backport from 2016-06-16 trunk r237536. 2016-06-16 Senthil Kumar Selvaraj PR target/71151 * config/avr/avr.c (avr_asm_init_sections): Remove setup of progmem_swtable_section. (progmem_swtable_section): Remove. (avr_asm_function_rodata_section): Remove. (TARGET_ASM_FUNCTION_RODATA_SECTION): Remove. * config/avr/avr.h (JUMP_TABLES_IN_TEXT_SECTION): Define to 1. testsuite/ Backport from 2016-06-16 trunk r237536, r237910. 2016-06-16 Senthil Kumar Selvaraj PR target/71151 * gcc.target/avr/pr71151-1.c: New test. * gcc.target/avr/pr71151-2.c: New test. * gcc.target/avr/pr71151-3.c: New test. * gcc.target/avr/pr71151-4.c: New test. * gcc.target/avr/pr71151-5.c: New test. * gcc.target/avr/pr71151-6.c: New test. * gcc.target/avr/pr71151-7.c: New test. * gcc.target/avr/pr71151-8.c: New test. * gcc.target/avr/pr71151-common.h: New file. --------------BAD6AC8CE3F83D5102789931 Content-Type: text/x-patch; name="pr71151-v6.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pr71151-v6.diff" Content-length: 12148 Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (revision 238934) +++ config/avr/avr.c (working copy) @@ -203,9 +203,6 @@ static GTY(()) rtx xstring_e; /* Current architecture. */ const avr_arch_t *avr_arch; -/* Section to put switch tables in. */ -static GTY(()) section *progmem_swtable_section; - /* Unnamed sections associated to __attribute__((progmem)) aka. PROGMEM or to address space __flash* or __memx. Only used as singletons inside avr_asm_select_section, but it must not be local there because of GTY. */ @@ -9461,24 +9458,6 @@ avr_output_progmem_section_asm_op (const static void avr_asm_init_sections (void) { - /* Set up a section for jump tables. Alignment is handled by - ASM_OUTPUT_BEFORE_CASE_LABEL. */ - - if (AVR_HAVE_JMP_CALL) - { - progmem_swtable_section - = get_unnamed_section (0, output_section_asm_op, - "\t.section\t.progmem.gcc_sw_table" - ",\"a\",@progbits"); - } - else - { - progmem_swtable_section - = get_unnamed_section (SECTION_CODE, output_section_asm_op, - "\t.section\t.progmem.gcc_sw_table" - ",\"ax\",@progbits"); - } - /* Override section callbacks to keep track of `avr_need_clear_bss_p' resp. `avr_need_copy_data_p'. */ @@ -9488,65 +9467,6 @@ avr_asm_init_sections (void) } -/* Implement `TARGET_ASM_FUNCTION_RODATA_SECTION'. */ - -static section* -avr_asm_function_rodata_section (tree decl) -{ - /* If a function is unused and optimized out by -ffunction-sections - and --gc-sections, ensure that the same will happen for its jump - tables by putting them into individual sections. */ - - unsigned int flags; - section * frodata; - - /* Get the frodata section from the default function in varasm.c - but treat function-associated data-like jump tables as code - rather than as user defined data. AVR has no constant pools. */ - { - int fdata = flag_data_sections; - - flag_data_sections = flag_function_sections; - frodata = default_function_rodata_section (decl); - flag_data_sections = fdata; - flags = frodata->common.flags; - } - - if (frodata != readonly_data_section - && flags & SECTION_NAMED) - { - /* Adjust section flags and replace section name prefix. */ - - unsigned int i; - - static const char* const prefix[] = - { - ".rodata", ".progmem.gcc_sw_table", - ".gnu.linkonce.r.", ".gnu.linkonce.t." - }; - - for (i = 0; i < sizeof (prefix) / sizeof (*prefix); i += 2) - { - const char * old_prefix = prefix[i]; - const char * new_prefix = prefix[i+1]; - const char * name = frodata->named.name; - - if (STR_PREFIX_P (name, old_prefix)) - { - const char *rname = ACONCAT ((new_prefix, - name + strlen (old_prefix), NULL)); - flags &= ~SECTION_CODE; - flags |= AVR_HAVE_JMP_CALL ? 0 : SECTION_CODE; - - return get_section (rname, flags, frodata->named.decl); - } - } - } - - return progmem_swtable_section; -} - - /* Implement `TARGET_ASM_NAMED_SECTION'. */ /* Track need of __do_clear_bss, __do_copy_data for named sections. */ @@ -13749,9 +13669,6 @@ avr_fold_builtin (tree fndecl, int n_arg #undef TARGET_FOLD_BUILTIN #define TARGET_FOLD_BUILTIN avr_fold_builtin -#undef TARGET_ASM_FUNCTION_RODATA_SECTION -#define TARGET_ASM_FUNCTION_RODATA_SECTION avr_asm_function_rodata_section - #undef TARGET_SCALAR_MODE_SUPPORTED_P #define TARGET_SCALAR_MODE_SUPPORTED_P avr_scalar_mode_supported_p Index: config/avr/avr.h =================================================================== --- config/avr/avr.h (revision 238934) +++ config/avr/avr.h (working copy) @@ -391,7 +391,7 @@ typedef struct avr_args #define SUPPORTS_INIT_PRIORITY 0 -#define JUMP_TABLES_IN_TEXT_SECTION 0 +#define JUMP_TABLES_IN_TEXT_SECTION 1 #define ASM_COMMENT_START " ; " Index: testsuite/gcc.target/avr/pr71151-1.c =================================================================== --- testsuite/gcc.target/avr/pr71151-1.c (nonexistent) +++ testsuite/gcc.target/avr/pr71151-1.c (working copy) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-Os -ffunction-sections -fdata-sections" } */ + +/* { dg-final { scan-assembler-not ".section .progmem.gcc_sw_table.foo.str1.1" } } */ +/* { dg-final { scan-assembler ".section .rodata.foo.str1.1,\"aMS\"" } } */ + + +extern void bar(const char*); +void foo(void) +{ + bar("BBBBBBBBBB"); +} Index: testsuite/gcc.target/avr/pr71151-2.c =================================================================== --- testsuite/gcc.target/avr/pr71151-2.c (nonexistent) +++ testsuite/gcc.target/avr/pr71151-2.c (working copy) @@ -0,0 +1,26 @@ +/* { dg-do run } */ +/* { dg-options "-Os -fno-tree-switch-conversion -ffunction-sections -fdata-sections" } */ + +/* Make sure jumptables work properly if placed below 64 KB i.e. 2 byte + flash address for loading jump table entry, 2 byte entry, after + removing the special section placement hook. */ + +#define SECTION_NAME ".foo" + +#include "exit-abort.h" +#include "pr71151-common.h" + +int main() +{ + foo(5); + if (y != 37) + abort(); + + foo(0); + if (y != 67) + abort(); + + foo(7); + if (y != 98) + abort(); +} Index: testsuite/gcc.target/avr/pr71151-3.c =================================================================== --- testsuite/gcc.target/avr/pr71151-3.c (nonexistent) +++ testsuite/gcc.target/avr/pr71151-3.c (working copy) @@ -0,0 +1,32 @@ +/* { dg-do run } */ +/* { dg-options "-Os -fno-tree-switch-conversion -ffunction-sections -mno-relax -fdata-sections -Wl,--section-start=.foo=0x10000" } */ + +#ifdef __AVR_HAVE_ELPM__ +/* Make sure jumptables work properly if placed above 64 KB and below 128 KB, + i.e. 3 byte flash address for loading jump table entry and 2 byte jump table + entry, with relaxation disabled, after removing the special section + placement hook. */ +#define SECTION_NAME ".foo" +#else +/* No special jump table placement so that avrtest won't abort + for, e.g. ATmega64. */ +#define SECTION_NAME ".text.foo" +#endif + +#include "exit-abort.h" +#include "pr71151-common.h" + +int main() +{ + foo(5); + if (y != 37) + abort(); + + foo(0); + if (y != 67) + abort(); + + foo(7); + if (y != 98) + abort(); +} Index: testsuite/gcc.target/avr/pr71151-4.c =================================================================== --- testsuite/gcc.target/avr/pr71151-4.c (nonexistent) +++ testsuite/gcc.target/avr/pr71151-4.c (working copy) @@ -0,0 +1,32 @@ +/* { dg-do run } */ +/* { dg-options "-Os -fno-tree-switch-conversion -ffunction-sections -fdata-sections -mrelax -Wl,--section-start=.foo=0x10000" } */ + +#ifdef __AVR_HAVE_ELPM__ +/* Make sure jumptables work properly if placed above 64 KB and below 128 KB, + i.e. 3 byte flash address for loading jump table entry and 2 byte jump + table entry, with relaxation enabled, after removing the special section + placement hook. */ +#define SECTION_NAME ".foo" +#else +/* No special jump table placement so that avrtest won't abort + for, e.g. ATmega64. */ +#define SECTION_NAME ".text.foo" +#endif + +#include "exit-abort.h" +#include "pr71151-common.h" + +int main() +{ + foo(5); + if (y != 37) + abort(); + + foo(0); + if (y != 67) + abort(); + + foo(7); + if (y != 98) + abort(); +} Index: testsuite/gcc.target/avr/pr71151-5.c =================================================================== --- testsuite/gcc.target/avr/pr71151-5.c (nonexistent) +++ testsuite/gcc.target/avr/pr71151-5.c (working copy) @@ -0,0 +1,32 @@ +/* { dg-do run } */ +/* { dg-options "-Os -fno-tree-switch-conversion -ffunction-sections -fdata-sections -mno-relax -Wl,--section-start=.foo=0x20000" } */ + +#ifdef __AVR_3_BYTE_PC__ +/* Make sure jumptables work properly if placed above 128 KB, i.e. 3 byte + flash address for loading jump table entry and a jump table entry + that is a stub, with relaxation disabled, after removing the special + section placement hook. */ +#define SECTION_NAME ".foo" +#else +/* No special jump table placement so that avrtest won't abort + for, e.g. ATmega128. */ +#define SECTION_NAME ".text.foo" +#endif + +#include "exit-abort.h" +#include "pr71151-common.h" + +int main() +{ + foo(5); + if (y != 37) + abort(); + + foo(0); + if (y != 67) + abort(); + + foo(7); + if (y != 98) + abort(); +} Index: testsuite/gcc.target/avr/pr71151-6.c =================================================================== --- testsuite/gcc.target/avr/pr71151-6.c (nonexistent) +++ testsuite/gcc.target/avr/pr71151-6.c (working copy) @@ -0,0 +1,32 @@ +/* { dg-do run } */ +/* { dg-options "-Os -fno-tree-switch-conversion -ffunction-sections -fdata-sections -mrelax -Wl,--section-start=.foo=0x20000" } */ + +#ifdef __AVR_3_BYTE_PC__ +/* Make sure jumptables work properly if placed above 128 KB, i.e. 3 byte + flash address for loading jump table entry and a jump table entry + that is a stub, with relaxation enabled, after removing the special + section placement hook. */ +#define SECTION_NAME ".foo" +#else +/* No special jump table placement so that avrtest won't abort + for, e.g. ATmega128. */ +#define SECTION_NAME ".text.foo" +#endif + +#include "exit-abort.h" +#include "pr71151-common.h" + +int main() +{ + foo(5); + if (y != 37) + abort(); + + foo(0); + if (y != 67) + abort(); + + foo(7); + if (y != 98) + abort(); +} Index: testsuite/gcc.target/avr/pr71151-7.c =================================================================== --- testsuite/gcc.target/avr/pr71151-7.c (nonexistent) +++ testsuite/gcc.target/avr/pr71151-7.c (working copy) @@ -0,0 +1,30 @@ +/* { dg-do run } */ +/* { dg-options "-Os -fno-tree-switch-conversion -ffunction-sections -fdata-sections -mno-relax -Wl,--section-start=.foo=0x1fffa" } */ + +#ifdef __AVR_3_BYTE_PC__ +/* Make sure jumptables work properly if placed straddling 128 KB i.e + some entries below 128 KB and some above it, with relaxation disabled. */ +#define SECTION_NAME ".foo" +#else +/* No special jump table placement so that avrtest won't abort + for, e.g. ATmega128. */ +#define SECTION_NAME ".text.foo" +#endif + +#include "exit-abort.h" +#include "pr71151-common.h" + +int main() +{ + foo(5); + if (y != 37) + abort(); + + foo(0); + if (y != 67) + abort(); + + foo(7); + if (y != 98) + abort(); +} Index: testsuite/gcc.target/avr/pr71151-8.c =================================================================== --- testsuite/gcc.target/avr/pr71151-8.c (nonexistent) +++ testsuite/gcc.target/avr/pr71151-8.c (working copy) @@ -0,0 +1,29 @@ +/* { dg-do run } */ +/* { dg-options "-Os -fno-tree-switch-conversion -ffunction-sections -fdata-sections -mrelax -Wl,--section-start=.foo=0x1fffa" } */ + +#ifdef __AVR_3_BYTE_PC__ +/* Make sure jumptables work properly if placed straddling 128 KB i.e + some entries below 128 KB and some above it, with relaxation disabled. */ +#define SECTION_NAME ".foo" +#else +/* No special jump table placement so that avrtest won't abort. */ +#define SECTION_NAME ".text.foo" +#endif + +#include "exit-abort.h" +#include "pr71151-common.h" + +int main() +{ + foo(5); + if (y != 37) + abort(); + + foo(0); + if (y != 67) + abort(); + + foo(7); + if (y != 98) + abort(); +} Index: testsuite/gcc.target/avr/pr71151-common.h =================================================================== --- testsuite/gcc.target/avr/pr71151-common.h (nonexistent) +++ testsuite/gcc.target/avr/pr71151-common.h (working copy) @@ -0,0 +1,27 @@ +volatile char y; +volatile char g; + +__attribute__((section(SECTION_NAME))) +void foo(char x) +{ + switch (x) + { + case 0: + y = 67; break; + case 1: + y = 20; break; + case 2: + y = 109; break; + case 3: + y = 33; break; + case 4: + y = 44; break; + case 5: + y = 37; break; + case 6: + y = 10; break; + case 7: + y = 98; break; + } + y = y + g; +} --------------BAD6AC8CE3F83D5102789931--