From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by sourceware.org (Postfix) with ESMTPS id 6193A3851C2E for ; Wed, 23 Sep 2020 12:13:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6193A3851C2E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jozef.l@mittosystems.com Received: by mail-wm1-x341.google.com with SMTP id v12so5049113wmh.3 for ; Wed, 23 Sep 2020 05:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mittosystems.com; s=google; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=E1yIsEiIavKNGtA46z4botKiBX0AR7oa0yg6UCODyGM=; b=YK+aALuyNN+0SgbKk+QOMMEoXetTRwaTvBTwAjS9nnCAevpk9bHZEkv4Fi3GBFxINK RavlgfGXe0/ZjAqSvUP5fc1N9TBO1UK8Z3vrwlP4xdGVYKMPwt5BVHG8vpU0wwcErmQE WIUI0uT+7HTqrHvoKObwahWLtEap3IQV88a7NPoor4RdfxcSzaTPiNIilAanDuySxYp7 q73LcFSrtrhJ6Y03+TDUzo1D7e60W/5RTDdWpsQrlmNTqOskxGMJhXFzkH1jBahfUWcG DvwuBwB+GEHeAj2umCEA1SWTWRw9/JWfBx3j4ZxYuBW3kAl5EOekqUIMIsHOZikdYJZs Yi2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to; bh=E1yIsEiIavKNGtA46z4botKiBX0AR7oa0yg6UCODyGM=; b=WiiBbp7LrBesabVXO3i5obbTpXsmSu6t3XYE5VJwwJ7thZs8arECKRIq6/SWy166uY jYThkLsVKPa1HNdjib2Pc5VeHBE3eGBKQ1tliu0xI56B0UJOphIaxD8PVElAaaPjBOOT jpniDArthJfHc1PQri4/IkSIaxnUJtdxnUHQ+KqRUrWg2zj3N7Dq1T73qYc3jKxBowGl 1xPJNU6eUdH2I+6DwSEw9p57gdrwh4AlnTOPfgpVPX1rz1X0i5tonSdVQMFcqWR4mS1i r5IjekgxdxfB1VpYsCBU7woqWBYTDOGHZ0lm4hNcNEHpAbdpxWGLX8ux+K+7kGKWoqB8 S5Aw== X-Gm-Message-State: AOAM532BkrMZ8pDgVi4gJ+uxHoCad/eGDJe8ROJSGVUGiS9yavRdRVwp 2FViuZwBFVo/8nz0Dq/wJNlgrf3E5Qiq0w== X-Google-Smtp-Source: ABdhPJzNrB4Heibyb8mFQgnQ+klQA9p5XL0I3VZFoR06D5lSa70PxUjEGab6PHxRLHQDXG6JLYR18Q== X-Received: by 2002:a1c:1f08:: with SMTP id f8mr6168708wmf.168.1600863231053; Wed, 23 Sep 2020 05:13:51 -0700 (PDT) Received: from jozef-acer-manjaro ([2a01:4b00:87fd:900:5e1d:5c99:56da:76e8]) by smtp.gmail.com with ESMTPSA id n66sm8401507wmb.35.2020.09.23.05.13.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2020 05:13:50 -0700 (PDT) Date: Wed, 23 Sep 2020 13:13:48 +0100 From: Jozef Lawrynowicz To: binutils@sourceware.org Subject: Re: [PATCH] Support SHF_GNU_RETAIN ELF section flag Message-ID: <20200923121348.pqctgecqglc7m527@jozef-acer-manjaro> Mail-Followup-To: binutils@sourceware.org References: <20200922202933.kgflmtnwzkdrmrvs@jozef-acer-manjaro> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="jns2lvdupg436zxj" Content-Disposition: inline In-Reply-To: <20200922202933.kgflmtnwzkdrmrvs@jozef-acer-manjaro> X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Sep 2020 12:13:57 -0000 --jns2lvdupg436zxj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Attached a revised patch: - Removed mmix-*-* XFAILs - Fixed SHF_GNU_RETAIN being clobbered when using the .section directive without the "R" flag, after the section has previously been marked with SHF_GNU_RETAIN. Added tests for this behavior. Thanks, Jozef On Tue, Sep 22, 2020 at 09:29:33PM +0100, Jozef Lawrynowicz wrote: > The attached patch adds support for the new SHF_GNU_RETAIN ELF section > flag, which was discussed on the GNU gABI mailing list here: > https://sourceware.org/pipermail/gnu-gabi/2020q3/000429.html > > The flag is GNU-specific so uses a bit in the SHF_MASKOS mask. > Its precise definition is as follows: > > ======================================================================= > Section Attribute Flags > +-------------------------------------+ > | Name | Value | > +-------------------------------------+ > | SHF_GNU_RETAIN | 0x200000 (1 << 21) | > +-------------------------------------+ > > SHF_GNU_RETAIN > The link editor should not garbage collect the section if it is > unused. > > ======================================================================= > > The overall intention for this new flag is to enable a new "retain" > attribute to be applied to declarations of functions and data in the > source code. This attribute can be used to ensure the definition > associated with the declaration is present in the linked output file, > even if linker garbage collection would normally remove the containing > section because it is unused. > > The new ".retain" assembler directive can be used to apply > SHF_GNU_RETAIN to a section. GCC will emit this directive when > assembling definitions of functions and data that have had the "retain" > attribute applied. > > Note that there is *not* a direct mapping of SHF_GNU_RETAIN to the BFD > section flag SEC_KEEP. SEC_KEEP would prevent the user being able to > explicitly remove an SHF_GNU_RETAIN section by placing it in /DISCARD/, > which could be necessary in some situations. > > I successfully regtested the patch for the Binutils, GAS and LD > testsuites for the following CPUs, applying the "-elf" suffix when > configuring: > aarch64 alpha arc arm avr bfin bpf cr16 cris crx csky d10v d30v dlx > epiphany fr30 frv ft32 h8300 hppa i386 ia64 ia64-vms ip2k iq2000 lm32 > m32c m32r m68hc11 m68hc12 m68k mcore mep metag microblaze mips mmix > moxie msp430 mt nds32 nfp nios2 or1k pj ppc pru riscv rl78 rx s12z > s390 score sh sparc spu tic6x tilegx tilepro v850 vax visium wasm32 > x86-64 x86 xc16x xgate xstormy16 xtensa z80 > > The new tests are passing for all targets except mmix-elf. This target > has a lot of LD failures, particularly --gc-sections doesn't appear to > have any effect. I don't know anything about the target, but I wonder if > it should be added to the hard-coded list of targets that doesn't > support --gc-sections. I have therefore XFAIL'd the new LD tests for > this target. > > I also regtested for i386-pe, to ensure there was no spill-over of the > new functionality into any non-ELF areas. > > Ok to apply? > > Thanks, > Jozef --jns2lvdupg436zxj Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Support-SHF_GNU_RETAIN-ELF-section-flag.patch" >From 862a04415e1b490b4561fe5a44c9fa4120c50825 Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Tue, 22 Sep 2020 21:00:35 +0100 Subject: [PATCH] Support SHF_GNU_RETAIN ELF section flag The GNU-specific SHF_GNU_RETAIN ELF section flag is defined as follows: ======================================================================= Section Attribute Flags +-------------------------------------+ | Name | Value | +-------------------------------------+ | SHF_GNU_RETAIN | 0x200000 (1 << 21) | +-------------------------------------+ SHF_GNU_RETAIN The link editor should not garbage collect the section if it is unused. ======================================================================= The new ".retain" assembler directive can be used to apply SHF_GNU_RETAIN to a section. Note that there is not a direct mapping of SHF_GNU_RETAIN to the BFD section flag SEC_KEEP. SEC_KEEP would prevent the user being able to explicitly remove an SHF_GNU_RETAIN section by placing it in /DISCARD/. bfd/ChangeLog: 2020-09-22 Jozef Lawrynowicz * elflink.c (bfd_elf_gc_sections): gc_mark the section if SHF_GNU_RETAIN is set. binutils/ChangeLog: 2020-09-22 Jozef Lawrynowicz * NEWS: Announce SHF_GNU_RETAIN. * readelf.c (get_elf_section_flags): Handle SHF_GNU_RETAIN. * testsuite/binutils-all/readelf.exp: Run new test. Don't run run_dump_test when there isn't an assembler available. * testsuite/binutils-all/retain1.d: New test. * testsuite/binutils-all/retain1.s: New test. gas/ChangeLog: 2020-09-22 Jozef Lawrynowicz * NEWS: Announce .retain directive and SHF_GNU_RETAIN. * config/obj-elf.c (elf_pseudo_table): Add "retain". (obj_elf_retain): New. (obj_elf_parse_section_letters): Handle 'R' flag. * doc/as.texi: Document .retain directive. (Section): Document 'R' flag. * testsuite/gas/elf/elf.exp: Run new tests. * testsuite/gas/elf/retain1.d: New test. * testsuite/gas/elf/retain1.s: New test. * testsuite/gas/elf/retain2.d: New test. * testsuite/gas/elf/retain2.l: New test. * testsuite/gas/elf/retain2.s: New test. * testsuite/gas/elf/retain3.d: New test. * testsuite/gas/elf/retain3.s: New test. * testsuite/gas/elf/section10.d: Adjust test. include/ChangeLog: 2020-09-22 Jozef Lawrynowicz * elf/common.h (SHF_GNU_RETAIN): Define. ld/ChangeLog: 2020-09-22 Jozef Lawrynowicz * NEWS: Announce SHF_GNU_RETAIN. * ld.texi (garbage collection): Document SHF_GNU_RETAIN. (Output Section Discarding): Likewise. * testsuite/ld-elf/elf.exp: Run new tests. * testsuite/ld-elf/retain1.msg: New test. * testsuite/ld-elf/retain1.s: New test. * testsuite/ld-elf/retain2.d: New test. * testsuite/ld-elf/retain2.ld: New test. * testsuite/ld-elf/retain2.map: New test. * testsuite/ld-elf/retain3.msg: New test. * testsuite/ld-elf/retain3.s: New test. * testsuite/ld-elf/retain4.s: New test. * testsuite/ld-elf/retain5.s: New test. * testsuite/ld-elf/retain6lib.s: New test. * testsuite/ld-elf/retain6main.s: New test. * testsuite/ld-elf/retain7.msg: New test. * testsuite/ld-elf/retain7lib.s: New test. * testsuite/ld-elf/retain7main.s: New test. --- bfd/elflink.c | 3 +- binutils/NEWS | 4 + binutils/readelf.c | 4 + binutils/testsuite/binutils-all/readelf.exp | 6 +- binutils/testsuite/binutils-all/retain1.d | 17 +++ binutils/testsuite/binutils-all/retain1.s | 114 ++++++++++++++++++++ gas/NEWS | 4 + gas/config/obj-elf.c | 71 +++++++++++- gas/doc/as.texi | 20 ++++ gas/testsuite/gas/elf/elf.exp | 7 ++ gas/testsuite/gas/elf/retain1.d | 24 +++++ gas/testsuite/gas/elf/retain1.s | 114 ++++++++++++++++++++ gas/testsuite/gas/elf/retain2.d | 3 + gas/testsuite/gas/elf/retain2.l | 3 + gas/testsuite/gas/elf/retain2.s | 7 ++ gas/testsuite/gas/elf/retain3.d | 24 +++++ gas/testsuite/gas/elf/retain3.s | 104 ++++++++++++++++++ gas/testsuite/gas/elf/retain4.d | 6 ++ gas/testsuite/gas/elf/retain4.s | 20 ++++ gas/testsuite/gas/elf/retain5.d | 6 ++ gas/testsuite/gas/elf/retain5.s | 18 ++++ gas/testsuite/gas/elf/section10.d | 4 +- include/elf/common.h | 1 + ld/NEWS | 4 + ld/ld.texi | 8 ++ ld/testsuite/ld-elf/elf.exp | 33 ++++++ ld/testsuite/ld-elf/retain1.msg | 9 ++ ld/testsuite/ld-elf/retain1.s | 114 ++++++++++++++++++++ ld/testsuite/ld-elf/retain2.d | 6 ++ ld/testsuite/ld-elf/retain2.ld | 7 ++ ld/testsuite/ld-elf/retain2.map | 32 ++++++ ld/testsuite/ld-elf/retain3.msg | 9 ++ ld/testsuite/ld-elf/retain3.s | 104 ++++++++++++++++++ ld/testsuite/ld-elf/retain4.s | 19 ++++ ld/testsuite/ld-elf/retain5.s | 13 +++ ld/testsuite/ld-elf/retain6lib.s | 6 ++ ld/testsuite/ld-elf/retain6main.s | 5 + ld/testsuite/ld-elf/retain7.msg | 1 + ld/testsuite/ld-elf/retain7lib.s | 17 +++ ld/testsuite/ld-elf/retain7main.s | 13 +++ 40 files changed, 977 insertions(+), 7 deletions(-) create mode 100644 binutils/testsuite/binutils-all/retain1.d create mode 100644 binutils/testsuite/binutils-all/retain1.s create mode 100644 gas/testsuite/gas/elf/retain1.d create mode 100644 gas/testsuite/gas/elf/retain1.s create mode 100644 gas/testsuite/gas/elf/retain2.d create mode 100644 gas/testsuite/gas/elf/retain2.l create mode 100644 gas/testsuite/gas/elf/retain2.s create mode 100644 gas/testsuite/gas/elf/retain3.d create mode 100644 gas/testsuite/gas/elf/retain3.s create mode 100644 gas/testsuite/gas/elf/retain4.d create mode 100644 gas/testsuite/gas/elf/retain4.s create mode 100644 gas/testsuite/gas/elf/retain5.d create mode 100644 gas/testsuite/gas/elf/retain5.s create mode 100644 ld/testsuite/ld-elf/retain1.msg create mode 100644 ld/testsuite/ld-elf/retain1.s create mode 100644 ld/testsuite/ld-elf/retain2.d create mode 100644 ld/testsuite/ld-elf/retain2.ld create mode 100644 ld/testsuite/ld-elf/retain2.map create mode 100644 ld/testsuite/ld-elf/retain3.msg create mode 100644 ld/testsuite/ld-elf/retain3.s create mode 100644 ld/testsuite/ld-elf/retain4.s create mode 100644 ld/testsuite/ld-elf/retain5.s create mode 100644 ld/testsuite/ld-elf/retain6lib.s create mode 100644 ld/testsuite/ld-elf/retain6main.s create mode 100644 ld/testsuite/ld-elf/retain7.msg create mode 100644 ld/testsuite/ld-elf/retain7lib.s create mode 100644 ld/testsuite/ld-elf/retain7main.s diff --git a/bfd/elflink.c b/bfd/elflink.c index 0e339f3c1e..6d1a1c5105 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -13977,7 +13977,8 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info) || (elf_section_data (o)->this_hdr.sh_type == SHT_FINI_ARRAY))) || (elf_section_data (o)->this_hdr.sh_type == SHT_NOTE - && elf_next_in_group (o) == NULL ))) + && elf_next_in_group (o) == NULL) + || (elf_section_flags (o) & SHF_GNU_RETAIN))) { if (!_bfd_elf_gc_mark (info, o, gc_mark_hook)) return FALSE; diff --git a/binutils/NEWS b/binutils/NEWS index c0dc73d7d8..6c7d3f3953 100644 --- a/binutils/NEWS +++ b/binutils/NEWS @@ -4,6 +4,10 @@ symbol names. In addition the --demangle=