diff options
author | Kaylee Blake <klkblake@gmail.com> | 2020-03-04 19:18:07 +1030 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2023-06-29 10:29:46 -0700 |
commit | 96cc7918c18cdb7bd0331d836fa7f05341732580 (patch) | |
tree | 906a911fb1b123f4ae238f8504671b1aeecbbe89 /bfd/bfd.c | |
parent | fa2b501cdcbb7e9e8437f1dfb4b1e939dcb07264 (diff) | |
download | gdb-96cc7918c18cdb7bd0331d836fa7f05341732580.zip gdb-96cc7918c18cdb7bd0331d836fa7f05341732580.tar.gz gdb-96cc7918c18cdb7bd0331d836fa7f05341732580.tar.bz2 |
ELF: Strip section header in ELF objects
Section header isn't mandatory on ELF executable nor shared library.
This patch adds a new linker option, -z nosectionheader, to omit ELF
section header, a new objcopy and strip option, --strip-section-headers,
to remove ELF section headers.
bfd/
2023-06-06 H.J. Lu <hongjiu.lu@intel.com>
Kaylee Blake <klkblake@gmail.com>
PR ld/25617
* bfd.c (BFD_NO_SECTION_HEADER): New.
(BFD_FLAGS_SAVED): Add BFD_NO_SECTION_HEADER.
(BFD_FLAGS_FOR_BFD_USE_MASK): Likewise.
* elfcode.h (elf_swap_ehdr_out): Omit section header with
BFD_NO_SECTION_HEADER.
(elf_write_shdrs_and_ehdr): Likewise.
* elfxx-target.h (TARGET_BIG_SYM): Add BFD_NO_SECTION_HEADER
to object_flags.
(TARGET_LITTLE_SYM): Likewise.
* bfd-in2.h: Regenerated.
binutils/
2023-06-06 H.J. Lu <hongjiu.lu@intel.com>
PR ld/25617
* NEWS: Mention --strip-section-headers for objcopy and strip.
* objcopy.c (strip_section_headers): New.
(command_line_switch): Add OPTION_STRIP_SECTION_HEADERS.
(strip_options): Add --strip-section-headers.
(copy_options): Likewise.
(copy_usage): Add --strip-section-headers.
(strip_usage): Likewise.
(copy_object): Handle --strip-section-headers for ELF files.
(strip_main): Handle OPTION_STRIP_SECTION_HEADERS.
(copy_main): Likewise.
* doc/binutils.texi: Document --strip-section-headers for objcopy
and strip.
ld/
2023-06-06 H.J. Lu <hongjiu.lu@intel.com>
Kaylee Blake <klkblake@gmail.com>
PR ld/25617
* NEWS: Mention -z nosectionheader.
* emultempl/elf.em: Support -z sectionheader and
-z nosectionheader.
* ld.h (ld_config_type): Add no_section_header.
* ld.texi: Document -z sectionheader and -z nosectionheader.
* ldlang.c (ldlang_open_output): Handle
config.no_section_header.
* lexsup.c (parse_args): Enable --strip-all with
-z nosectionheader. Disallow -r with -z nosectionheader.
(elf_static_list_options): Add -z sectionheader and
-z nosectionheader.
Diffstat (limited to 'bfd/bfd.c')
-rw-r--r-- | bfd/bfd.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -192,11 +192,15 @@ CODE_FRAGMENT . {* Compress sections in this BFD with SHF_COMPRESSED zstd. *} .#define BFD_COMPRESS_ZSTD 0x400000 . +. {* Don't generate ELF section header. *} +.#define BFD_NO_SECTION_HEADER 0x800000 +. . {* Flags bits which are for BFD use only. *} .#define BFD_FLAGS_FOR_BFD_USE_MASK \ . (BFD_IN_MEMORY | BFD_COMPRESS | BFD_DECOMPRESS | BFD_LINKER_CREATED \ . | BFD_PLUGIN | BFD_TRADITIONAL_FORMAT | BFD_DETERMINISTIC_OUTPUT \ -. | BFD_COMPRESS_GABI | BFD_CONVERT_ELF_COMMON | BFD_USE_ELF_STT_COMMON) +. | BFD_COMPRESS_GABI | BFD_CONVERT_ELF_COMMON | BFD_USE_ELF_STT_COMMON \ +. | BFD_NO_SECTION_HEADER) . . {* The format which belongs to the BFD. (object, core, etc.) *} . ENUM_BITFIELD (bfd_format) format : 3; |