add common linkage for data

This commit is contained in:
Quentin Carbonneaux 2024-04-12 11:32:36 +02:00
parent 4a809d69b5
commit 8ded7a56a2
4 changed files with 21 additions and 3 deletions

1
all.h
View file

@ -371,6 +371,7 @@ struct Addr { /* amd64 addressing */
struct Lnk { struct Lnk {
char export; char export;
char thread; char thread;
char common;
char align; char align;
char *sec; char *sec;
char *secf; char *secf;

14
emit.c
View file

@ -75,7 +75,17 @@ emitdat(Dat *d, FILE *f)
zero = 0; zero = 0;
break; break;
case DEnd: case DEnd:
if (zero != -1) { if (d->lnk->common) {
if (zero == -1)
die("invalid common data definition");
p = d->name[0] == '"' ? "" : T.assym;
fprintf(f, ".comm %s%s,%"PRId64,
p, d->name, zero);
if (d->lnk->align)
fprintf(f, ",%d", d->lnk->align);
fputc('\n', f);
}
else if (zero != -1) {
emitlnk(d->name, d->lnk, SecBss, f); emitlnk(d->name, d->lnk, SecBss, f);
fprintf(f, "\t.fill %"PRId64",1,0\n", zero); fprintf(f, "\t.fill %"PRId64",1,0\n", zero);
} }
@ -87,6 +97,8 @@ emitdat(Dat *d, FILE *f)
fprintf(f, "\t.fill %"PRId64",1,0\n", d->u.num); fprintf(f, "\t.fill %"PRId64",1,0\n", d->u.num);
break; break;
default: default:
if (d->lnk->common)
die("unsupported common data item");
if (zero != -1) { if (zero != -1) {
emitlnk(d->name, d->lnk, SecData, f); emitlnk(d->name, d->lnk, SecData, f);
if (zero > 0) if (zero > 0)

View file

@ -48,6 +48,7 @@ enum Token {
Thlt, Thlt,
Texport, Texport,
Tthread, Tthread,
Tcommon,
Tfunc, Tfunc,
Ttype, Ttype,
Tdata, Tdata,
@ -106,6 +107,7 @@ static char *kwmap[Ntok] = {
[Thlt] = "hlt", [Thlt] = "hlt",
[Texport] = "export", [Texport] = "export",
[Tthread] = "thread", [Tthread] = "thread",
[Tcommon] = "common",
[Tfunc] = "function", [Tfunc] = "function",
[Ttype] = "type", [Ttype] = "type",
[Tdata] = "data", [Tdata] = "data",
@ -132,7 +134,7 @@ enum {
TMask = 16383, /* for temps hash */ TMask = 16383, /* for temps hash */
BMask = 8191, /* for blocks hash */ BMask = 8191, /* for blocks hash */
K = 9583425, /* found using tools/lexh.c */ K = 11183273, /* found using tools/lexh.c */
M = 23, M = 23,
}; };
@ -1159,6 +1161,9 @@ parselnk(Lnk *lnk)
case Tthread: case Tthread:
lnk->thread = 1; lnk->thread = 1;
break; break;
case Tcommon:
lnk->common = 1;
break;
case Tsection: case Tsection:
if (lnk->sec) if (lnk->sec)
err("only one section allowed"); err("only one section allowed");

View file

@ -29,7 +29,7 @@ char *tok[] = {
"function", "type", "data", "section", "align", "dbgfile", "function", "type", "data", "section", "align", "dbgfile",
"blit", "l", "w", "sh", "uh", "h", "sb", "ub", "b", "blit", "l", "w", "sh", "uh", "h", "sb", "ub", "b",
"d", "s", "z", "loadw", "loadl", "loads", "loadd", "d", "s", "z", "loadw", "loadl", "loads", "loadd",
"alloc1", "alloc2", "alloc1", "alloc2", "thread", "common",
}; };
enum { enum {