summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2022-02-10 15:29:20 -0800
committerQuentin Carbonneaux <quentin@c9x.me>2022-02-11 08:49:42 +0100
commit7aceb24c50276322f79e7d13cbc6c9cd9251f447 (patch)
treecfb133aeef9cfeb99400b67bd2e57dea8e3ebca7
parent9fc0394d7ed2b86be9eae7f2b410e83fbe3ae497 (diff)
downloadroux-7aceb24c50276322f79e7d13cbc6c9cd9251f447.tar.gz
gas: put zero data into .bss by default
This allows frontends to use BSS generically, without knowledge of
platform-dependent details.
-rw-r--r--all.h6
-rw-r--r--gas.c21
-rw-r--r--parse.c4
3 files changed, 20 insertions, 11 deletions
diff --git a/all.h b/all.h
index 942c52d..257d6ba 100644
--- a/all.h
+++ b/all.h
@@ -387,6 +387,8 @@ struct Dat {
 		DL,
 		DZ
 	} type;
+	char *name;
+	Lnk *lnk;
 	union {
 		int64_t num;
 		double fltd;
@@ -396,10 +398,6 @@ struct Dat {
 			char *name;
 			int64_t off;
 		} ref;
-		struct {
-			char *name;
-			Lnk *lnk;
-		} start;
 	} u;
 	char isref;
 	char isstr;
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");
diff --git a/parse.c b/parse.c
index 5e5ab66..fb8b509 100644
--- a/parse.c
+++ b/parse.c
@@ -1010,8 +1010,8 @@ parsedat(void cb(Dat *), Lnk *lnk)
 		t = nextnl();
 	}
 	d.type = DStart;
-	d.u.start.name = name;
-	d.u.start.lnk = lnk;
+	d.name = name;
+	d.lnk = lnk;
 	cb(&d);
 
 	if (t != Tlbrace)