* [PATCH v3] objcopy: Add ELF header e_flags option in objcopy.
@ 2022-04-17 8:23 liuzhensong
2022-04-17 22:58 ` H.J. Lu
0 siblings, 1 reply; 3+ messages in thread
From: liuzhensong @ 2022-04-17 8:23 UTC (permalink / raw)
To: binutils; +Cc: liuzhensong
Specify flags when copying binary to ELF.
The flags is treated as an absolute number to be
stored in the e_flags field of the ELF header.
Usage:
objcopy -I binary -O target --elf-eflags=val bin_file elf_file
binutils/
* objcopy.c
* doc/binutils.texi:Add the new objcopy option.
---
binutils/doc/binutils.texi | 7 +++++++
binutils/objcopy.c | 16 ++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 2c234c682aa..65230775b29 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -1326,6 +1326,7 @@ objcopy [@option{-F} @var{bfdname}|@option{--target=}@var{bfdname}]
[@option{--merge-notes}]
[@option{--no-merge-notes}]
[@option{--verilog-data-width=@var{val}}]
+ [@option{--elf-eflags=}@var{value}]
[@option{-v}|@option{--verbose}]
[@option{-V}|@option{--version}]
[@option{--help}] [@option{--info}]
@@ -2187,6 +2188,12 @@ For Verilog output, this options controls the number of bytes
converted for each output data element. The input target controls the
endianness of the conversion.
+@item --elf-eflags=@var{value}
+Meaningful only for ELF output. Use @var{value} as e_flags of the
+output. This is useful for changing the e_flags of an existing binary.
+The @var{value} is treated as an absolute number to be stored in the
+e_flags field of the ELF header.
+
@item -v
@itemx --verbose
Verbose output: list all object files modified. In the case of
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 6fb31c8cac7..3c1eaf5ec1a 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;
+/* Specify ELF header e_flags? */
+static bool elf_eflags_set = false;
+static unsigned int elf_eflags = 0;
+
/* 150 isn't special; it's just an arbitrary non-ASCII char value. */
enum command_line_switch
{
@@ -321,6 +325,7 @@ enum command_line_switch
OPTION_DEBUGGING,
OPTION_DECOMPRESS_DEBUG_SECTIONS,
OPTION_DUMP_SECTION,
+ OPTION_ELF_EFLAGS,
OPTION_ELF_STT_COMMON,
OPTION_EXTRACT_DWO,
OPTION_EXTRACT_SYMBOL,
@@ -443,6 +448,7 @@ static struct option copy_options[] =
{"discard-all", no_argument, 0, 'x'},
{"discard-locals", no_argument, 0, 'X'},
{"dump-section", required_argument, 0, OPTION_DUMP_SECTION},
+ {"elf-eflags", required_argument, 0, OPTION_ELF_EFLAGS},
{"elf-stt-common", required_argument, 0, OPTION_ELF_STT_COMMON},
{"enable-deterministic-archives", no_argument, 0, 'D'},
{"extract-dwo", no_argument, 0, OPTION_EXTRACT_DWO},
@@ -684,6 +690,7 @@ copy_usage (FILE *stream, int exit_status)
--elf-stt-common=[yes|no] Generate ELF common symbols with STT_COMMON\n\
type\n\
--verilog-data-width <number> Specifies data width, in bytes, for verilog output\n\
+ --elf-eflags=<value> Set e_flags to <value> for ELF output\n\
-M --merge-notes Remove redundant entries in note sections\n\
--no-merge-notes Do not attempt to remove redundant notes (default)\n\
-v --verbose List all object files modified\n\
@@ -3496,6 +3503,10 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
}
}
+ if (bfd_get_flavour (obfd) == bfd_target_elf_flavour
+ && elf_eflags_set)
+ elf_elfheader (obfd)->e_flags = elf_eflags;
+
return true;
}
@@ -5863,6 +5874,11 @@ copy_main (int argc, char *argv[])
fatal (_("verilog data width must be at least 1 byte"));
break;
+ case OPTION_ELF_EFLAGS:
+ elf_eflags_set = true;
+ elf_eflags = parse_vma (optarg, "--elf-eflags");
+ break;
+
case 0:
/* We've been given a long option. */
break;
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] objcopy: Add ELF header e_flags option in objcopy.
2022-04-17 8:23 [PATCH v3] objcopy: Add ELF header e_flags option in objcopy liuzhensong
@ 2022-04-17 22:58 ` H.J. Lu
2022-04-19 6:56 ` Jan Beulich
0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2022-04-17 22:58 UTC (permalink / raw)
To: liuzhensong; +Cc: Binutils
On Sun, Apr 17, 2022, 1:25 AM liuzhensong <liuzhensong@loongson.cn> wrote:
> Specify flags when copying binary to ELF.
> The flags is treated as an absolute number to be
> stored in the e_flags field of the ELF header.
>
> Usage:
> objcopy -I binary -O target --elf-eflags=val bin_file elf_file
>
> binutils/
> * objcopy.c
> * doc/binutils.texi:Add the new objcopy option.
> ---
> binutils/doc/binutils.texi | 7 +++++++
> binutils/objcopy.c | 16 ++++++++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
> index 2c234c682aa..65230775b29 100644
> --- a/binutils/doc/binutils.texi
> +++ b/binutils/doc/binutils.texi
> @@ -1326,6 +1326,7 @@ objcopy [@option{-F}
> @var{bfdname}|@option{--target=}@var{bfdname}]
> [@option{--merge-notes}]
> [@option{--no-merge-notes}]
> [@option{--verilog-data-width=@var{val}}]
> + [@option{--elf-eflags=}@var{value}]
> [@option{-v}|@option{--verbose}]
> [@option{-V}|@option{--version}]
> [@option{--help}] [@option{--info}]
> @@ -2187,6 +2188,12 @@ For Verilog output, this options controls the
> number of bytes
> converted for each output data element. The input target controls the
> endianness of the conversion.
>
> +@item --elf-eflags=@var{value}
> +Meaningful only for ELF output. Use @var{value} as e_flags of the
> +output. This is useful for changing the e_flags of an existing binary.
> +The @var{value} is treated as an absolute number to be stored in the
> +e_flags field of the ELF header.
> +
> @item -v
> @itemx --verbose
> Verbose output: list all object files modified. In the case of
> diff --git a/binutils/objcopy.c b/binutils/objcopy.c
> index 6fb31c8cac7..3c1eaf5ec1a 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;
>
> +/* Specify ELF header e_flags? */
> +static bool elf_eflags_set = false;
> +static unsigned int elf_eflags = 0;
> +
> /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
> enum command_line_switch
> {
> @@ -321,6 +325,7 @@ enum command_line_switch
> OPTION_DEBUGGING,
> OPTION_DECOMPRESS_DEBUG_SECTIONS,
> OPTION_DUMP_SECTION,
> + OPTION_ELF_EFLAGS,
> OPTION_ELF_STT_COMMON,
> OPTION_EXTRACT_DWO,
> OPTION_EXTRACT_SYMBOL,
> @@ -443,6 +448,7 @@ static struct option copy_options[] =
> {"discard-all", no_argument, 0, 'x'},
> {"discard-locals", no_argument, 0, 'X'},
> {"dump-section", required_argument, 0, OPTION_DUMP_SECTION},
> + {"elf-eflags", required_argument, 0, OPTION_ELF_EFLAGS},
> {"elf-stt-common", required_argument, 0, OPTION_ELF_STT_COMMON},
> {"enable-deterministic-archives", no_argument, 0, 'D'},
> {"extract-dwo", no_argument, 0, OPTION_EXTRACT_DWO},
> @@ -684,6 +690,7 @@ copy_usage (FILE *stream, int exit_status)
> --elf-stt-common=[yes|no] Generate ELF common symbols with
> STT_COMMON\n\
> type\n\
> --verilog-data-width <number> Specifies data width, in bytes, for
> verilog output\n\
> + --elf-eflags=<value> Set e_flags to <value> for ELF
> output\n\
> -M --merge-notes Remove redundant entries in note
> sections\n\
> --no-merge-notes Do not attempt to remove redundant
> notes (default)\n\
> -v --verbose List all object files modified\n\
> @@ -3496,6 +3503,10 @@ copy_object (bfd *ibfd, bfd *obfd, const
> bfd_arch_info_type *input_arch)
> }
> }
>
> + if (bfd_get_flavour (obfd) == bfd_target_elf_flavour
> + && elf_eflags_set)
> + elf_elfheader (obfd)->e_flags = elf_eflags;
> +
> return true;
> }
>
> @@ -5863,6 +5874,11 @@ copy_main (int argc, char *argv[])
> fatal (_("verilog data width must be at least 1 byte"));
> break;
>
> + case OPTION_ELF_EFLAGS:
> + elf_eflags_set = true;
> + elf_eflags = parse_vma (optarg, "--elf-eflags");
> + break;
> +
> case 0:
> /* We've been given a long option. */
> break;
> --
> 2.31.1
>
Should we extend elfedit instead?
H.J.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] objcopy: Add ELF header e_flags option in objcopy.
2022-04-17 22:58 ` H.J. Lu
@ 2022-04-19 6:56 ` Jan Beulich
0 siblings, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2022-04-19 6:56 UTC (permalink / raw)
To: H.J. Lu, liuzhensong; +Cc: Binutils
On 18.04.2022 00:58, H.J. Lu via Binutils wrote:
> On Sun, Apr 17, 2022, 1:25 AM liuzhensong <liuzhensong@loongson.cn> wrote:
>>
> Should we extend elfedit instead?
I think so, yes.
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-19 6:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-17 8:23 [PATCH v3] objcopy: Add ELF header e_flags option in objcopy liuzhensong
2022-04-17 22:58 ` H.J. Lu
2022-04-19 6:56 ` Jan Beulich
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).