summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-28 02:03:38 +0100
committerXavier ASUS <xavi92psx@gmail.com>2019-10-28 02:03:38 +0100
commit3378ab8f236f387978fa4cc75bd5fca7021e8a13 (patch)
tree84abfdab6de3f84979f4db03837974a87ef85236
parente801690e4fc177f063e2ae854b3f2a69bd1b9ba0 (diff)
First implementation for --data-sections
OTOH, section names included in "options" were being assigned *before* parsing command line arguments. These arose some issues so I have created a post-parsing function.
-rw-r--r--src/SDCCglobl.h1
-rw-r--r--src/SDCCglue.c21
-rw-r--r--src/SDCCmain.c23
3 files changed, 36 insertions, 9 deletions
diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h
index f8b41b3..78a28e0 100644
--- a/src/SDCCglobl.h
+++ b/src/SDCCglobl.h
@@ -330,6 +330,7 @@ struct options
bool oldralloc; /* Use old register allocator */
int gasOutput; /* Output assembly in GNU as format */
int function_sections; /* Place each function into a separate section. Useful for link-time dead code elimination. */
+ int data_sections; /* Place each static variable into a separate section. Useful for link-time dead code elimination. */
};
/* forward definition for variables accessed globally */
diff --git a/src/SDCCglue.c b/src/SDCCglue.c
index 04804e2..52dcf3d 100644
--- a/src/SDCCglue.c
+++ b/src/SDCCglue.c
@@ -177,7 +177,8 @@ emitRegularMap (memmap *map, bool addPublics, bool arFlag)
if (map == code)
dbuf_tprintf (&map->oBuf, "\t!area\n", ".text");
else if (map == data)
- dbuf_tprintf (&map->oBuf, "\t!area\n", DATA_NAME);
+ if (!options.data_sections)
+ dbuf_tprintf (&map->oBuf, "\t!area\n", DATA_NAME);
for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms))
{
@@ -388,12 +389,17 @@ emitRegularMap (memmap *map, bool addPublics, bool arFlag)
{
if (IS_STATIC (sym->etype) || sym->level)
if (options.gasOutput)
- dbuf_tprintf (&map->oBuf, "\t!local\n", sym->rname);
+ {
+ if (options.data_sections)
+ dbuf_tprintf (&map->oBuf, "\t!area.%s\n", options.data_seg, sym->rname);
+
+ dbuf_tprintf (&map->oBuf, "\t!local\n", sym->rname);
+ }
else
dbuf_tprintf (&map->oBuf, "!slabeldef\n", sym->rname);
else
if (options.gasOutput)
- dbuf_tprintf (&map->oBuf, "!global\n", sym->rname);
+ dbuf_tprintf (&map->oBuf, "!global\n", sym->rname);
else
dbuf_tprintf (&map->oBuf, "!labeldef\n", sym->rname);
@@ -1997,8 +2003,13 @@ emitStaticSeg (memmap *map, struct dbuf_s *oBuf)
IS_INT (sym->type->next) && IS_LONG (sym->type->next) && SPEC_CVAL (sym->etype).v_char32))
{
if (options.const_seg)
- dbuf_tprintf(&code->oBuf, "\t!area\n", options.const_seg);
- dbuf_printf (oBuf, "%s:\n", sym->rname);
+ if (options.data_sections)
+ dbuf_tprintf(&code->oBuf, "\t!area.%s\n", options.const_seg, sym->rname);
+ else
+ dbuf_tprintf(&code->oBuf, "\t!area\n", options.const_seg);
+
+ dbuf_tprintf (oBuf, "!labeldef\n", sym->rname);
+
if (IS_CHAR (sym->type->next))
printChar (oBuf, SPEC_CVAL (sym->etype).v_char, size);
else if (IS_INT (sym->type->next) && !IS_LONG (sym->type->next))
diff --git a/src/SDCCmain.c b/src/SDCCmain.c
index 015e3c1..99e0c4c 100644
--- a/src/SDCCmain.c
+++ b/src/SDCCmain.c
@@ -153,6 +153,8 @@ char buffer[PATH_MAX * 2];
#define OPTION_DUMP_AST "--dump-ast"
#define OPTION_DUMP_I_CODE "--dump-i-code"
#define OPTION_DUMP_GRAPHS "--dump-graphs"
+#define OPTION_FUNCTION_SECTIONS "--function-sections"
+#define OPTION_DATA_SECTIONS "--data-sections"
#define OPTION_SMALL_MODEL "--model-small"
#define OPTION_MEDIUM_MODEL "--model-medium"
@@ -174,7 +176,8 @@ static const OPTION optionsTable[] = {
{'W', NULL, NULL, "Pass through options to the pre-processor (p), assembler (a) or linker (l)"},
{'S', NULL, &noAssemble, "Compile only; do not assemble or link"},
{0 , "--gas", &options.gasOutput, "Compile in GAS (GNU Assembler) format."},
- {0 , "--function-sections", &options.function_sections, "Place each function into a separate section. Useful for link-time dead code elimination."},
+ {0 , OPTION_FUNCTION_SECTIONS, &options.function_sections, "Place each function into a separate section. Useful for link-time dead code elimination."},
+ {0 , OPTION_DATA_SECTIONS, &options.data_sections, "Place each static variable into a separate section. Useful for link-time dead code elimination."},
{'c', "--compile-only", &options.cc_only, "Compile and assemble, but do not link"},
{'E', "--preprocessonly", &preProcOnly, "Preprocess only, do not compile"},
{0, "--c1mode", &options.c1mode, "Act in c1 mode. The standard input is preprocessed code, the output is assembly code."},
@@ -629,9 +632,6 @@ setDefaultOptions (void)
options.std_c99 = 1;
options.std_c11 = 1; /* default to C11 (we want inline by default, so we need at least C99, and support for C11 is more complete than C99) */
options.std_c2x = 0;
- options.code_seg = CODE_NAME ? Safe_strdup (CODE_NAME) : NULL; /* default to CSEG for generated code */
- options.const_seg = CONST_NAME ? Safe_strdup (CONST_NAME) : NULL; /* default to CONST for generated code */
- options.data_seg = DATA_NAME ? Safe_strdup (DATA_NAME) : NULL; /* default to DATA for non-initialized data */
options.stack10bit = 0;
options.out_fmt = 0;
options.dump_graphs = 0;
@@ -654,6 +654,18 @@ setDefaultOptions (void)
port->setDefaultOptions ();
}
+static void finalizeDefaultOptions(void)
+{
+ if (!options.code_seg)
+ options.code_seg = CODE_NAME ? Safe_strdup (CODE_NAME) : NULL; /* default to CSEG for generated code */
+
+ if (!options.const_seg)
+ options.const_seg = CONST_NAME ? Safe_strdup (CONST_NAME) : NULL; /* default to CONST for generated code */
+
+ if (!options.data_seg)
+ options.data_seg = DATA_NAME ? Safe_strdup (DATA_NAME) : NULL; /* default to DATA for non-initialized data */
+}
+
/*-----------------------------------------------------------------*/
/* processFile - determines the type of file from the extension */
/*-----------------------------------------------------------------*/
@@ -2608,6 +2620,9 @@ main (int argc, char **argv, char **envp)
setDefaultOptions ();
parseCmdLine (argc, argv);
+
+ finalizeDefaultOptions ();
+
#ifdef JAMIN_DS390
if (ds390_jammed)
{