public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Support 'exclude' in objcopy --set-section-flags
@ 2020-01-16  8:55 Fangrui Song via binutils
  2020-02-03  6:00 ` Fangrui Song
  0 siblings, 1 reply; 5+ messages in thread
From: Fangrui Song via binutils @ 2020-01-16  8:55 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 322 bytes --]

https://sourceware.org/bugzilla/show_bug.cgi?id=25371

commit 18ae9cc1db45e2e7f6467b91d8abbc5eb45fbaa5 makes SHF_EXCLUDE
generic, not like other SHF_MASKPROC flags. So we do not preserve
SHF_EXCLUDE when setting sh_flags.

--set-section-flags .foo= => clear SHF_EXCLUDE
--set-section-flags .foo=exclude => set SHF_EXCLUDE

[-- Attachment #2: objcopy.patch --]
[-- Type: text/x-diff, Size: 3350 bytes --]

From cddb761804cf4e4bf3b67fef1ef0af3dbe07cd2b Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Thu, 16 Jan 2020 00:43:14 -0800
Subject: [PATCH] Support 'exclude' in objcopy --set-section-flags
To: binutils@sourceware.org

---
 bfd/elf.c                  | 2 +-
 binutils/ChangeLog         | 4 ++++
 binutils/doc/binutils.texi | 8 ++++----
 binutils/objcopy.c         | 3 ++-
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/bfd/elf.c b/bfd/elf.c
index 08aaab644a..9849d2d53c 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7766,7 +7766,7 @@ _bfd_elf_init_private_section_data (bfd *ibfd,
 
   /* FIXME: Is this correct for all OS/PROC specific flags?  */
   elf_section_flags (osec) |= (elf_section_flags (isec)
-			       & (SHF_MASKOS | SHF_MASKPROC));
+                              & (SHF_MASKOS | SHF_MASKPROC) & ~SHF_EXCLUDE);
 
   /* Copy sh_info from input for mbind section.  */
   if ((elf_tdata (ibfd)->has_gnu_osabi & elf_gnu_osabi_mbind) != 0
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 3737672832..398531ecb2 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,7 @@
+2020-01-16  Fangrui Song  <maskray@google.com>
+
+	* objcopy.c (parse_flags): Handle "exclude".
+
 2020-01-13  Nick Clifton  <nickc@redhat.com>
 
 	* objdump.c (disassemble_bytes): Remove C99-ism.
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 669bee968f..289d7b14a3 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -1644,10 +1644,10 @@ Set the flags for any sections matching @var{sectionpattern}.  The
 @var{flags} argument is a comma separated string of flag names.  The
 recognized names are @samp{alloc}, @samp{contents}, @samp{load},
 @samp{noload}, @samp{readonly}, @samp{code}, @samp{data}, @samp{rom},
-@samp{share}, and @samp{debug}.  You can set the @samp{contents} flag
-for a section which does not have contents, but it is not meaningful
-to clear the @samp{contents} flag of a section which does have
-contents--just remove the section instead.  Not all flags are
+@samp{exclude}, @samp{share}, and @samp{debug}.  You can set the
+@samp{contents} flag for a section which does not have contents, but it
+is not meaningful to clear the @samp{contents} flag of a section which
+does have contents--just remove the section instead.  Not all flags are
 meaningful for all object file formats.
 
 @item --set-section-alignment @var{sectionpattern}=@var{align}
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index ef3b693be4..3cee65de50 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -780,6 +780,7 @@ parse_flags (const char *s)
       PARSE_FLAG ("code", SEC_CODE);
       PARSE_FLAG ("data", SEC_DATA);
       PARSE_FLAG ("rom", SEC_ROM);
+      PARSE_FLAG ("exclude", SEC_EXCLUDE);
       PARSE_FLAG ("share", SEC_COFF_SHARED);
       PARSE_FLAG ("contents", SEC_HAS_CONTENTS);
       PARSE_FLAG ("merge", SEC_MERGE);
@@ -794,7 +795,7 @@ parse_flags (const char *s)
 	  copy[len] = '\0';
 	  non_fatal (_("unrecognized section flag `%s'"), copy);
 	  fatal (_("supported flags: %s"),
-		 "alloc, load, noload, readonly, debug, code, data, rom, share, contents, merge, strings");
+		 "alloc, load, noload, readonly, debug, code, data, rom, exclude, share, contents, merge, strings");
 	}
 
       s = snext;
-- 
2.25.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-11 17:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16  8:55 [PATCH] Support 'exclude' in objcopy --set-section-flags Fangrui Song via binutils
2020-02-03  6:00 ` Fangrui Song
2020-02-10 16:24   ` Nick Clifton
2020-02-10 18:16     ` Fangrui Song
     [not found]     ` <SN6PR07MB522933C280BE82ECF585CB7DCB190@SN6PR07MB5229.namprd07.prod.outlook.com>
2020-02-11 17:14       ` Nick Clifton

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).