diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-02-16 04:55:42 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-02-16 04:55:53 -0800 |
commit | ca1289b9f3b6c9854386d1373918978412a59f94 (patch) | |
tree | 108abbbfcc9936c592fd7fd0b0bec027434efc17 /gas/config/obj-elf.c | |
parent | 394ae71f026cf62beb30511da42c8198da90d82d (diff) | |
download | binutils-ca1289b9f3b6c9854386d1373918978412a59f94.zip binutils-ca1289b9f3b6c9854386d1373918978412a59f94.tar.gz binutils-ca1289b9f3b6c9854386d1373918978412a59f94.tar.bz2 |
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.
Diffstat (limited to 'gas/config/obj-elf.c')
-rw-r--r-- | gas/config/obj-elf.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index f52dc69..2fb8ccd 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -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)) |