diff options
author | Michael Forney <mforney@mforney.org> | 2022-02-10 15:29:20 -0800 |
---|---|---|
committer | Quentin Carbonneaux <quentin@c9x.me> | 2022-02-11 08:49:42 +0100 |
commit | 7aceb24c50276322f79e7d13cbc6c9cd9251f447 (patch) | |
tree | cfb133aeef9cfeb99400b67bd2e57dea8e3ebca7 /gas.c | |
parent | 9fc0394d7ed2b86be9eae7f2b410e83fbe3ae497 (diff) | |
download | roux-7aceb24c50276322f79e7d13cbc6c9cd9251f447.tar.gz |
gas: put zero data into .bss by default
This allows frontends to use BSS generically, without knowledge of platform-dependent details.
Diffstat (limited to 'gas.c')
-rw-r--r-- | gas.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/gas.c b/gas.c index 4400769..e67043b 100644 --- a/gas.c +++ b/gas.c @@ -33,21 +33,32 @@ gasemitdat(Dat *d, FILE *f) [DW] = "\t.int", [DL] = "\t.quad" }; + static int64_t zero; char *p; switch (d->type) { case DStart: - gasemitlnk( - d->u.start.name, - d->u.start.lnk, - ".data", f); + zero = 0; break; case DEnd: + if (zero != -1) { + gasemitlnk(d->name, d->lnk, ".bss", f); + fprintf(f, "\t.fill %"PRId64",1,0\n", zero); + } break; case DZ: - fprintf(f, "\t.fill %"PRId64",1,0\n", d->u.num); + if (zero != -1) + zero += d->u.num; + else + fprintf(f, "\t.fill %"PRId64",1,0\n", d->u.num); break; default: + if (zero != -1) { + gasemitlnk(d->name, d->lnk, ".data", f); + if (zero > 0) + fprintf(f, "\t.fill %"PRId64",1,0\n", zero); + zero = -1; + } if (d->isstr) { if (d->type != DB) err("strings only supported for 'b' currently"); |