diff options
Diffstat (limited to 'gas')
-rw-r--r-- | gas/ChangeLog | 22 | ||||
-rw-r--r-- | gas/NEWS | 2 | ||||
-rw-r--r-- | gas/config/obj-elf.c | 56 | ||||
-rw-r--r-- | gas/config/obj-elf.h | 2 | ||||
-rw-r--r-- | gas/doc/as.texinfo | 25 | ||||
-rw-r--r-- | gas/testsuite/gas/elf/elf.exp | 1 | ||||
-rw-r--r-- | gas/testsuite/gas/elf/section10.d | 36 | ||||
-rw-r--r-- | gas/testsuite/gas/elf/section10.s | 35 | ||||
-rw-r--r-- | gas/testsuite/gas/i386/ilp32/x86-64-unwind.d | 3 | ||||
-rw-r--r-- | gas/testsuite/gas/rx/mvtacgu.d | 8 | ||||
-rw-r--r-- | gas/testsuite/gas/tic6x/scomm-directive-4.d | 4 |
11 files changed, 174 insertions, 20 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog index c72e504..57a34ca 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,25 @@ +2016-02-15 Nick Clifton <nickc@redhat.com> + + * doc/as.texinfo (.section): Document that numeric values can now + be used for the flags and type fields of the ELF target's .section + directive. Add notes about the restrictions on setting flags and + types. + * config/obj-elf.c (obj_elf_change_section): Allow known sections + to be given processor specific section types. Allow processor and + application specific flags of a section to be set after + definition. + (obj_elf_parse_section_letters): Handle parsing numeric values. + (obj_elf_section_type): Handle parsing numeric values. + (obj_elf_section): Allow numeric type values. + * config/obj-elf.h (obj_elf_change_section): Update prototype. + * testsuite/gas/elf/section10.d: New test. + * testsuite/gas/elf/section10.s: Source file for new test. + * testsuite/gas/elf/elf.exp: Run the new test. + * testsuite/gas/i386/ilp32/x86-64-unwind.d: Remove dependency upon + the description of the flags produced by readelf. + * testsuite/gas/tic6x/scomm-directive-4.d: Likewise. + * NEWS: Mention the new feature. + 2016-02-11 Nick Clifton <nickc@redhat.com> PR gas/19614 @@ -1,4 +1,6 @@ -*- text -*- +* Add ability to set section flags and types via numeric values for ELF + based targets. * Add a configure option --enable-x86-relax-relocations to decide whether x86 assembler should generate relax relocations by default. Default to diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index f4726ff..9af349c 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -547,7 +547,7 @@ get_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf) void obj_elf_change_section (const char *name, - int type, + unsigned int type, bfd_vma attr, int entsize, const char *group_name, @@ -621,7 +621,9 @@ obj_elf_change_section (const char *name, && ssect->type != SHT_PREINIT_ARRAY) { /* We allow to specify any type for a .note section. */ - if (ssect->type != SHT_NOTE) + if (ssect->type != SHT_NOTE + /* Processor and application defined types are allowed too. */ + && type < SHT_LOPROC) as_warn (_("setting incorrect section type for %s"), name); } @@ -633,7 +635,8 @@ obj_elf_change_section (const char *name, } } - if (old_sec == NULL && (attr & ~ssect->attr) != 0) + if (old_sec == NULL && ((attr & ~(SHF_MASKOS | SHF_MASKPROC)) + & ~ssect->attr) != 0) { /* As a GNU extension, we permit a .note section to be allocatable. If the linker sees an allocatable .note @@ -682,6 +685,7 @@ obj_elf_change_section (const char *name, override = TRUE; } } + if (!override && old_sec == NULL) attr |= ssect->attr; } @@ -745,6 +749,11 @@ obj_elf_change_section (const char *name, | SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD | SEC_THREAD_LOCAL))) as_warn (_("ignoring changed section attributes for %s"), name); + else + /* FIXME: Maybe we should consider removing a previously set + processor or application specific attribute as suspicious ? */ + elf_section_flags (sec) = attr; + if ((flags & SEC_MERGE) && old_sec->entsize != (unsigned) entsize) as_warn (_("ignoring changed section entity size for %s"), name); } @@ -806,14 +815,26 @@ obj_elf_parse_section_letters (char *str, size_t len, bfd_boolean *is_clone) } default: { - char *bad_msg = _("unrecognized .section attribute: want a,e,w,x,M,S,G,T"); + char *bad_msg = _("unrecognized .section attribute: want a,e,w,x,M,S,G,T or number"); #ifdef md_elf_section_letter bfd_vma md_attr = md_elf_section_letter (*str, &bad_msg); if (md_attr != (bfd_vma) -1) attr |= md_attr; else #endif - as_fatal ("%s", bad_msg); + if (ISDIGIT (*str)) + { + char * end; + + attr |= strtoul (str, & end, 0); + /* Update str and len, allowing for the fact that + we will execute str++ and len-- below. */ + end --; + len -= (end - str); + str = end; + } + else + as_fatal ("%s", bad_msg); } break; } @@ -847,6 +868,17 @@ obj_elf_section_type (char *str, size_t len, bfd_boolean warn) } #endif + if (ISDIGIT (*str)) + { + char * end; + int type = strtoul (str, & end, 0); + + if (warn && (size_t) (end - str) != len) + as_warn (_("extraneous characters at end of numeric section type")); + + return type; + } + if (warn) as_warn (_("unrecognized section type")); return 0; @@ -1046,9 +1078,17 @@ obj_elf_section (int push) else if (c == '@' || c == '%') { ++input_line_pointer; - c = get_symbol_name (& beg); - (void) restore_line_pointer (c); - type = obj_elf_section_type (beg, input_line_pointer - beg, TRUE); + + if (ISDIGIT (* input_line_pointer)) + { + type = strtoul (input_line_pointer, & input_line_pointer, 0); + } + else + { + c = get_symbol_name (& beg); + (void) restore_line_pointer (c); + type = obj_elf_section_type (beg, input_line_pointer - beg, TRUE); + } } else input_line_pointer = save; diff --git a/gas/config/obj-elf.h b/gas/config/obj-elf.h index f3424a5..257d877 100644 --- a/gas/config/obj-elf.h +++ b/gas/config/obj-elf.h @@ -162,7 +162,7 @@ extern void obj_elf_common (int); extern void obj_elf_data (int); extern void obj_elf_text (int); extern void obj_elf_change_section - (const char *, int, bfd_vma, int, const char *, int, int); + (const char *, unsigned int, bfd_vma, int, const char *, int, int); extern struct fix *obj_elf_vtable_inherit (int); extern struct fix *obj_elf_vtable_entry (int); extern bfd_boolean obj_elf_seen_attribute diff --git a/gas/doc/as.texinfo b/gas/doc/as.texinfo index 917781b..86b09fc 100644 --- a/gas/doc/as.texinfo +++ b/gas/doc/as.texinfo @@ -6375,8 +6375,22 @@ section is a member of a section group section is used for thread-local-storage @item ? section is a member of the previously-current section's group, if any +@item @var{number} +a numeric value indicating the bits to be set in the ELF section header's flags +field. Note - if one or more of the alphabetic characters described above is +also included in the flags field, their bit values will be ORed into the +resulting value. +@item @{target specific} +some targets extend this list with their own types @end table +Note - once a section's flags have been set they cannot be changed. There are +a few exceptions to this rule however. Processor and application specific +flags can be added to an already defined section. The @code{.interp}, +@code{.strtab} and @code{.symtab} sections can have the allocate flag +(@code{a}) set after they are initially defined, and the @code{.note-GNU-stack} +section may have the executable (@code(x)) flag added. + The optional @var{type} argument may contain one of the following constants: @table @code @item @@progbits @@ -6391,14 +6405,23 @@ section contains an array of pointers to init functions section contains an array of pointers to finish functions @item @@preinit_array section contains an array of pointers to pre-init functions +@item @@@var{number} +a numeric value to be set as the ELF section header's type field. +@item @@@{target specific} +some targets extend this list with their own types @end table -Many targets only support the first three section types. +Many targets only support the first three section types. The type may be +enclosed in double quotes if necessary. Note on targets where the @code{@@} character is the start of a comment (eg ARM) then another character is used instead. For example the ARM port uses the @code{%} character. +Note - some sections, eg @code{.text} and @code{.data} are considered to be +special and have fixed types. Any attempt to declare them with a different +type will generate an error from the assembler. + If @var{flags} contains the @code{M} symbol then the @var{type} argument must be specified as well as an extra argument---@var{entsize}---like this: diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp index 1c94016..40dfd12 100644 --- a/gas/testsuite/gas/elf/elf.exp +++ b/gas/testsuite/gas/elf/elf.exp @@ -201,6 +201,7 @@ if { [is_elf_format] } then { run_dump_test "section7" run_dump_test "section8" run_dump_test "section9" + run_dump_test "section10" run_dump_test "dwarf2-1" run_dump_test "dwarf2-2" run_dump_test "dwarf2-3" diff --git a/gas/testsuite/gas/elf/section10.d b/gas/testsuite/gas/elf/section10.d new file mode 100644 index 0000000..aa5ca3c --- /dev/null +++ b/gas/testsuite/gas/elf/section10.d @@ -0,0 +1,36 @@ +#readelf: -N --wide +#name: numeric section flags and types +# The RX port annoyingly reorders the sections so that they do not match the sequence expected below. +#skip: rx-*-* + +#... +[ ]*\[.*\][ ]+.text +[ ]*PROGBITS.* +[ ]*\[.*4000006\]: ALLOC, EXEC, OS \(.*4000000\) +#... +[ ]*\[.*\][ ]+sec1 +[ ]*PROGBITS.* +[ ]*\[.*6000000\]: OS \(.*6000000\) +[ ]*\[.*\][ ]+sec2 +[ ]*PROGBITS.* +[ ]*\[0+00806\]: ALLOC, EXEC, COMPRESSED +[ ]*\[<unknown>: 0x[0-9]+\], .* +#... +[ ]*\[.*\][ ]+sec3 +[ ]*PROGBITS.* +[ ]*\[.*ffff030\]: MERGE, STRINGS,.* EXCLUDE, OS \(.*ff00000\), PROC \(.*[347]0000000\), UNKNOWN \(0+0ff000\) +#... +[ ]*\[.*\][ ]+sec4 +[ ]*LOOS\+0x11[ ].* +[ ]*\[0+06\]: ALLOC, EXEC +#... +[ ]*\[.*\][ ]+sec5 +[ ]*LOUSER\+0x9[ ].* +[ ]*\[.*fff0000\]:.* EXCLUDE, OS \(.*ff00000\), PROC \(.*[347]0000000\), UNKNOWN \(.*f0000\) +[ ]*\[.*\][ ]+.data.foo +[ ]*LOUSER\+0x7f000000[ ].* +[ ]*\[0+003\]: WRITE, ALLOC +[ ]*\[.*\][ ]+sec6 +[ ]*0000162e: <unknown>[ ].* +[ ]*\[.*120004\]: EXEC, OS \(.*100000\), UNKNOWN \(.*20000\) +#pass diff --git a/gas/testsuite/gas/elf/section10.s b/gas/testsuite/gas/elf/section10.s new file mode 100644 index 0000000..0576007 --- /dev/null +++ b/gas/testsuite/gas/elf/section10.s @@ -0,0 +1,35 @@ + # Test numeric values for the section's flags field. + .section sec1, "0x06000000" + .word 1 + + # Make sure that a numeric value can be mixed with alpha values. + .section sec2, "a2048x" + .word 2 + + # Make sure that specifying further arguments to .sections is still supported + .section sec3, "0xfffff000MS", %progbits, 32 + .word 3 + + # Make sure that extra flags can be set for well known sections as well. + .section .text, "0x04000006" + .word 4 + + # Test numeric values for the section's type field. + .section sec4, "ax", %0x60000011 + .word 5 + + # Test both together, with a quoted type value. + .section sec5, "0xffff0000", "0x80000009" + .word 6 + + # Test that declaring an extended version of a known special section works. + .section .data.foo, "aw", %0xff000000 + .word 7 + + # Check that .pushsection works as well. + .pushsection sec6, 2, "0x120004", %5678 + .word 8 + + .popsection + + # FIXME: We ought to check setting 64-bit flag values for 64-bit ELF targets... diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-unwind.d b/gas/testsuite/gas/i386/ilp32/x86-64-unwind.d index 4f6f155..0bac7a2 100644 --- a/gas/testsuite/gas/i386/ilp32/x86-64-unwind.d +++ b/gas/testsuite/gas/i386/ilp32/x86-64-unwind.d @@ -15,7 +15,4 @@ Section Headers: \[ 6\] .symtab SYMTAB 00000000 [0-9a-f]+ 000050 10 7 5 4 \[ 7\] .strtab STRTAB 00000000 [0-9a-f]+ 000001 00 0 0 1 Key to Flags: - W \(write\), A \(alloc\), X \(execute\), M \(merge\), S \(strings\), l \(large\) - I \(info\), L \(link order\), G \(group\), T \(TLS\), E \(exclude\), x \(unknown\) - O \(extra OS processing required\) o \(OS specific\), p \(processor specific\) #pass diff --git a/gas/testsuite/gas/rx/mvtacgu.d b/gas/testsuite/gas/rx/mvtacgu.d index 96fe2ce..07053d0 100644 --- a/gas/testsuite/gas/rx/mvtacgu.d +++ b/gas/testsuite/gas/rx/mvtacgu.d @@ -6,7 +6,7 @@ dump\.o: file format .* Disassembly of section \.text: 00000000 <\.text>: - 0: fd 17 30 mvtacgu r0, a0 - 3: fd 17 3f mvtacgu r15, a0 - 6: fd 17 b0 mvtacgu r0, a1 - 9: fd 17 bf mvtacgu r15, a1 + 0: fd 17 30 mvtacgu a0, r0 + 3: fd 17 3f mvtacgu a0, r15 + 6: fd 17 b0 mvtacgu a1, r0 + 9: fd 17 bf mvtacgu a1, r15 diff --git a/gas/testsuite/gas/tic6x/scomm-directive-4.d b/gas/testsuite/gas/tic6x/scomm-directive-4.d index 18497ec..7822e8f 100644 --- a/gas/testsuite/gas/tic6x/scomm-directive-4.d +++ b/gas/testsuite/gas/tic6x/scomm-directive-4.d @@ -16,9 +16,7 @@ Section Headers: \[ 6\] \.symtab SYMTAB 00000000 [0-9a-f]+ 0000d0 10 7 5 4 \[ 7\] \.strtab STRTAB 00000000 [0-9a-f]+ 00001d 00 0 0 1 Key to Flags: - W \(write\), A \(alloc\), X \(execute\), M \(merge\), S \(strings\) - I \(info\), L \(link order\), G \(group\), T \(TLS\), E \(exclude\), x \(unknown\) - O \(extra OS processing required\) o \(OS specific\), p \(processor specific\) +#... Symbol table '\.symtab' contains 13 entries: Num: Value Size Type Bind Vis Ndx Name |