[PATCH] ld: Handle special ELF readonly output sections

Jan Beulich jbeulich@suse.com
Wed Apr 22 08:04:03 GMT 2026


On 31.03.2026 20:15, H.J. Lu wrote:
> @@ -3309,7 +3308,25 @@ _bfd_elf_get_sec_type_attr (bfd *abfd, asection *sec)
>    if (spec == NULL)
>      return NULL;
>  
> -  return _bfd_elf_get_special_section (sec->name, spec, sec->use_rela_p);
> +  return _bfd_elf_get_special_section (name, spec, use_rela_p);
> +}
> +
> +const struct bfd_elf_special_section *
> +_bfd_elf_get_sec_type_attr (bfd *abfd, asection *sec)
> +{
> +  return elf_get_special_section (abfd, sec->name, sec->use_rela_p);
> +}
> +
> +bool
> +_bfd_elf_is_special_readonly_section (bfd *abfd, const char *name)
> +{
> +  elf_backend_data *bed;
> +  const struct bfd_elf_special_section *spec;
> +  bed = get_elf_backend_data (abfd);
> +  spec = elf_get_special_section (abfd, name, bed->default_use_rela_p);
> +  if (spec == NULL)
> +    return false;
> +  return (spec->attr & SHF_WRITE) == 0;
>  }

This once again being solely name-based, ...

> --- /dev/null
> +++ b/ld/testsuite/ld-elf/flags2.ld
> @@ -0,0 +1 @@
> +SECTIONS { .rodata : ALIGN(4) { __crc_hello = .; LONG(0x05d25769); } }

... what's wrong with using the READONLY keyword here instead? If people
create a section solely(?) from a linker script, can't they be expected
to set the section's properties correctly? While it's against conventions,
someone wanting a writable .rodata section ought to be able to get one.
Much like they can from e.g. an assembly source file.

Related, but not for this patch: Seeing get_os_init_flag(), why is
typed_readonly_section not also resulting in SEC_READONLY there?

> --- /dev/null
> +++ b/ld/testsuite/ld-elf/flags2.s
> @@ -0,0 +1,6 @@
> +	.text
> +	.globl	start
> +	.type	start, %function
> +start:
> +	.byte 0
> +	.section .note.GNU-stack, "", %progbits

I think new testcases better wouldn't use %progbits for .note.GNU-stack
anymore.

Jan


More information about the Binutils mailing list