shithub: mc

Download patch

ref: f2027c43e0e85e679c4988954b8e9b35c0a1bdd3
parent: 82ffa8d68b897200ae2fedc863aa7ac064660d1d
author: Ori Bernstein <[email protected]>
date: Wed Nov 18 06:29:09 EST 2015

Fix BSS on OSX.

    Our alignment was too big, and we really didn't need to leading
    '_'. In fact, we didn't even need zero blobs.

--- a/6/asm.h
+++ b/6/asm.h
@@ -67,7 +67,6 @@
 	Btbytes,
 	Btseq,
 	Btpad,
-	Btzero,
 } Blobtype;
 
 struct Blob {
@@ -254,7 +253,6 @@
 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,16 +27,6 @@
 	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;
@@ -118,7 +108,8 @@
 
 static size_t blobpad(Blob *seq, size_t sz)
 {
-	b(seq, mkblobpad(sz));
+	if (sz)
+		b(seq, mkblobpad(sz));
 	return sz;
 }
 
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -300,13 +300,9 @@
 	if (!b)
 		return;
 	if (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);
-		}
+		if (b->isglobl)
+			fprintf(fd, ".globl %s%s\n", Symprefix, b->lbl);
+		fprintf(fd, "%s%s:\n", Symprefix, b->lbl);
 	}
 	switch (b->type) {
 	case Btimin:	encodemin(fd, b->ival);	break;
@@ -316,7 +312,6 @@
 	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++)
@@ -372,13 +367,13 @@
 	if (blob->decl.init) {
 		fprintf(fd, ".align %zd\n", tyalign(decltype(blob)));
 		fprintf(fd, "%s:\n", lbl);
+
 		b = litblob(globls, strtab, blob->decl.init);
+		writeblob(fd, b);
+		blobfree(b);
 	} else {
-		b = mkblobzero(size(blob));
-		b->lbl = lbl;
+		fprintf(fd, ".comm %s,%zd,5\n", lbl, size(blob));
 	}
-	writeblob(fd, b);
-	blobfree(b);
 }
 
 void gengas(Node *file, char *out)
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -355,8 +355,6 @@
 			fprintf(fd, "DATA %s+%zd(SB)/1,$0\n", lbl, off+n+i);
 		n += b->npad;
 		break;
-	case Btzero:
-		break;
 	}
 	return n;
 }