From patchwork Mon May 22 21:12:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 20538 Received: (qmail 130799 invoked by alias); 22 May 2017 21:12:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 130771 invoked by uid 89); 22 May 2017 21:12:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HK_RANDOM_ENVFROM, HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:D*cadence.com, Fill, circular X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-lf0-f67.google.com Received: from mail-lf0-f67.google.com (HELO mail-lf0-f67.google.com) (209.85.215.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 22 May 2017 21:12:48 +0000 Received: by mail-lf0-f67.google.com with SMTP id m18so6434103lfj.0; Mon, 22 May 2017 14:12:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hDR2c/nFE4t3oAz4xz1GA3fUvWEOiUjhYWaqZAzOJCE=; b=V4qpcMEDk8jo+PrWrCH+7liHOtyU3uAgOnTY8OzkH0FvZovkEWPL2pvXiBweuFQ5ol vXbd0c9grLw2PG/B/nm5itxEmkVq7cBRojsjfheghFGMauu3f6lP7KKECAkrkCygMW4j iCq+CZ0sGUvzIW6KFtLmTGoIeoQNFyaSDCOCw1zFKDgGC1Sdgz5TAWlsxbRKcRkjwvTy nqwM7GDfMgOkBpvQ3IFmvuFQ4KtCmMhUOR4LjDbq3LhqIIVHlVR7ePpXbBo1gAg0ulW5 pZVPp/6++aQ7ywIF2pIKS6wQZHAqw0sIsFpzKPWyWXLOfU5aqVKsKQhp4h0USaP+NPg5 ZCtw== X-Gm-Message-State: AODbwcDNwBmO/v3MduH9jXARVXW3AUNwtC6XmeDbM4/yI/2PfofaeUJW cCg+byqUTANglA== X-Received: by 10.46.5.82 with SMTP id 79mr7113980ljf.95.1495487570146; Mon, 22 May 2017 14:12:50 -0700 (PDT) Received: from octofox.metropolis ([5.19.183.212]) by smtp.gmail.com with ESMTPSA id a7sm3335749ljb.44.2017.05.22.14.12.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 May 2017 14:12:49 -0700 (PDT) From: Max Filippov To: binutils@sourceware.org, gdb-patches@sourceware.org Cc: Sterling Augustine , David Weatherford , Maxim Grigoriev , Woody LaRue , Max Filippov Subject: [RFC 1/5] xtensa: don't expect XCHAL_* macros to be constant Date: Mon, 22 May 2017 14:12:29 -0700 Message-Id: <1495487553-19078-2-git-send-email-jcmvbkbc@gmail.com> In-Reply-To: <1495487553-19078-1-git-send-email-jcmvbkbc@gmail.com> References: <1495487553-19078-1-git-send-email-jcmvbkbc@gmail.com> Get rid of the assumption that XCHAL_* macros are preprocessor constants: don't use them in preprocessor conditionals or in static variable initializers. 2017-05-22 Max Filippov bfd/ * elf32-xtensa.c (elf_xtensa_be_plt_entry, elf_xtensa_le_plt_entry): Add dimension for the ABI to arrays, keep both windowed and call0 ABI PLT definitions. (elf_xtensa_create_plt_entry): Use selected ABI to choose upper elf_xtensa_*_plt_entry endex. (ELF_MAXPAGESIZE): Fix at minimal supported MMU page size. gas/ * config/tc-xtensa.c (density_supported, xtensa_fetch_width, absolute_literals_supported): Leave definitions uninitialized. (directive_state): Leave entries for directive_density and directive_absolute_literals initialized to false. (xg_init_global_config, xtensa_init): New functions. * config/tc-xtensa.h (TARGET_BYTES_BIG_ENDIAN): Define as 0. (HOST_SPECIAL_INIT): New definition. (xtensa_init): New declaration. --- bfd/elf32-xtensa.c | 60 +++++++++++++++++++++++++++++--------------------- gas/config/tc-xtensa.c | 32 ++++++++++++++++++--------- gas/config/tc-xtensa.h | 9 +++++++- 3 files changed, 64 insertions(+), 37 deletions(-) diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index 80f50e3..078918f 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -519,28 +519,42 @@ elf_xtensa_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, invoked. Note: the 32-byte frame size used here cannot be changed without a corresponding change in the runtime linker. */ -static const bfd_byte elf_xtensa_be_plt_entry[PLT_ENTRY_SIZE] = +static const bfd_byte elf_xtensa_be_plt_entry[][PLT_ENTRY_SIZE] = { -#if XSHAL_ABI == XTHAL_ABI_WINDOWED - 0x6c, 0x10, 0x04, /* entry sp, 32 */ -#endif - 0x18, 0x00, 0x00, /* l32r a8, [got entry for rtld's resolver] */ - 0x1a, 0x00, 0x00, /* l32r a10, [got entry for rtld's link map] */ - 0x1b, 0x00, 0x00, /* l32r a11, [literal for reloc index] */ - 0x0a, 0x80, 0x00, /* jx a8 */ - 0 /* unused */ + { + 0x6c, 0x10, 0x04, /* entry sp, 32 */ + 0x18, 0x00, 0x00, /* l32r a8, [got entry for rtld's resolver] */ + 0x1a, 0x00, 0x00, /* l32r a10, [got entry for rtld's link map] */ + 0x1b, 0x00, 0x00, /* l32r a11, [literal for reloc index] */ + 0x0a, 0x80, 0x00, /* jx a8 */ + 0 /* unused */ + }, + { + 0x18, 0x00, 0x00, /* l32r a8, [got entry for rtld's resolver] */ + 0x1a, 0x00, 0x00, /* l32r a10, [got entry for rtld's link map] */ + 0x1b, 0x00, 0x00, /* l32r a11, [literal for reloc index] */ + 0x0a, 0x80, 0x00, /* jx a8 */ + 0 /* unused */ + } }; -static const bfd_byte elf_xtensa_le_plt_entry[PLT_ENTRY_SIZE] = +static const bfd_byte elf_xtensa_le_plt_entry[][PLT_ENTRY_SIZE] = { -#if XSHAL_ABI == XTHAL_ABI_WINDOWED - 0x36, 0x41, 0x00, /* entry sp, 32 */ -#endif - 0x81, 0x00, 0x00, /* l32r a8, [got entry for rtld's resolver] */ - 0xa1, 0x00, 0x00, /* l32r a10, [got entry for rtld's link map] */ - 0xb1, 0x00, 0x00, /* l32r a11, [literal for reloc index] */ - 0xa0, 0x08, 0x00, /* jx a8 */ - 0 /* unused */ + { + 0x36, 0x41, 0x00, /* entry sp, 32 */ + 0x81, 0x00, 0x00, /* l32r a8, [got entry for rtld's resolver] */ + 0xa1, 0x00, 0x00, /* l32r a10, [got entry for rtld's link map] */ + 0xb1, 0x00, 0x00, /* l32r a11, [literal for reloc index] */ + 0xa0, 0x08, 0x00, /* jx a8 */ + 0 /* unused */ + }, + { + 0x81, 0x00, 0x00, /* l32r a8, [got entry for rtld's resolver] */ + 0xa1, 0x00, 0x00, /* l32r a10, [got entry for rtld's link map] */ + 0xb1, 0x00, 0x00, /* l32r a11, [literal for reloc index] */ + 0xa0, 0x08, 0x00, /* jx a8 */ + 0 /* unused */ + } }; /* The size of the thread control block. */ @@ -2336,8 +2350,8 @@ elf_xtensa_create_plt_entry (struct bfd_link_info *info, /* Fill in the entry in the procedure linkage table. */ memcpy (splt->contents + code_offset, (bfd_big_endian (output_bfd) - ? elf_xtensa_be_plt_entry - : elf_xtensa_le_plt_entry), + ? elf_xtensa_be_plt_entry[XSHAL_ABI != XTHAL_ABI_WINDOWED] + : elf_xtensa_le_plt_entry[XSHAL_ABI != XTHAL_ABI_WINDOWED]), PLT_ENTRY_SIZE); abi_offset = XSHAL_ABI == XTHAL_ABI_WINDOWED ? 3 : 0; bfd_put_16 (output_bfd, l32r_offset (got_base + 0, @@ -11317,11 +11331,7 @@ static const struct bfd_elf_special_section elf_xtensa_special_sections[] = #define ELF_MACHINE_CODE EM_XTENSA #define ELF_MACHINE_ALT1 EM_XTENSA_OLD -#if XCHAL_HAVE_MMU -#define ELF_MAXPAGESIZE (1 << XCHAL_MMU_MIN_PTE_PAGE_SIZE) -#else /* !XCHAL_HAVE_MMU */ -#define ELF_MAXPAGESIZE 1 -#endif /* !XCHAL_HAVE_MMU */ +#define ELF_MAXPAGESIZE 0x1000 #endif /* ELF_ARCH */ #define elf_backend_can_gc_sections 1 diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c index bac7946..ed7ba0a 100644 --- a/gas/config/tc-xtensa.c +++ b/gas/config/tc-xtensa.c @@ -72,13 +72,13 @@ const char FLT_CHARS[] = "rRsSfFdDxXpP"; /* Flags to indicate whether the hardware supports the density and absolute literals options. */ -bfd_boolean density_supported = XCHAL_HAVE_DENSITY; -bfd_boolean absolute_literals_supported = XSHAL_USE_ABSOLUTE_LITERALS; +bfd_boolean density_supported; +bfd_boolean absolute_literals_supported; static vliw_insn cur_vinsn; unsigned xtensa_num_pipe_stages; -unsigned xtensa_fetch_width = XCHAL_INST_FETCH_WIDTH; +unsigned xtensa_fetch_width; static enum debug_info_type xt_saved_debug_type = DEBUG_NONE; @@ -419,21 +419,13 @@ bfd_boolean directive_state[] = { FALSE, /* none */ FALSE, /* literal */ -#if !XCHAL_HAVE_DENSITY FALSE, /* density */ -#else - TRUE, /* density */ -#endif TRUE, /* transform */ FALSE, /* freeregs */ FALSE, /* longcalls */ FALSE, /* literal_prefix */ FALSE, /* schedule */ -#if XSHAL_USE_ABSOLUTE_LITERALS - TRUE /* absolute_literals */ -#else FALSE /* absolute_literals */ -#endif }; /* A circular list of all potential and actual literal pool locations @@ -5216,6 +5208,24 @@ md_number_to_chars (char *buf, valueT val, int n) number_to_chars_littleendian (buf, val, n); } +static void +xg_init_global_config (void) +{ + target_big_endian = XCHAL_HAVE_BE; + + density_supported = XCHAL_HAVE_DENSITY; + absolute_literals_supported = XSHAL_USE_ABSOLUTE_LITERALS; + xtensa_fetch_width = XCHAL_INST_FETCH_WIDTH; + + directive_state[directive_density] = XCHAL_HAVE_DENSITY; + directive_state[directive_absolute_literals] = XSHAL_USE_ABSOLUTE_LITERALS; +} + +void +xtensa_init (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) +{ + xg_init_global_config (); +} /* This function is called once, at assembler startup time. It should set up all the tables, etc. that the MD part of the assembler will diff --git a/gas/config/tc-xtensa.h b/gas/config/tc-xtensa.h index 50e4640..69a5c8a 100644 --- a/gas/config/tc-xtensa.h +++ b/gas/config/tc-xtensa.h @@ -30,7 +30,7 @@ struct fix; #include "xtensa-isa.h" #include "xtensa-config.h" -#define TARGET_BYTES_BIG_ENDIAN XCHAL_HAVE_BE +#define TARGET_BYTES_BIG_ENDIAN 0 /* Maximum number of opcode slots in a VLIW instruction. */ @@ -335,6 +335,13 @@ extern bfd_boolean xtensa_check_inside_bundle (void); extern void xtensa_handle_align (fragS *); extern char *xtensa_section_rename (const char *); +/* We need to set the target endianness in xtensa_init and not in md_begin. + This is because xtensa_target_format is called before md_begin, and we + want to have all non-statically initialized fields initialized. */ + +#define HOST_SPECIAL_INIT xtensa_init +extern void xtensa_init (int, char **); + #define TARGET_FORMAT xtensa_target_format () #define TARGET_ARCH bfd_arch_xtensa #define TC_SEGMENT_INFO_TYPE xtensa_segment_info