shithub: mc

Download patch

ref: 82ffa8d68b897200ae2fedc863aa7ac064660d1d
parent: 8531896f8d21ba1e727262aaf5cd96043590b480
author: Ori Bernstein <[email protected]>
date: Tue Nov 17 17:54:08 EST 2015

Put empty symbols in bss, and use .fill directives.

	We don't need to put zero bytes into the binary, and
	we don't need to generate thousands of .byte directives.

--- a/6/asm.h
+++ b/6/asm.h
@@ -67,6 +67,7 @@
 	Btbytes,
 	Btseq,
 	Btpad,
+	Btzero,
 } Blobtype;
 
 struct Blob {
@@ -253,6 +254,7 @@
 void genp9(Node *file, char *out);
 
 /* blob stuff */
+Blob *mkblobzero(size_t sz);
 Blob *mkblobpad(size_t sz);
 Blob *mkblobi(Blobtype type, uint64_t ival);
 Blob *mkblobbytes(char *buf, size_t len);
--- a/6/blob.c
+++ b/6/blob.c
@@ -27,6 +27,16 @@
 	return b;
 }
 
+Blob *mkblobzero(size_t sz)
+{
+	Blob *b;
+
+	b = zalloc(sizeof(Blob));
+	b->type = Btzero;
+	b->npad = sz;
+	return b;
+}
+
 Blob *mkblobpad(size_t sz)
 {
 	Blob *b;
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -300,41 +300,28 @@
 	if (!b)
 		return;
 	if (b->lbl) {
-		if (b->isglobl)
-			fprintf(fd, ".globl %s%s\n", Symprefix, b->lbl);
-		fprintf(fd, "%s%s:\n", Symprefix, b->lbl);
+		if (b->type == Btzero) {
+			fprintf(fd, ".comm %s%s,%zd,16\n", Symprefix, b->lbl, b->npad);
+		} else {
+			if (b->isglobl)
+				fprintf(fd, ".globl %s%s\n", Symprefix, b->lbl);
+			fprintf(fd, "%s%s:\n", Symprefix, b->lbl);
+		}
 	}
 	switch (b->type) {
-	case Bti8:
-		fprintf(fd, "\t.byte %zd\n", b->ival);
-		break;
-	case Bti16:
-		fprintf(fd, "\t.short %zd\n", b->ival);
-		break;
-	case Bti32:
-		fprintf(fd, "\t.long %zd\n", b->ival);
-		break;
-	case Bti64:
-		fprintf(fd, "\t.quad %zd\n", b->ival);
-		break;
-	case Btimin:
-		encodemin(fd, b->ival);
-		break;
-	case Btref:
-		fprintf(fd, "\t.quad %s + %zd\n", b->ref.str, b->ref.off);
-		break;
-	case Btbytes:
-		writebytes(fd, b->bytes.buf, b->bytes.len);
-		break;
+	case Btimin:	encodemin(fd, b->ival);	break;
+	case Bti8:	fprintf(fd, "\t.byte %zd\n", b->ival);	break;
+	case Bti16:	fprintf(fd, "\t.short %zd\n", b->ival);	break;
+	case Bti32:	fprintf(fd, "\t.long %zd\n", b->ival);	break;
+	case Bti64:	fprintf(fd, "\t.quad %zd\n", b->ival);	break;
+	case Btbytes:	writebytes(fd, b->bytes.buf, b->bytes.len);	break;
+	case Btpad:	fprintf(fd, "\t.fill %zd,1,0\n", b->npad);	break;
+	case Btzero:	fprintf(fd, "\t.fill %zd,1,0\n", b->npad);	break;
+	case Btref:	fprintf(fd, "\t.quad %s + %zd\n", b->ref.str, b->ref.off);	break;
 	case Btseq:
 		for (i = 0; i < b->seq.nsub; i++)
 			writeblob(fd, b->seq.sub[i]);
 		break;
-	case Btpad:
-		for (i = 0; i < b->npad; i++)
-			fprintf(fd, "\t.byte 0\n");
-		break;
-
 	}
 }
 
@@ -382,12 +369,14 @@
 	lbl = htget(globls, blob);
 	if (blob->decl.vis != Visintern)
 		fprintf(fd, ".globl %s\n", lbl);
-	fprintf(fd, ".align %zd\n", tyalign(decltype(blob)));
-	fprintf(fd, "%s:\n", lbl);
-	if (blob->decl.init)
+	if (blob->decl.init) {
+		fprintf(fd, ".align %zd\n", tyalign(decltype(blob)));
+		fprintf(fd, "%s:\n", lbl);
 		b = litblob(globls, strtab, blob->decl.init);
-	else
-		b = mkblobpad(size(blob));
+	} else {
+		b = mkblobzero(size(blob));
+		b->lbl = lbl;
+	}
 	writeblob(fd, b);
 	blobfree(b);
 }
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -355,6 +355,8 @@
 			fprintf(fd, "DATA %s+%zd(SB)/1,$0\n", lbl, off+n+i);
 		n += b->npad;
 		break;
+	case Btzero:
+		break;
 	}
 	return n;
 }