harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 41330a3aaac62c36f78b58d2cd87007ed18e62e3
parent 0b4d9df6e0219b0fdb099f745e4319ed2c628e13
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu, 11 Feb 2021 11:52:09 -0500

emit: move zeroed data into .bss

Diffstat:
Msrc/emit.c | 34++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+), 0 deletions(-)

diff --git a/src/emit.c b/src/emit.c @@ -233,6 +233,38 @@ emit_data_string(const char *str, size_t sz, FILE *out) } } +static bool +is_zeroes(struct qbe_data_item *data) +{ + switch (data->type) { + case QD_ZEROED: + break; + case QD_VALUE: + switch (data->value.kind) { + case QV_CONST: + if (data->value.lval != 0) { + return false; + } + break; + case QV_GLOBAL: + case QV_LABEL: + case QV_TEMPORARY: + return false; + } + break; + case QD_STRING: + for (size_t i = 0; i < data->sz; ++i) { + if (data->str[i] != 0) { + return false; + } + } + } + if (!data->next) { + return true; + } + return is_zeroes(data->next); +} + static void emit_data(struct qbe_def *def, FILE *out) { @@ -243,6 +275,8 @@ emit_data(struct qbe_def *def, FILE *out) def->data.section, def->data.secflags); } else if (def->data.section) { fprintf(out, "section \"%s\" ", def->data.section); + } else if (is_zeroes(&def->data.items)) { + fprintf(out, "section \".bss.%s\" ", def->name); } else { fprintf(out, "section \".data.%s\" ", def->name); }