From 2edb36e77f3ff468eac2b2c8954e9c031148e724 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mon, 27 Jun 2016 13:49:09 +0100 Subject: [PATCH] Add command line option to stop the assembler from padding the end of sections to their alignment boundary. PR gas/20247 * as.h (do_not_pad_sections_to_alignment): New global variable. * as.c (show_usage): Add --no-pad-sections. (parse_args): Likewise. * write.c (size_seg): Skip padding the end of the section if requested from the command line. (SUB_SEGMENT_ALIGN): Likewise. * doc/as.texinfo: Document the new option. * NEWS: Mention the new feature. * testsuite/gas/elf/section11.s: New test. * testsuite/gas/elf/section11.d: New test driver. * testsuite/gas/elf/elf.exp: Run the new test. --- gas/NEWS | 3 +++ gas/as.c | 10 +++++++++- gas/as.h | 6 ++++-- gas/doc/as.texinfo | 18 +++++++++++++++++- gas/testsuite/gas/elf/elf.exp | 1 + gas/testsuite/gas/elf/section11.d | 13 +++++++++++++ gas/testsuite/gas/elf/section11.s | 14 ++++++++++++++ gas/write.c | 10 ++++++++-- 8 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 gas/testsuite/gas/elf/section11.d create mode 100644 gas/testsuite/gas/elf/section11.s diff --git a/gas/NEWS b/gas/NEWS index a099060282..08807f18f1 100644 --- a/gas/NEWS +++ b/gas/NEWS @@ -1,4 +1,7 @@ -*- text -*- +* Add --no-pad-sections to stop the assembler from padding the end of output + sections up to their alignment boundary. + * Support for the ARMv8-M architecture has been added to the ARM port. Support for the ARMv8-M Security and DSP Extensions has also been added to the ARM port. diff --git a/gas/as.c b/gas/as.c index badeac9bee..8784fb481c 100644 --- a/gas/as.c +++ b/gas/as.c @@ -342,6 +342,8 @@ Options:\n\ fprintf (stream, _("\ -nocpp ignored\n")); fprintf (stream, _("\ + -no-pad-sections do not pad the end of sections to alignment boundaries\n")); + fprintf (stream, _("\ -o OBJFILE name the object-file output OBJFILE (default a.out)\n")); fprintf (stream, _("\ -R fold data section into text section\n")); @@ -479,7 +481,8 @@ parse_args (int * pargc, char *** pargv) OPTION_REDUCE_MEMORY_OVERHEADS, OPTION_WARN_FATAL, OPTION_COMPRESS_DEBUG, - OPTION_NOCOMPRESS_DEBUG + OPTION_NOCOMPRESS_DEBUG, + OPTION_NO_PAD_SECTIONS /* = STD_BASE + 40 */ /* When you add options here, check that they do not collide with OPTION_MD_BASE. See as.h. */ }; @@ -542,6 +545,7 @@ parse_args (int * pargc, char *** pargv) ,{"MD", required_argument, NULL, OPTION_DEPFILE} ,{"mri", no_argument, NULL, 'M'} ,{"nocpp", no_argument, NULL, OPTION_NOCPP} + ,{"no-pad-sections", no_argument, NULL, OPTION_NO_PAD_SECTIONS} ,{"no-warn", no_argument, NULL, 'W'} ,{"reduce-memory-overheads", no_argument, NULL, OPTION_REDUCE_MEMORY_OVERHEADS} ,{"statistics", no_argument, NULL, OPTION_STATISTICS} @@ -637,6 +641,10 @@ parse_args (int * pargc, char *** pargv) case OPTION_NOCPP: break; + case OPTION_NO_PAD_SECTIONS: + do_not_pad_sections_to_alignment = 1; + break; + case OPTION_STATISTICS: flag_print_statistics = 1; break; diff --git a/gas/as.h b/gas/as.h index 51e16f11bf..169c714adb 100644 --- a/gas/as.h +++ b/gas/as.h @@ -76,8 +76,8 @@ 150 isn't special; it's just an arbitrary non-ASCII char value. */ #define OPTION_STD_BASE 150 /* The first getopt value for machine-dependent long options. - 190 gives the standard options room to grow. */ -#define OPTION_MD_BASE 190 + 290 gives the standard options room to grow. */ +#define OPTION_MD_BASE 290 #ifdef DEBUG #undef NDEBUG @@ -377,6 +377,8 @@ COMMON int need_pass_2; leave lots of padding. */ COMMON int linkrelax; +COMMON int do_not_pad_sections_to_alignment; + /* TRUE if we should produce a listing. */ extern int listing; diff --git a/gas/doc/as.texinfo b/gas/doc/as.texinfo index 6d2c325798..9ebfda0071 100644 --- a/gas/doc/as.texinfo +++ b/gas/doc/as.texinfo @@ -235,6 +235,7 @@ gcc(1), ld(1), and the Info entries for @file{binutils} and @file{ld}. [@b{-K}] [@b{-L}] [@b{--listing-lhs-width}=@var{NUM}] [@b{--listing-lhs-width2}=@var{NUM}] [@b{--listing-rhs-width}=@var{NUM}] [@b{--listing-cont-lines}=@var{NUM}] [@b{--keep-locals}] + [@b{--no-pad-sections}] [@b{-o} @var{objfile}] [@b{-R}] [@b{--hash-size}=@var{NUM}] [@b{--reduce-memory-overheads}] [@b{--statistics}] @@ -773,6 +774,11 @@ Set the maximum width of an input source line, as displayed in a listing, to Set the maximum number of lines printed in a listing for a single line of input to @var{number} + 1. +@item --no-pad-sections +Stop the assembler for padding the ends of output sections to the alignment +of that section. The default is to pad the sections, but this can waste space +which might be needed on targets which have tight memory constraints. + @item -o @var{objfile} Name the object-file output from @command{@value{AS}} @var{objfile}. @@ -2158,6 +2164,7 @@ assembler.) * listing:: --listing-XXX to configure listing output * M:: -M or --mri to assemble in MRI compatibility mode * MD:: --MD for dependency tracking +* no-pad-sections:: --no-pad-sections to stop section padding * o:: -o to name the object file * R:: -R to join data and text sections * statistics:: --statistics to see statistics about assembly @@ -2494,6 +2501,15 @@ The rule is written to the file named in its argument. This feature is used in the automatic updating of makefiles. +@node no-pad-sections +@section Output Section Padding +@kindex --no-pad-sections +@cindex output section padding +Normally the assembler will pad the end of each output section up to its +alignment boundary. But this can waste space, which can be significant on +memory constrained targets. So the @option{--no-pad-sections} option will +disable this behaviour. + @node o @section Name the Object File: @option{-o} @@ -2680,7 +2696,7 @@ do include file processing with the @code{.include} directive (@pxref{Include,,@code{.include}}). You can use the @sc{gnu} C compiler driver to get other ``CPP'' style preprocessing by giving the input file a @samp{.S} suffix. @xref{Overall Options, ,Options Controlling the Kind of -Output, gcc.info, Using GNU CC} . +Output, gcc info, Using GNU CC}. Excess whitespace, comments, and character constants cannot be used in the portions of the input text that are not diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp index 95c9204e46..3e85ae2164 100644 --- a/gas/testsuite/gas/elf/elf.exp +++ b/gas/testsuite/gas/elf/elf.exp @@ -205,6 +205,7 @@ if { [is_elf_format] } then { run_dump_test "section8" run_dump_test "section9" run_dump_test "section10" + run_dump_test "section11" run_dump_test "dwarf2-1" run_dump_test "dwarf2-2" run_dump_test "dwarf2-3" diff --git a/gas/testsuite/gas/elf/section11.d b/gas/testsuite/gas/elf/section11.d new file mode 100644 index 0000000000..c1043db7a0 --- /dev/null +++ b/gas/testsuite/gas/elf/section11.d @@ -0,0 +1,13 @@ +#as: --no-pad-sections +#readelf: -S --wide +#name: Disabling section padding +# The RX port uses non standard section names. +#skip: rx-*-* + +#... + \[ .\] .text[ ]+PROGBITS[ ]+0+00 0+[0-9a-f]+ 0+0(1|4|5) 00 AX 0 0 16 +#... + \[ .\] .data[ ]+PROGBITS[ ]+0+00 0+[0-9a-f]+ 0+01 00 WA 0 0 16 +#... + \[ .\] .bss[ ]+NOBITS[ ]+0+00 0+[0-9a-f]+ 0+01 00 WA 0 0 16 +#pass diff --git a/gas/testsuite/gas/elf/section11.s b/gas/testsuite/gas/elf/section11.s new file mode 100644 index 0000000000..200d34c7ae --- /dev/null +++ b/gas/testsuite/gas/elf/section11.s @@ -0,0 +1,14 @@ +.section .bss +.balign 16 +.skip 1 + + +.data +.balign 16 +.skip 1 + + +.text +.balign 16 +.skip 1 + diff --git a/gas/write.c b/gas/write.c index 0dfca0c01c..9af1f80f08 100644 --- a/gas/write.c +++ b/gas/write.c @@ -579,7 +579,12 @@ size_seg (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) x = bfd_set_section_flags (abfd, sec, flags); gas_assert (x); - newsize = md_section_align (sec, size); + /* If permitted, allow the backend to pad out the section + to some alignment boundary. */ + if (do_not_pad_sections_to_alignment) + newsize = size; + else + newsize = md_section_align (sec, size); x = bfd_set_section_size (abfd, sec, newsize); gas_assert (x); @@ -1696,7 +1701,7 @@ set_symtab (void) } /* Finish the subsegments. After every sub-segment, we fake an - ".align ...". This conforms to BSD4.2 brane-damage. We then fake + ".align ...". This conforms to BSD4.2 brain-damage. We then fake ".fill 0" because that is the kind of frag that requires least thought. ".align" frags like to have a following frag since that makes calculating their intended length trivial. */ @@ -1708,6 +1713,7 @@ set_symtab (void) code-bearing sections. */ #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \ (!(FRCHAIN)->frch_next && subseg_text_p (SEG) \ + && !do_not_pad_sections_to_alignment \ ? get_recorded_alignment (SEG) \ : 0) #else