From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106748 invoked by alias); 4 May 2019 07:57:33 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 106741 invoked by uid 89); 4 May 2019 07:57:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=sk:decode_, fini, HX-Spam-Relays-External:209.85.215.194, H*RU:209.85.215.194 X-HELO: mail-pg1-f194.google.com Received: from mail-pg1-f194.google.com (HELO mail-pg1-f194.google.com) (209.85.215.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 04 May 2019 07:57:31 +0000 Received: by mail-pg1-f194.google.com with SMTP id i21so3849783pgi.12 for ; Sat, 04 May 2019 00:57:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=NcH5b04xlIRQ1kQlw5hlkSHO1Ns4TJGha7PZzw7xw5Q=; b=kfhiu7hy0Pno6cGt9qJBEXXGNWgQhH9KaSbfRbfZFbcMzyiuS9kAyoAWKOsJTu/ZTA N3+CLx1vI3j1K0R/A50Oz2zw3GGqaVdF3Zu46iyijU/nvj9ljvKAnVCcmNd0zSxnQ6j/ bOHM7xViQbYwoniiFe8rD5JK1SqGRPjxGhjGavhdyYQ0pElIokaCMTbNMQz3yyhkTVmF SxfSeYnduCIp22SnLr+6isQCRDWAQ0h7O1M5rPXx+Oc67qDGkCNYPG6wHTrojdjPTepe 5XKsBvNgeTdpQzwuJJKm09bj3vzr4Bbe3xAZm0Jn8UBQdUWDxU0CMWYqimKYiZLEsWWD bypA== Return-Path: Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:7058:900e:4f9b:e26e]) by smtp.gmail.com with ESMTPSA id g128sm5913626pfb.131.2019.05.04.00.57.27 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 04 May 2019 00:57:28 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id E476C8A1CF; Sat, 4 May 2019 17:27:23 +0930 (ACST) Date: Sat, 04 May 2019 07:57:00 -0000 From: Alan Modra To: binutils@sourceware.org Subject: PR24511, nm should not mark symbols in .init_array as "t" Message-ID: <20190504075723.GJ3195@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-IsSubscribed: yes X-SW-Source: 2019-05/txt/msg00126.txt.bz2 This patch restricts the section names matched in coff_section_type, a function that translates section names to symbol type, and arranges to translate section flags to symbol type before looking at names. The latter change resulted in various test failures due to improper section flags being used in tests, and by the plugin support, so fix that too. The new test fails on many ELF targets that lack .init/fini_array in their scripts. I've just xfailed those. pru-elf oddly defines __init_array_begin rather than __init_array_start. I've left that target as a FAIL, and pj-elf too which reports an error for undefined weak symbols. bfd/ PR 24511 * syms.c (coff_section_type): Only allow '.', '$' and numeric following the standard section names. (bfd_decode_symclass): Prioritize section flag tests in decode_section_type before name tests in coff_section_type. * plugin.c (bfd_plugin_canonicalize_symtab): Init fake_section and fake_common_section using BFD_FAKE_SECTION. Use "fake" as their names and choose standard .text section flags for fake_section. ld/ PR 24511 * testsuite/ld-elf/pr14156a.d: Allow for .init/.fini being a data section on hppa64. * testsuite/ld-elf/pr14156b.d: Likewise. * testsuite/ld-scripts/pr18963.t: Map standard sections to set output section flags. * testsuite/ld-scripts/sane1.t: Likewise. * testsuite/ld-elf/init-fini-arrays.s: Reference __init_array_start and __fini_array_start. Define __start et al. * testsuite/ld-elf/pr24511.d: New test. diff --git a/bfd/plugin.c b/bfd/plugin.c index 8cb44ceb5d..376e92cdb3 100644 --- a/bfd/plugin.c +++ b/bfd/plugin.c @@ -530,13 +530,13 @@ bfd_plugin_canonicalize_symtab (bfd *abfd, struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data; long nsyms = plugin_data->nsyms; const struct ld_plugin_symbol *syms = plugin_data->syms; - static asection fake_section; - static asection fake_common_section; + static asection fake_section + = BFD_FAKE_SECTION (fake_section, NULL, "plug", 0, + SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS); + static asection fake_common_section + = BFD_FAKE_SECTION (fake_common_section, NULL, "plug", 0, SEC_IS_COMMON); int i; - fake_section.name = ".text"; - fake_common_section.flags = SEC_IS_COMMON; - for (i = 0; i < nsyms; i++) { asymbol *s = bfd_alloc (abfd, sizeof (asymbol)); diff --git a/bfd/syms.c b/bfd/syms.c index fe7e7dfac8..da1c90d52e 100644 --- a/bfd/syms.c +++ b/bfd/syms.c @@ -595,8 +595,9 @@ static const struct section_to_type stt[] = /* Return the single-character symbol type corresponding to section S, or '?' for an unknown COFF section. - Check for any leading string which matches, so .text5 returns - 't' as well as .text */ + Check for leading strings which match, followed by a number, '.', + or '$' so .text5 matches the .text entry, but .init_array doesn't + match the .init entry. */ static char coff_section_type (const char *s) @@ -604,8 +605,12 @@ coff_section_type (const char *s) const struct section_to_type *t; for (t = &stt[0]; t->section; t++) - if (!strncmp (s, t->section, strlen (t->section))) - return t->type; + { + size_t len = strlen (t->section); + if (strncmp (s, t->section, len) == 0 + && memchr (".$0123456789", s[len], 13) != 0) + return t->type; + } return '?'; } @@ -700,9 +705,9 @@ bfd_decode_symclass (asymbol *symbol) c = 'a'; else if (symbol->section) { - c = coff_section_type (symbol->section->name); + c = decode_section_type (symbol->section); if (c == '?') - c = decode_section_type (symbol->section); + c = coff_section_type (symbol->section->name); } else return '?'; diff --git a/ld/testsuite/ld-elf/init-fini-arrays.s b/ld/testsuite/ld-elf/init-fini-arrays.s index 6740ed6793..b8adc29a3c 100644 --- a/ld/testsuite/ld-elf/init-fini-arrays.s +++ b/ld/testsuite/ld-elf/init-fini-arrays.s @@ -1,7 +1,20 @@ .section .init_array.01000,"aw",%init_array .p2align 2 - .word 0 + .weak __init_array_start, ___init_array_start + .dc.a __init_array_start + .dc.a ___init_array_start .section .fini_array.01000,"aw",%fini_array .p2align 2 - .word 0 + .weak __fini_array_start, ___fini_array_start + .dc.a __fini_array_start + .dc.a ___fini_array_start + + .text + .globl main, _main, start, _start, __start +main: +_main: +start: +_start: +__start: + .dc.a 0 diff --git a/ld/testsuite/ld-elf/pr14156a.d b/ld/testsuite/ld-elf/pr14156a.d index cf38ee1016..535ac3e159 100644 --- a/ld/testsuite/ld-elf/pr14156a.d +++ b/ld/testsuite/ld-elf/pr14156a.d @@ -7,10 +7,10 @@ #nm: -n #... -[0-9a-f]+ T foo -[0-9a-f]+ t foo1 +[0-9a-f]+ [TD] foo +[0-9a-f]+ [td] foo1 #... -[0-9a-f]+ t foo2 -[0-9a-f]+ t foo3 -[0-9a-f]+ t last +[0-9a-f]+ [td] foo2 +[0-9a-f]+ [td] foo3 +[0-9a-f]+ [td] last #pass diff --git a/ld/testsuite/ld-elf/pr14156b.d b/ld/testsuite/ld-elf/pr14156b.d index f965f74e6e..27da0166f4 100644 --- a/ld/testsuite/ld-elf/pr14156b.d +++ b/ld/testsuite/ld-elf/pr14156b.d @@ -7,10 +7,10 @@ #nm: -n #... -[0-9a-f]+ T foo -[0-9a-f]+ t foo1 +[0-9a-f]+ [TD] foo +[0-9a-f]+ [td] foo1 #... -[0-9a-f]+ t foo2 -[0-9a-f]+ t foo3 -[0-9a-f]+ t last +[0-9a-f]+ [td] foo2 +[0-9a-f]+ [td] foo3 +[0-9a-f]+ [td] last #pass diff --git a/ld/testsuite/ld-elf/pr24511.d b/ld/testsuite/ld-elf/pr24511.d new file mode 100644 index 0000000000..f77a43b9e2 --- /dev/null +++ b/ld/testsuite/ld-elf/pr24511.d @@ -0,0 +1,18 @@ +#source: init-fini-arrays.s +#ld: +#nm: -n +# Most targets with their own scripts don't support init/fini_array and +# thus don't define __init/fini_array_start. +#xfail: avr-*-* cr16-*-* crx-*-* d10v-*-* d30v-*-* dlx-*-* ft32-*-* iq2000-*-* +#xfail: m68hc1*-*-* mep-*-* microblaze*-*-elf* s12z-*-* v850-*-* visium-*-* +#xfail: xgate-*-* xstormy*-*-* +# Some targets with their own scripts haven't kept up with elf.sc and +# PROVIDE __init_array_start rather than using PROVIDE_HIDDEN. These +# result in D symbols. rx-elf makes .init/fini_array SHF_EXECINSTR so +# gets t symbols. + +#... +[0-9a-f]+ [dDt] _?__init_array_start +#... +[0-9a-f]+ [dDt] _?__fini_array_start +#pass diff --git a/ld/testsuite/ld-scripts/pr18963.t b/ld/testsuite/ld-scripts/pr18963.t index b0cd7421eb..830ded78dd 100644 --- a/ld/testsuite/ld-scripts/pr18963.t +++ b/ld/testsuite/ld-scripts/pr18963.t @@ -5,16 +5,19 @@ SECTIONS .text : { _start = .; + *(.text) . = 0x10000; } B = .; .data : { + *(.data) . = 0x10000; } C = .; .bss : { + *(.bss) . = 0x10000; } D = A - C + B; diff --git a/ld/testsuite/ld-scripts/sane1.t b/ld/testsuite/ld-scripts/sane1.t index 037a62c856..90ee9b62d0 100644 --- a/ld/testsuite/ld-scripts/sane1.t +++ b/ld/testsuite/ld-scripts/sane1.t @@ -20,6 +20,7 @@ SECTIONS s4 = ABSOLUTE (d1) - 2; s5 = ABSOLUTE (d2) % 5; s6 = ABSOLUTE (d2) / 5; + *(.data) } /DISCARD/ : {*(*)} -- Alan Modra Australia Development Lab, IBM