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.
This commit is contained in:
Fangrui Song
2023-07-09 10:57:19 -07:00
committed by Fangrui Song
parent 4fb2abb59d
commit 5e24da908d
13 changed files with 155 additions and 10 deletions

View File

@@ -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;
}