public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Binutils <binutils@sourceware.org>
Subject: Re: [PATCH] Support SHF_GNU_RETAIN ELF section flag
Date: Tue, 22 Sep 2020 16:58:23 -0700	[thread overview]
Message-ID: <CAMe9rOq9dBOXkMe8U-DvFy059++aPj0a5rOacZGLvcwrmiwLjg@mail.gmail.com> (raw)
In-Reply-To: <20200922202933.kgflmtnwzkdrmrvs@jozef-acer-manjaro>

On Tue, Sep 22, 2020 at 1:30 PM Jozef Lawrynowicz
<jozef.l@mittosystems.com> 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.

  parent reply	other threads:[~2020-09-22 23:59 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22 20:29 Jozef Lawrynowicz
2020-09-22 23:24 ` Hans-Peter Nilsson
2020-09-22 23:58 ` H.J. Lu [this message]
2020-09-23  1:09 ` Fangrui Song
2020-09-23  9:58   ` Jozef Lawrynowicz
2020-09-23 13:39     ` H.J. Lu
2020-09-23 13:51       ` Michael Matz
2020-09-23 16:52         ` Jozef Lawrynowicz
2020-09-23 17:13           ` H.J. Lu
2020-09-23 18:47             ` Jozef Lawrynowicz
2020-09-23 19:03               ` H.J. Lu
2020-09-23 20:04                 ` Jozef Lawrynowicz
2020-09-23 20:17                   ` H.J. Lu
2020-09-23 23:29                     ` Fangrui Song
2020-09-24 11:39                       ` Jozef Lawrynowicz
2020-09-24 19:06                         ` Fangrui Song
2020-09-24 13:27                       ` Michael Matz
2020-09-24 13:18                     ` H.J. Lu
2020-09-24 13:49                       ` Jozef Lawrynowicz
2020-09-24 13:59                         ` H.J. Lu
2020-09-24 16:56                           ` Jozef Lawrynowicz
2020-09-24 17:04                             ` H.J. Lu
2020-09-24 17:18                               ` Jozef Lawrynowicz
2020-09-24 17:37                                 ` H.J. Lu
2020-09-23 12:13 ` Jozef Lawrynowicz
2020-09-23 13:59   ` Alan Modra
2020-09-23 16:54     ` Jozef Lawrynowicz
2020-09-28 11:35 ` Pedro Alves
2020-09-28 12:28   ` Jozef Lawrynowicz
2020-09-28 14:46     ` Pedro Alves
2020-09-29 13:18       ` Michael Matz
2020-09-29 13:22         ` Jozef Lawrynowicz
2020-09-29 13:48         ` Pedro Alves
2020-09-29 13:55           ` Michael Matz
2020-09-29 14:04             ` Pedro Alves
2020-09-29 14:10               ` Michael Matz
2020-09-29 14:11                 ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOq9dBOXkMe8U-DvFy059++aPj0a5rOacZGLvcwrmiwLjg@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).