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

Fangrui Song maskray@google.com
Sun Jul 9 17:46:10 GMT 2023


On 2023-07-09, Alan Modra wrote:
>On Fri, Jul 07, 2023 at 10:30:35PM -0700, Fangrui Song via Binutils wrote:
>> +static bool
>> +elf_x86_64_copy_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED,
>> +				      asection *isec,
>> +				      bfd *obfd ATTRIBUTE_UNUSED,
>> +				      asection *osec) {
>> +  /* objcopy --set-section-flags without "large" drops SHF_X86_64_LARGE.  */
>> +  elf_section_flags (osec) = (elf_section_flags (isec) & ~SHF_X86_64_LARGE);
>> +
>> +  return true;
>> +}
>> +
>
>Unlike the other two functions, this one replaces the standard
>_bfd_elf_copy_private_section_data.  You'll want to call it, and
>distinguish between a call from objcopy.c and a call from ldwrite.c.
>I think you're OK accessing elf_section_flags for osec without first
>checking for an elf bfd, because bfd_copy_private_section_data invokes
>the obfd xvec function.  Like this:
>
>static bool
>elf_x86_64_copy_private_section_data (bfd *ibfd, asection *isec,
>				      bfd *obfd, asection *osec)
>{
>  if (!_bfd_elf_copy_private_section_data (ibfd, isec, obfd, osec))
>    return false;
>
>  /* objcopy --set-section-flags without "large" drops SHF_X86_64_LARGE.  */
>  if (ibfd != obfd)
>    elf_section_flags (osec) &= ~SHF_X86_64_LARGE;
>
>  return true;
>}
>
>The patch looks OK to me with the above replacement.

Thank you.  I see that we need to call _bfd_elf_copy_private_section_data  first to
respect a few other properties including sh_entsize and "readonly".

For objcopy -I binary -O elf64-x86-64 pr25749-2.c a.o,
ibfd may not be an ELF bfd, but obfd is guaranteed to be an ELF bfd.

ld/ldwrite.c calls bfd_copy_private_section_data with ibfd == obfd.


More information about the Binutils mailing list