From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 3F1D83858D1E for ; Sun, 17 Apr 2022 22:58:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F1D83858D1E Received: by mail-pl1-x631.google.com with SMTP id c23so11105494plo.0 for ; Sun, 17 Apr 2022 15:58:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ObpDWP9tUyZmCjg5ZCKuUgUaAqhGcgnoonAHQ5wiCYc=; b=JUoIDhWOQnVien3fgy7HphjtiWdT7E8oJ9I/YcfssCUF7NM0YV1ZmkWbOndlhn10Hd RHUmvY8xmAua8wnWNc+FQI90F2P4G6/BYvQMwYV/RmWw1otuuu/tHF/CSXAoo/vZNlsk DK6e0T9hHuWsjsxrNfkUv5z4m4I7LDJT4tO4q1qZ/TbQ6vqXwRglhyLB0QkM/IgFZ36r 4zKZ8R6N2Qu9RLL6HQYDjuhLcKcaNNDkf13L5pQCsJ2mW+f2xKTMZP0EA/pM6wCPfyzY vBhuZyqI+hmkLRmkyJ9M2SBtq4U7gfJRJyh/LBai2oS+d4xEokhKjkNqlTLVLpfBeK18 hlaA== X-Gm-Message-State: AOAM5331TOHq3Ejn1Ty9NUPg8xtmfQ5VVlxHQyrXbxWFdHvCf3XxrOHA N/qwRlGSdtY6qdYPEdw0xcl9Vi3748wmr35P5YHMjQie X-Google-Smtp-Source: ABdhPJxCHY231SuitWtL3zIe4xiVlPnAk3Gg2BCUnWAin2l9YMHhxmIIV4z/h8H1TCQ4UMhztAqnFOtM/MKu5xIsw38= X-Received: by 2002:a17:902:d2d2:b0:159:118:e10e with SMTP id n18-20020a170902d2d200b001590118e10emr1797530plc.102.1650236311211; Sun, 17 Apr 2022 15:58:31 -0700 (PDT) MIME-Version: 1.0 References: <20220417082358.395464-1-liuzhensong@loongson.cn> In-Reply-To: <20220417082358.395464-1-liuzhensong@loongson.cn> From: "H.J. Lu" Date: Sun, 17 Apr 2022 15:58:20 -0700 Message-ID: Subject: Re: [PATCH v3] objcopy: Add ELF header e_flags option in objcopy. To: liuzhensong Cc: Binutils X-Spam-Status: No, score=-3025.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Sun, 17 Apr 2022 22:58:34 -0000 On Sun, Apr 17, 2022, 1:25 AM liuzhensong 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 Specifies data width, in bytes, for > verilog output\n\ > + --elf-eflags= Set e_flags to 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.