From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id EB119385780B for ; Tue, 22 Sep 2020 20:29:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EB119385780B 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-wr1-x436.google.com with SMTP id w5so18527856wrp.8 for ; Tue, 22 Sep 2020 13:29:36 -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:mime-version :content-disposition; bh=R6bOZiCHQqWxzraCurpQNCp4emQAWwX3EqN1ui3IAoQ=; b=UqADMe83SN9tP18YK0td+O3py45NTh8sf++gyqGlIRDKg37l1otdEcwHm8QK/G3f4g TonSQy8ekpy1iY/nzt5ucs6R7MVxWbxUBGkN6T8I3CgAE+OwnQV5b2PJTF+16YBif14B mSYY4d36rCgbT3lpc9hqsQQIJvt6TlBly4S3hx4q8Zhz6fRwShv3SleD2anmx02Eq7h4 WqLvR4i7Lrp8h/OKDZCgbahz+t9agJ6IatC5dolXjDQ4qFJUI2gawy6GlzM7MuhcCES2 YMDGsKa5mmMpwf2Yi2uWCmh5KtwQA3VoK4GJuHnPX89Ep7AgKZ9WbcsHBFmoHLFtCPTw MJyg== 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 :mime-version:content-disposition; bh=R6bOZiCHQqWxzraCurpQNCp4emQAWwX3EqN1ui3IAoQ=; b=tglt01tfYbqtXQRuQQs9yToc5B3y2Z3OtF8nV5qoNLTX3d7ZZoRKUNZbafFIAkdBvR lG6cFd2ct3UOhpl034T169CVgk1njhojRK888MM/cDWjTttv+IverRiJGi19TFl3wwbL r7pgadfZklsQ3/ktz+gFQsgCzc4uo8K9FI2SouD16B1eTFicIY6R7EtmG6D3pkGEany7 chPDeAWqVRwalXNd8LtHZJLRMCNj3zK5+fShWwsYW4jfTzGaAsDTXzb1H+Re1PIkc/bD jKmBc6lEwDbliHxLwL5OeRDGcjpv7k/UHnwp+hTq35yv4498/fnss2m0VsAkY2j66I3M WG+g== X-Gm-Message-State: AOAM533x55uQYszN+MNG5wCW8rkz6Aro04CpGzvL5UDCVwXBqPvk6HwK PTVF1iDytNmOzWr2eLwZTa9F8nEA+CcOlA== X-Google-Smtp-Source: ABdhPJwdvrNfkJXAcvNRDv0LDcHiQoTcoHW5u6yldhIeg4NyVDaodEvtg7GiyErRP5gC1JTiAvHUXQ== X-Received: by 2002:a5d:4d48:: with SMTP id a8mr7188440wru.318.1600806575667; Tue, 22 Sep 2020 13:29:35 -0700 (PDT) Received: from jozef-acer-manjaro ([2a01:4b00:87fd:900:5e1d:5c99:56da:76e8]) by smtp.gmail.com with ESMTPSA id i83sm6037182wma.22.2020.09.22.13.29.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 13:29:35 -0700 (PDT) Date: Tue, 22 Sep 2020 21:29:33 +0100 From: Jozef Lawrynowicz To: binutils@sourceware.org Subject: [PATCH] Support SHF_GNU_RETAIN ELF section flag Message-ID: <20200922202933.kgflmtnwzkdrmrvs@jozef-acer-manjaro> Mail-Followup-To: binutils@sourceware.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ghyd25n7jgv62eje" Content-Disposition: inline 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: Tue, 22 Sep 2020 20:29:42 -0000 --ghyd25n7jgv62eje Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --ghyd25n7jgv62eje Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Support-SHF_GNU_RETAIN-ELF-section-flag.patch" >From d7f92cd05883567cf07cb8878aa60b666894197d 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. This 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 | 59 ++++++++++ gas/doc/as.texi | 20 ++++ gas/testsuite/gas/elf/elf.exp | 5 + 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/section10.d | 4 +- include/elf/common.h | 1 + ld/NEWS | 4 + ld/ld.texi | 8 ++ ld/testsuite/ld-elf/elf.exp | 38 ++++++- ld/testsuite/ld-elf/retain1.msg | 9 ++ ld/testsuite/ld-elf/retain1.s | 114 ++++++++++++++++++++ ld/testsuite/ld-elf/retain2.d | 7 ++ 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 +++ 36 files changed, 921 insertions(+), 5 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 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=