gas: Allow SHF_GNU_RETAIN on all sections

Since SHF_GNU_RETAIN is allowed on all sections, strip SHF_GNU_RETAIN
when checking incorrect section attributes.

	PR gas/27412
	* config/obj-elf.c (obj_elf_change_section): Strip SHF_GNU_RETAIN
	when checking incorrect section attributes.
	* testsuite/gas/elf/elf.exp: Run section28 and section29.
	* testsuite/gas/elf/section28.d: New file.
	* testsuite/gas/elf/section28.s: Likewise.
	* testsuite/gas/elf/section29.d: Likewise.
	* testsuite/gas/elf/section29.s: Likewise.
This commit is contained in:
H.J. Lu
2021-02-16 04:55:42 -08:00
parent 394ae71f02
commit ca1289b9f3
7 changed files with 66 additions and 6 deletions

View File

@@ -667,39 +667,45 @@ obj_elf_change_section (const char *name,
| SHF_MASKPROC))
& ~ssect->attr) != 0)
{
/* Strip SHF_GNU_RETAIN. */
bfd_vma generic_attr = attr;
if (elf_tdata (stdoutput)->has_gnu_osabi)
generic_attr &= ~SHF_GNU_RETAIN;
/* As a GNU extension, we permit a .note section to be
allocatable. If the linker sees an allocatable .note
section, it will create a PT_NOTE segment in the output
file. We also allow "x" for .note.GNU-stack. */
if (ssect->type == SHT_NOTE
&& (attr == SHF_ALLOC || attr == SHF_EXECINSTR))
&& (generic_attr == SHF_ALLOC
|| generic_attr == SHF_EXECINSTR))
;
/* Allow different SHF_MERGE and SHF_STRINGS if we have
something like .rodata.str. */
else if (ssect->suffix_length == -2
&& name[ssect->prefix_length] == '.'
&& (attr
&& (generic_attr
& ~ssect->attr
& ~SHF_MERGE
& ~SHF_STRINGS) == 0)
;
/* .interp, .strtab and .symtab can have SHF_ALLOC. */
else if (attr == SHF_ALLOC
else if (generic_attr == SHF_ALLOC
&& (strcmp (name, ".interp") == 0
|| strcmp (name, ".strtab") == 0
|| strcmp (name, ".symtab") == 0))
override = TRUE;
/* .note.GNU-stack can have SHF_EXECINSTR. */
else if (attr == SHF_EXECINSTR
else if (generic_attr == SHF_EXECINSTR
&& strcmp (name, ".note.GNU-stack") == 0)
override = TRUE;
#ifdef TC_ALPHA
/* A section on Alpha may have SHF_ALPHA_GPREL. */
else if ((attr & ~ssect->attr) == SHF_ALPHA_GPREL)
else if ((generic_attr & ~ssect->attr) == SHF_ALPHA_GPREL)
override = TRUE;
#endif
#ifdef TC_RX
else if (attr == (SHF_EXECINSTR | SHF_WRITE | SHF_ALLOC)
else if (generic_attr == (SHF_EXECINSTR | SHF_WRITE | SHF_ALLOC)
&& (ssect->type == SHT_INIT_ARRAY
|| ssect->type == SHT_FINI_ARRAY
|| ssect->type == SHT_PREINIT_ARRAY))