Browse Source

add data $name = section "section" ...

This allows you to explicitly specify the section to emit the data
directive for, allowing for sections other than .data: for example, .bss
or .init_array.
Drew DeVault 5 years ago
parent
commit
83c2108341
3 changed files with 26 additions and 13 deletions
  1. 5 1
      gas.c
  2. 18 9
      parse.c
  3. 3 3
      tools/lexh.c

+ 5 - 1
gas.c

@@ -19,7 +19,11 @@ gasemitdat(Dat *d, FILE *f)
 	switch (d->type) {
 	switch (d->type) {
 	case DStart:
 	case DStart:
 		align = 0;
 		align = 0;
-		fprintf(f, ".data\n");
+		if (d->u.str) {
+			fprintf(f, ".section %s\n", d->u.str);
+		} else {
+			fprintf(f, ".data\n");
+		}
 		break;
 		break;
 	case DEnd:
 	case DEnd:
 		break;
 		break;

+ 18 - 9
parse.c

@@ -41,6 +41,7 @@ enum {
 	Tfunc,
 	Tfunc,
 	Ttype,
 	Ttype,
 	Tdata,
 	Tdata,
+	Tsection,
 	Talign,
 	Talign,
 	Tl,
 	Tl,
 	Tw,
 	Tw,
@@ -90,6 +91,7 @@ static char *kwmap[Ntok] = {
 	[Tfunc] = "function",
 	[Tfunc] = "function",
 	[Ttype] = "type",
 	[Ttype] = "type",
 	[Tdata] = "data",
 	[Tdata] = "data",
+	[Tsection] = "section",
 	[Talign] = "align",
 	[Talign] = "align",
 	[Tl] = "l",
 	[Tl] = "l",
 	[Tw] = "w",
 	[Tw] = "w",
@@ -984,29 +986,36 @@ parsedatstr(Dat *d)
 static void
 static void
 parsedat(void cb(Dat *), int export)
 parsedat(void cb(Dat *), int export)
 {
 {
-	char s[NString];
+	char name[NString] = {0};
 	int t;
 	int t;
 	Dat d;
 	Dat d;
 
 
-	d.type = DStart;
-	d.isstr = 0;
-	d.isref = 0;
-	d.export = export;
-	cb(&d);
 	if (nextnl() != Tglo || nextnl() != Teq)
 	if (nextnl() != Tglo || nextnl() != Teq)
 		err("data name, then = expected");
 		err("data name, then = expected");
-	strcpy(s, tokval.str);
+	strncpy(name, tokval.str, NString-1);
 	t = nextnl();
 	t = nextnl();
+	d.u.str = 0;
+	if (t == Tsection) {
+		if (nextnl() != Tstr)
+			err("section \"name\" expected");
+		d.u.str = tokval.str;
+		t = nextnl();
+	}
+	d.type = DStart;
+	cb(&d);
 	if (t == Talign) {
 	if (t == Talign) {
 		if (nextnl() != Tint)
 		if (nextnl() != Tint)
 			err("alignment expected");
 			err("alignment expected");
 		d.type = DAlign;
 		d.type = DAlign;
 		d.u.num = tokval.num;
 		d.u.num = tokval.num;
+		d.isstr = 0;
+		d.isref = 0;
 		cb(&d);
 		cb(&d);
 		t = nextnl();
 		t = nextnl();
 	}
 	}
 	d.type = DName;
 	d.type = DName;
-	d.u.str = s;
+	d.u.str = name;
+	d.export = export;
 	cb(&d);
 	cb(&d);
 
 
 	if (t != Tlbrace)
 	if (t != Tlbrace)
@@ -1025,8 +1034,8 @@ parsedat(void cb(Dat *), int export)
 		}
 		}
 		t = nextnl();
 		t = nextnl();
 		do {
 		do {
-			d.isref = 0;
 			d.isstr = 0;
 			d.isstr = 0;
+			d.isref = 0;
 			memset(&d.u, 0, sizeof d.u);
 			memset(&d.u, 0, sizeof d.u);
 			if (t == Tflts)
 			if (t == Tflts)
 				d.u.flts = tokval.flts;
 				d.u.flts = tokval.flts;

+ 3 - 3
tools/lexh.c

@@ -25,9 +25,9 @@ char *tok[] = {
 	"vaarg", "vastart", "...", "env",
 	"vaarg", "vastart", "...", "env",
 
 
 	"call", "phi", "jmp", "jnz", "ret", "export",
 	"call", "phi", "jmp", "jnz", "ret", "export",
-	"function", "type", "data", "align", "l", "w",
-	"h", "b", "d", "s", "z", "loadw", "loadl", "loads",
-	"loadd", "alloc1", "alloc2",
+	"function", "type", "data", "section", "align",
+	"l", "w", "h", "b", "d", "s", "z", "loadw", "loadl",
+	"loads", "loadd", "alloc1", "alloc2",
 
 
 };
 };
 enum {
 enum {