ref: a143d21397a31766874783b7e008a54928af5da5
parent: c3298baf19a3e399a7e65f15bd7a8e62dbba89a6
author: Ori Bernstein <[email protected]>
date: Tue Jul 24 21:11:39 EDT 2012
Don't export symbols willy-nilly. Only export things in the package section, or 'main'.
--- a/8/asm.h
+++ b/8/asm.h
@@ -75,7 +75,7 @@
struct Func {
char *name;
- int isglobl;
+ int isexport;
size_t stksz;
Type *type;
Htab *locs;
--- a/8/isel.c
+++ b/8/isel.c
@@ -753,7 +753,7 @@
{
size_t i, j;
- if (fn->isglobl)
+ if (fn->isexport || !strcmp(fn->name, "main"))
fprintf(fd, ".globl %s\n", fn->name);
fprintf(fd, "%s:\n", fn->name);
for (j = 0; j < s->cfg->nbb; j++) {
@@ -828,7 +828,8 @@
assert(blob->type == Ndecl);
lbl = htget(globls, blob);
- fprintf(fd, ".globl %s\n", lbl);
+ if (blob->decl.isexport)
+ fprintf(fd, ".globl %s\n", lbl);
fprintf(fd, "%s:\n", lbl);
if (blob->decl.init) {
if (exprop(blob->decl.init) != Olit)
--- a/8/simp.c
+++ b/8/simp.c
@@ -1104,7 +1104,7 @@
append(s, s->endlbl);
}
-static Func *lowerfn(Simp *s, char *name, Node *n)
+static Func *lowerfn(Simp *s, char *name, Node *n, int export)
{
size_t i;
Func *fn;
@@ -1144,7 +1144,7 @@
fn = zalloc(sizeof(Func));
fn->name = strdup(name);
- fn->isglobl = 1; /* FIXME: we should actually use the visibility of the sym... */
+ fn->isexport = export;
fn->stksz = s->stksz;
fn->locs = s->locs;
fn->ret = s->ret;
@@ -1188,7 +1188,7 @@
if (isconstfn(dcl)) {
if (!dcl->decl.isextern && !dcl->decl.isgeneric) {
- f = lowerfn(&s, name, dcl->decl.init);
+ f = lowerfn(&s, name, dcl->decl.init, dcl->decl.isexport);
lappend(fn, nfn, f);
}
} else {
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -116,8 +116,8 @@
outnode(n->file.stmts[i], fd, depth + 1);
break;
case Ndecl:
- fprintf(fd, "(did = %zd, isconst = %d, isgeneric = %d, isextern = %d\n",
- n->decl.did, n->decl.isconst, n->decl.isgeneric, n->decl.isextern);
+ fprintf(fd, "(did = %zd, isconst = %d, isgeneric = %d, isextern = %d\n, isexport = %d)",
+ n->decl.did, n->decl.isconst, n->decl.isgeneric, n->decl.isextern, n->decl.isexport);
outsym(n, fd, depth + 1);
outnode(n->decl.init, fd, depth + 1);
break;
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -770,8 +770,11 @@
* need to patch the types in if they don't have a definition */
if (d->type == Ndecl) {
s = getdcl(file->file.exports, d->decl.name);
- if (s)
+ if (s) {
+ s->decl.isexport = 1;
+ d->decl.isexport = 1;
unify(st, d, type(st, d), s->decl.type);
+ }
}
}
popstab();
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -218,6 +218,7 @@
struct {
size_t did;
char isglobl;
+ char isexport;
char isconst;
char isgeneric;
char isextern;