+2021-02-16 H.J. Lu <hongjiu.lu@intel.com>
+
+ 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.
+
2021-02-16 Jan Beulich <jbeulich@suse.com>
* testsuite/gas/i386/sse-check.s,
| 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))
run_dump_test "section25"
run_dump_test "section26"
run_dump_test "section27"
+ run_dump_test "section28"
+ run_dump_test "section29"
run_dump_test "sh-link-zero"
run_dump_test "dwarf2-1" $dump_opts
run_dump_test "dwarf2-2" $dump_opts
--- /dev/null
+#readelf: -h -S --wide
+#name: SHF_GNU_RETAIN sections 28
+#notarget: ![supports_gnu_osabi]
+
+#...
+ +OS/ABI: +UNIX - (GNU|FreeBSD)
+#...
+ \[..\] \.note\.Linux +NOTE +[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 +A +0.*
+#...
+ \[..\] \.note\.Linux +NOTE +[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 +AR +0.*
+#...
+ \[..\] \.note\.foo +NOTE +[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 +0 +.*
+#...
+ \[..\] \.note\.foo +NOTE +[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 +R +0 +.*
+#pass