diff options
author | Fangrui Song <maskray@google.com> | 2023-07-09 10:57:19 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2023-07-09 10:57:19 -0700 |
commit | 5e24da908dbf6ddeb03e2b194f6b39dea3c660f3 (patch) | |
tree | e794077f7d101002abb3d965f3377ebbbb4ea0a6 /binutils | |
parent | 4fb2abb59d16f6395162f2e8d9494cde4a37e4a1 (diff) | |
download | gdb-5e24da908dbf6ddeb03e2b194f6b39dea3c660f3.zip gdb-5e24da908dbf6ddeb03e2b194f6b39dea3c660f3.tar.gz gdb-5e24da908dbf6ddeb03e2b194f6b39dea3c660f3.tar.bz2 |
PR30592 objcopy: allow --set-section-flags to add or remove SHF_X86_64_LARGE
For example, objcopy --set-section-flags .data=alloc,large will add
SHF_X86_64_LARGE to the .data section. Omitting "large" will drop the
SHF_X86_64_LARGE flag.
The bfd_section flag is named generically, SEC_ELF_LARGE, in case other
processors want to follow SHF_X86_64_LARGE. SEC_ELF_LARGE has the same
value as SEC_TIC54X_BLOCK used by coff.
bfd/
* section.c: Define SEC_ELF_LARGE.
* bfd-in2.h: Regenerate.
* elf64-x86-64.c (elf_x86_64_section_flags, elf_x86_64_fake_sections,
elf_x86_64_copy_private_section_data): New.
binutils/
* NEWS: Mention the new feature for objcopy.
* doc/binutils.texi: Mention "large".
* objcopy.c (parse_flags): Parse "large".
(check_new_section_flags): Error if "large" is used with a
non-x86-64 ELF target.
* testsuite/binutils-all/x86-64/large-sections.d: New.
* testsuite/binutils-all/x86-64/large-sections.s: New.
* testsuite/binutils-all/x86-64/large-sections-i386.d: New.
* testsuite/binutils-all/x86-64/large-sections-2.d: New.
* testsuite/binutils-all/x86-64/large-sections-2-x32.d: New.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/ChangeLog | 14 | ||||
-rw-r--r-- | binutils/NEWS | 3 | ||||
-rw-r--r-- | binutils/doc/binutils.texi | 15 | ||||
-rw-r--r-- | binutils/objcopy.c | 22 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/x86-64/large-sections-2-x32.d | 15 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/x86-64/large-sections-2.d | 15 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/x86-64/large-sections-i386.d | 6 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/x86-64/large-sections.d | 14 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/x86-64/large-sections.s | 8 |
9 files changed, 102 insertions, 10 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 866cf56..097673f 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,17 @@ +2023-07-09 Fangrui Song <maskray@google.com> + + PR 30592 + * NEWS: Mention the new feature for objcopy. + * doc/binutils.texi: Mention "large". + * objcopy.c (parse_flags): Parse "large". + (check_new_section_flags): Error if "large" is used with a + non-x86-64 ELF target. + * testsuite/binutils-all/x86-64/large-sections.d: New. + * testsuite/binutils-all/x86-64/large-sections.s: New. + * testsuite/binutils-all/x86-64/large-sections-i386.d: New. + * testsuite/binutils-all/x86-64/large-sections-2.d: New. + * testsuite/binutils-all/x86-64/large-sections-2-x32.d: New. + 2023-07-03 Nick Clifton <nickc@redhat.com> * README-how-to-make-a-release: Change some version numbers. diff --git a/binutils/NEWS b/binutils/NEWS index 563062c..d64cae0 100644 --- a/binutils/NEWS +++ b/binutils/NEWS @@ -1,5 +1,8 @@ -*- text -*- +* objcopy --set-section-flags now supports "large" to set SHF_X86_64_LARGE + for ELF x86-64 objects. + Changes in 2.41: * The MIPS port now supports the Sony Interactive Entertainment Allegrex diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index 8314cb5..309bedf 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -1745,13 +1745,14 @@ 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{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. In particular the -@samp{share} flag is only meaningful for COFF format files and not for -ELF format files. +@samp{exclude}, @samp{share}, @samp{debug}, and @samp{large}. +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. In particular the +@samp{share} flag is only meaningful for COFF format files and not for ELF +format files. The ELF x86-64 specific flag @samp{large} corresponds to +SHF_X86_64_LARGE. @item --set-section-alignment @var{sectionpattern}=@var{align} Set the alignment for any sections matching @var{sectionpattern}. diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 3569b89..c931f67 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -803,6 +803,7 @@ parse_flags (const char *s) PARSE_FLAG ("contents", SEC_HAS_CONTENTS); PARSE_FLAG ("merge", SEC_MERGE); PARSE_FLAG ("strings", SEC_STRINGS); + PARSE_FLAG ("large", SEC_ELF_LARGE); #undef PARSE_FLAG else { @@ -812,8 +813,10 @@ parse_flags (const char *s) strncpy (copy, s, len); copy[len] = '\0'; non_fatal (_("unrecognized section flag `%s'"), copy); - fatal (_("supported flags: %s"), - "alloc, load, noload, readonly, debug, code, data, rom, exclude, share, contents, merge, strings"); + fatal (_ ("supported flags: %s"), + "alloc, load, noload, readonly, debug, code, data, rom, " + "exclude, contents, merge, strings, (COFF specific) share, " + "(ELF x86-64 specific) large"); } s = snext; @@ -2618,7 +2621,7 @@ merge_gnu_build_notes (bfd * abfd, } static flagword -check_new_section_flags (flagword flags, bfd * abfd, const char * secname) +check_new_section_flags (flagword flags, bfd *abfd, const char * secname) { /* Only set the SEC_COFF_SHARED flag on COFF files. The same bit value is used by ELF targets to indicate @@ -2631,6 +2634,19 @@ check_new_section_flags (flagword flags, bfd * abfd, const char * secname) bfd_get_filename (abfd), secname); flags &= ~ SEC_COFF_SHARED; } + + /* Report a fatal error if 'large' is used with a non-x86-64 ELF target. + Suppress the error for non-ELF targets to allow -O binary and formats that + use the bit value SEC_ELF_LARGE for other purposes. */ + if ((flags & SEC_ELF_LARGE) != 0 + && bfd_get_flavour (abfd) == bfd_target_elf_flavour + && get_elf_backend_data (abfd)->elf_machine_code != EM_X86_64) + { + fatal (_ ("%s[%s]: 'large' flag is ELF x86-64 specific"), + bfd_get_filename (abfd), secname); + flags &= ~SEC_ELF_LARGE; + } + return flags; } diff --git a/binutils/testsuite/binutils-all/x86-64/large-sections-2-x32.d b/binutils/testsuite/binutils-all/x86-64/large-sections-2-x32.d new file mode 100644 index 0000000..fb28d08 --- /dev/null +++ b/binutils/testsuite/binutils-all/x86-64/large-sections-2-x32.d @@ -0,0 +1,15 @@ +#source: large-sections.s +#PROG: objcopy +#as: --x32 +#objcopy: --set-section-flags .ldata=alloc +#readelf: -S -W + +#... + \[[ 0-9]+\] \.text.*[ \t]+PROGBITS[ \t0-9a-f]+AX[ \t]+.* +#... + \[[ 0-9]+\] \.data.*[ \t]+PROGBITS[ \t0-9a-f]+WA[ \t]+.* +#... + \[[ 0-9]+\] \.ltext.*[ \t]+PROGBITS[ \t0-9a-f]+AXl[ \t]+.* +#... + \[[ 0-9]+\] \.ldata.*[ \t]+PROGBITS[ \t0-9a-f]+WA[ \t]+.* +#pass diff --git a/binutils/testsuite/binutils-all/x86-64/large-sections-2.d b/binutils/testsuite/binutils-all/x86-64/large-sections-2.d new file mode 100644 index 0000000..29ace42 --- /dev/null +++ b/binutils/testsuite/binutils-all/x86-64/large-sections-2.d @@ -0,0 +1,15 @@ +#source: large-sections.s +#PROG: objcopy +#as: --64 +#objcopy: --set-section-flags .ldata=alloc +#readelf: -S -W + +#... + \[[ 0-9]+\] \.text.*[ \t]+PROGBITS[ \t0-9a-f]+AX[ \t]+.* +#... + \[[ 0-9]+\] \.data.*[ \t]+PROGBITS[ \t0-9a-f]+WA[ \t]+.* +#... + \[[ 0-9]+\] \.ltext.*[ \t]+PROGBITS[ \t0-9a-f]+AXl[ \t]+.* +#... + \[[ 0-9]+\] \.ldata.*[ \t]+PROGBITS[ \t0-9a-f]+WA[ \t]+.* +#pass diff --git a/binutils/testsuite/binutils-all/x86-64/large-sections-i386.d b/binutils/testsuite/binutils-all/x86-64/large-sections-i386.d new file mode 100644 index 0000000..b06c7c9 --- /dev/null +++ b/binutils/testsuite/binutils-all/x86-64/large-sections-i386.d @@ -0,0 +1,6 @@ +#source: large-sections.s +#PROG: objcopy +#as: --64 +#objcopy: -O elf32-i386 --set-section-flags .data=alloc,large +#target: x86_64-*-linux* +#error: \A[^[]*\[.data\]: 'large' flag is ELF x86-64 specific diff --git a/binutils/testsuite/binutils-all/x86-64/large-sections.d b/binutils/testsuite/binutils-all/x86-64/large-sections.d new file mode 100644 index 0000000..5d945e4 --- /dev/null +++ b/binutils/testsuite/binutils-all/x86-64/large-sections.d @@ -0,0 +1,14 @@ +#PROG: objcopy +#as: --64 +#objcopy: --set-section-flags .text=alloc,readonly,code,large --set-section-flags .data=alloc,large +#readelf: -S -W + +#... + \[[ 0-9]+\] \.text.*[ \t]+PROGBITS[ \t0-9a-f]+AXl[ \t]+.* +#... + \[[ 0-9]+\] \.data.*[ \t]+PROGBITS[ \t0-9a-f]+WAl[ \t]+.* +#... + \[[ 0-9]+\] \.ltext.*[ \t]+PROGBITS[ \t0-9a-f]+AXl[ \t]+.* +#... + \[[ 0-9]+\] \.ldata.*[ \t]+PROGBITS[ \t0-9a-f]+WAl[ \t]+.* +#pass diff --git a/binutils/testsuite/binutils-all/x86-64/large-sections.s b/binutils/testsuite/binutils-all/x86-64/large-sections.s new file mode 100644 index 0000000..072e456 --- /dev/null +++ b/binutils/testsuite/binutils-all/x86-64/large-sections.s @@ -0,0 +1,8 @@ + .section .text, "ax" + nop + .section .data, "aw" + .byte 1 + .section .ltext, "axl" + nop + .section .ldata, "awl" + .byte 1 |