From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by sourceware.org (Postfix) with ESMTPS id DDC0738708C7 for ; Tue, 22 Sep 2020 23:59:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DDC0738708C7 Received: by mail-io1-xd43.google.com with SMTP id g128so21670493iof.11 for ; Tue, 22 Sep 2020 16:59:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=pe7Vol6fZ/GxTyqnhF1R/GVIGmyDYDg/gdq2D8eHTlE=; b=hSYWRHHr+6a0MBstNqqqAXke7igsFfsjffJc7UGwtdsdTIfESbzfg55Mwn/p7tL2hR E++gPxooE8ImqpvhLJMY0Ul+6qQWePWgnrNbUDTcpVbKaG8blBk0zDEY4i0NMXSLran3 x+eenmEwoEhWQUgDYg2Ag3eHkuDrQNOM4j2d5hcacNY96x2L+rj9kEyo2nXV4oWDJ7dF 5lZ84VjXsdh2S36DusLM4pWNFrsX3+z2DwEb8eJOuHt+T56yAIrKYrabQY4AzizJakDf b/paKUYudUwM3uxmhCfS0gELAZjRRYBBs1sYWylrFO8JxIoWFDpWMG/kcqQP+3t+k9dN Zo7A== X-Gm-Message-State: AOAM530i3QDYGZm2OqSXT09bvO1Vlzs6lEA+Zm1y3UzI8VKZuhg+X/11 7Jq92mdlrEeEm9AWG5yXc076GOSiBuyUDf3lD2enRO2m684= X-Google-Smtp-Source: ABdhPJyIoK/W7XHSqcSIIlRfIwCAClfIvDiuoYbnl7he0L7+dRs0+k1khm5QzlpgzKr/KAEK67MX1cv3A013jrF1sgI= X-Received: by 2002:a05:6638:1643:: with SMTP id a3mr6181017jat.4.1600819144153; Tue, 22 Sep 2020 16:59:04 -0700 (PDT) MIME-Version: 1.0 References: <20200922202933.kgflmtnwzkdrmrvs@jozef-acer-manjaro> In-Reply-To: <20200922202933.kgflmtnwzkdrmrvs@jozef-acer-manjaro> From: "H.J. Lu" Date: Tue, 22 Sep 2020 16:58:23 -0700 Message-ID: Subject: Re: [PATCH] Support SHF_GNU_RETAIN ELF section flag To: Binutils Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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 23:59:06 -0000 On Tue, Sep 22, 2020 at 1:30 PM 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 + /* A GNU extension for preventing linker garbage collection of sections. */ + {"retain", obj_elf_retain, 0}, + Why is this needed? Isn't @@ -857,6 +861,9 @@ obj_elf_parse_section_letters (char *str, size_t len, case 'd': *gnu_attr |= SHF_GNU_MBIND; break; + case 'R': + *gnu_attr |= SHF_GNU_RETAIN; + break; case '?': *is_clone = TRUE; break; enough? The .section directive is used for all other SHF_XXX bits. I don't think we need a separate directive for SHF_GNU_RETAIN? -- H.J.