public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] binutils: Add elf header eflag option in objcopy.
@ 2022-03-12  7:46 liuzhensong
  0 siblings, 0 replies; only message in thread
From: liuzhensong @ 2022-03-12  7:46 UTC (permalink / raw)
  To: binutils; +Cc: liuzhensong

  Specify flags when copying binary to elf file.

  usage:
  objcopy -I binary --alt-elf-eflags=val bin  elf

  binutils/
    * objcopy.c
---
 binutils/objcopy.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index d53aa5c6000..b03012210b0 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -303,6 +303,10 @@ enum long_section_name_handling
    This is also the only behaviour for 'strip'.  */
 static enum long_section_name_handling long_section_names = KEEP;
 
+/* Use alternative elf header e_flags?  */
+static bool alt_elf_eflags_set = false;
+static unsigned int alt_elf_eflags = 0;
+
 /* 150 isn't special; it's just an arbitrary non-ASCII char value.  */
 enum command_line_switch
 {
@@ -310,6 +314,7 @@ enum command_line_switch
   OPTION_ADD_GNU_DEBUGLINK,
   OPTION_ADD_SYMBOL,
   OPTION_ALT_MACH_CODE,
+  OPTION_ALT_ELF_EFLAGS,
   OPTION_CHANGE_ADDRESSES,
   OPTION_CHANGE_LEADING_CHAR,
   OPTION_CHANGE_SECTION_ADDRESS,
@@ -427,6 +432,7 @@ static struct option copy_options[] =
   {"adjust-vma", required_argument, 0, OPTION_CHANGE_ADDRESSES},
   {"adjust-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS},
   {"alt-machine-code", required_argument, 0, OPTION_ALT_MACH_CODE},
+  {"alt-elf-eflags", required_argument, 0, OPTION_ALT_ELF_EFLAGS},
   {"binary-architecture", required_argument, 0, 'B'},
   {"byte", required_argument, 0, 'b'},
   {"change-addresses", required_argument, 0, OPTION_CHANGE_ADDRESSES},
@@ -660,6 +666,7 @@ copy_usage (FILE *stream, int exit_status)
      --weaken-symbols <file>       -W for all symbols listed in <file>\n\
      --add-symbol <name>=[<section>:]<value>[,<flags>]  Add a symbol\n\
      --alt-machine-code <index>    Use the target's <index>'th alternative machine\n\
+     --alt-elf-eflags=<value> 	   Use the alternative elf header e_flags\n\
      --writable-text               Mark the output text as writable\n\
      --readonly-text               Make the output text write protected\n\
      --pure                        Mark the output file as demand paged\n\
@@ -3484,6 +3491,11 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 	}
     }
 
+  if (alt_elf_eflags_set)
+    {
+      elf_elfheader (obfd)->e_flags = alt_elf_eflags;
+    }
+
   return true;
 }
 
@@ -5851,6 +5863,11 @@ copy_main (int argc, char *argv[])
 	    fatal (_("verilog data width must be at least 1 byte"));
 	  break;
 
+	case OPTION_ALT_ELF_EFLAGS:
+	  alt_elf_eflags_set = true;
+	  alt_elf_eflags = parse_vma (optarg, "--alt-elf-eflags");
+	  break;
+
 	case 0:
 	  /* We've been given a long option.  */
 	  break;
-- 
2.31.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-12  7:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-12  7:46 [PATCH] binutils: Add elf header eflag option in objcopy liuzhensong

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