This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Implementing -fdata-sections for uninitialised data (resubmission)
- To: gcc-patches at gcc dot gnu dot org
- Subject: Implementing -fdata-sections for uninitialised data (resubmission)
- From: Nick Clifton <nickc at cygnus dot com>
- Date: Mon, 3 Jan 2000 12:32:35 -0800
Hi Guys,
This is a resubmission of a patch which I submitted last year, but
which appears to have fallen through the cracks and not been
reviewed.
This patch adds the ability to generate unique sections for data
that is going to go in the .bss section. Together with the
--gc-sections command line switch this will allow the gnu linker to
discard any uninitialised variables that are not referenced by any
code, saving space in the resulting executable.
Note that this feature is only enabled if the -fdata-sections
command line switch is given to GCC, and then only if the new target
macros ASM_OUTPUT_SHARED_BSS or ASM_OUTPUT_SHARED_LOCAL are
defined. Since no port currently defines these macros, this patch
cannot affect current code generation. (I have an implementation of
these macros for the arm-elf toolchain, which works for the eCos
sources).
This patch also needs a small addition to the linker script of
whichever toolchain actually uses it. I will be submitting a simple
patch to binutils to do this for the default elf linker script.
(And yes, Geoff, I will fix up .sbss too...)
Note - this patch makes no attempt to generate unique section names
for common variables. There are two reasons for this. Firstly
common variables are typically generated by issuing the .comm
assembler pseudo op, and it is the assembler which is responsible
for switching to the .comm section, generating the symbol and
assigning a size to it. Hence it would be necessary to either
extend the assembler so that the .comm directive could take a
section name, or else bypass the assembler completely and generate
the .comm entry manually.
The second reason is that the linker will treat entries in the .comm
section specially, (ie it will treat them as common) and I was not
sure if this behaviour would be extended to sections named, for
example .comm.foo.
Of course these problems could be fixed, but there is currently no
demand for them, so why complicate this patch ?
Is it OK to apply this patch ?
Cheers
Nick
2000-01-03 Nick Clifton <nickc@cygnus.com>
* varasm.c (asm_emit_uninitialised): If flag_data_sections is
true, then attempt to use ASM_OUTPUT_UNIQUE_BSS or
ASM_OUTPUT_UNIQUE_LOCAL to emit the variable.
* tm.texi (ASM_OUTPUT_UNIQUE_BSS): Document new target macro.
(ASM_OUTPUT_UNIQUE_LOCAL): Document new target macro.
Index: gcc/varasm.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/varasm.c,v
retrieving revision 1.91
diff -p -r1.91 varasm.c
*** varasm.c 1999/12/20 13:18:16 1.91
--- varasm.c 2000/01/03 20:27:29
*************** asm_emit_uninitialised (decl, name, size
*** 1274,1279 ****
--- 1274,1299 ----
}
}
+ if (flag_data_sections)
+ {
+ switch (destination)
+ {
+ #ifdef ASM_OUTPUT_UNIQUE_BSS
+ case asm_dest_bss:
+ ASM_OUTPUT_UNIQUE_BSS (asm_out_file, decl, name, size);
+ return;
+ #endif
+ #ifdef ASM_OUTPUT_UNIQUE_LOCAL
+ case asm_dest_local:
+ ASM_OUTPUT_UNIQUE_LOCAL (asm_out_file, decl, name, size);
+ return;
+ #endif
+ case asm_dest_common:
+ default:
+ break;
+ }
+ }
+
switch (destination)
{
#ifdef ASM_EMIT_BSS
Index: gcc/tm.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tm.texi,v
retrieving revision 1.99
diff -p -r1.99 tm.texi
*** tm.texi 1999/11/30 12:16:55 1.99
--- tm.texi 2000/01/03 20:27:30
*************** If defined, it is similar to @code{ASM_O
*** 5479,5484 ****
--- 5479,5491 ----
is used when @var{name} is shared. If not defined, @code{ASM_OUTPUT_BSS}
will be used.
+ @findex ASM_OUTPUT_UNIQUE_BSS
+ @item ASM_OUTPUT_UNIQUE_BSS (@var{stream}, @var{decl}, @var{name}, @var{size})
+ If defined, it is similar to @code{ASM_OUTPUT_BSS}, except that it
+ is used when @var{name} should be placed in its own uniquely named
+ section so that it can be subject to linker garbage collection. If not
+ defined, @code{ASM_OUTPUT_BSS} will be used.
+
@findex ASM_OUTPUT_LOCAL
@item ASM_OUTPUT_LOCAL (@var{stream}, @var{name}, @var{size}, @var{rounded})
A C statement (sans semicolon) to output to the stdio stream
*************** in place of both @code{ASM_OUTPUT_DECL}
*** 5510,5522 ****
@code{ASM_OUTPUT_ALIGNED_DECL}. Define this macro when you need to see
the variable's decl in order to chose what to output.
-
@findex ASM_OUTPUT_SHARED_LOCAL
@item ASM_OUTPUT_SHARED_LOCAL (@var{stream}, @var{name}, @var{size}, @var{rounded})
If defined, it is similar to @code{ASM_OUTPUT_LOCAL}, except that it
is used when @var{name} is shared. If not defined, @code{ASM_OUTPUT_LOCAL}
will be used.
@end table
@node Label Output
@subsection Output and Generation of Labels
--- 5517,5535 ----
@code{ASM_OUTPUT_ALIGNED_DECL}. Define this macro when you need to see
the variable's decl in order to chose what to output.
@findex ASM_OUTPUT_SHARED_LOCAL
@item ASM_OUTPUT_SHARED_LOCAL (@var{stream}, @var{name}, @var{size}, @var{rounded})
If defined, it is similar to @code{ASM_OUTPUT_LOCAL}, except that it
is used when @var{name} is shared. If not defined, @code{ASM_OUTPUT_LOCAL}
will be used.
@end table
+
+ @findex ASM_OUTPUT_UNIQUE_LOCAL
+ @item ASM_OUTPUT_UNIQUE_LOCAL (@var{stream}, @var{decl}, @var{name}, @var{size})
+ If defined, it is similar to @code{ASM_OUTPUT_LOCAL}, except that it
+ is used when @var{name} should be placed in its own uniquely named
+ section so that it can be subject to linker garbage collection. If not
+ defined, @code{ASM_OUTPUT_LOCAL} will be used.
@node Label Output
@subsection Output and Generation of Labels