[PATCH v3] PR30592 objcopy: allow --set-section-flags to add or remove SHF_X86_64_LARGE

Alan Modra amodra@gmail.com
Fri Jul 7 08:24:27 GMT 2023


On Thu, Jul 06, 2023 at 10:43:06PM -0700, Fangrui Song via Binutils wrote:
> include/
>     * elf/common.h: Define SHF_X86_64_LARGE to be used by elf.c.

Don't do this.

> --- a/bfd/elf.c
> +++ b/bfd/elf.c
> @@ -1045,6 +1045,11 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
>    if ((hdr->sh_flags & SHF_EXCLUDE) != 0)
>      flags |= SEC_EXCLUDE;
>  
> +  bed = get_elf_backend_data (abfd);
> +  if (bed->elf_machine_code == EM_X86_64 &&
> +      (hdr->sh_flags & SHF_X86_64_LARGE) != 0)
> +    flags |= SEC_ELF_LARGE;

Or this.  Instead write an elf_backend_section_flags for x86_64.

> @@ -3912,6 +3916,8 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg)
>      }
>    if ((asect->flags & (SEC_GROUP | SEC_EXCLUDE)) == SEC_EXCLUDE)
>      this_hdr->sh_flags |= SHF_EXCLUDE;
> +  if (bed->elf_machine_code == EM_X86_64 && (asect->flags & SEC_ELF_LARGE) != 0)
> +    this_hdr->sh_flags |= SHF_X86_64_LARGE;
>  

Or this.  Instead write elf_backend_fake_sections for x86_64.

>    /* If the section has relocs, set up a section header for the
>       SHT_REL[A] section.  If two relocation sections are required for
> @@ -8508,6 +8514,10 @@ _bfd_elf_init_private_section_data (bfd *ibfd,
>    elf_section_flags (osec) = (elf_section_flags (isec)
>  			      & (SHF_MASKOS | SHF_MASKPROC));
>  
> +  /* objcopy --set-section-flags without "large" drops SHF_X86_64_LARGE.  */
> +  if (get_elf_backend_data (ibfd)->elf_machine_code == EM_X86_64)
> +    elf_section_flags (osec) = (elf_section_flags (isec) & ~SHF_X86_64_LARGE);
> +
>    /* Copy sh_info from input for mbind section.  */
>    if ((elf_tdata (ibfd)->has_gnu_osabi & elf_gnu_osabi_mbind) != 0
>        && elf_section_flags (isec) & SHF_GNU_MBIND)

And this should be done in a bfd_elf64_bfd_copy_private_symbol_data
for x86_64.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list