Add command line option to stop the assembler from padding the end of sections to...
authorNick Clifton <nickc@redhat.com>
Mon, 27 Jun 2016 12:49:09 +0000 (13:49 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 27 Jun 2016 12:51:06 +0000 (13:51 +0100)
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
gas/as.c
gas/as.h
gas/doc/as.texinfo
gas/testsuite/gas/elf/elf.exp
gas/testsuite/gas/elf/section11.d [new file with mode: 0644]
gas/testsuite/gas/elf/section11.s [new file with mode: 0644]
gas/write.c

index a0990602826158b9fd1633220081a16f55e40ebf..08807f18f1615c5ebf1413bac6a997bb9bdc3b95 100644 (file)
--- 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.
index badeac9bee329d9ab9f0e5580f98039b722fcd5e..8784fb481c06fa3a77793d739d087552845bea70 100644 (file)
--- 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;
index 51e16f11bf8f5aa03b73aa1f2293a8cfb6f4f187..169c714adb2cb61bd2bcaec792397f9b31ab1d81 100644 (file)
--- 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;
 
index 6d2c325798d585115f3e80aade9416838888f36c..9ebfda007101df6b269c0b67591039c776fafd02 100644 (file)
@@ -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
index 95c9204e4696de655945e1c04404812edb448ef2..3e85ae21646699c3e02c465331e2ba6cffe0ee23 100644 (file)
@@ -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 (file)
index 0000000..c1043db
--- /dev/null
@@ -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 (file)
index 0000000..200d34c
--- /dev/null
@@ -0,0 +1,14 @@
+.section .bss
+.balign 16
+.skip 1
+
+
+.data
+.balign 16
+.skip 1
+
+
+.text
+.balign 16
+.skip 1
+
index 0dfca0c01c3b88d4b1201fd1be3b9bf0b4985a92..9af1f80f08fc4268bd86e9b22ed94537b8f383d4 100644 (file)
@@ -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
This page took 0.034948 seconds and 4 git commands to generate.