diff options
author | Quentin Carbonneaux <quentin@c9x.me> | 2022-09-09 17:40:31 +0200 |
---|---|---|
committer | Quentin Carbonneaux <quentin@c9x.me> | 2022-10-08 21:48:42 +0200 |
commit | 00a30954aca97004cb6f586bdeeabb488f1e3c3f (patch) | |
tree | 951dc4c0a5be04fe7d5aed13f4201eb90c60f841 /emit.c | |
parent | 5cea0c20ee3573949a2c24e4b3dea65fcbf6e48b (diff) | |
download | roux-00a30954aca97004cb6f586bdeeabb488f1e3c3f.tar.gz |
add support for thread-local storage
The apple targets are not done yet.
Diffstat (limited to 'emit.c')
-rw-r--r-- | emit.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/emit.c b/emit.c index 372ce3d..5e0f452 100644 --- a/emit.c +++ b/emit.c @@ -1,17 +1,30 @@ #include "all.h" +enum { + SecText, + SecData, + SecBss, +}; + void -emitlnk(char *n, Lnk *l, char *s, FILE *f) +emitlnk(char *n, Lnk *l, int s, FILE *f) { + static char *sec[2][3] = { + [0][SecText] = ".text", + [0][SecData] = ".data", + [0][SecBss] = ".bss", + [1][SecText] = ".abort \"unreachable\"", + [1][SecData] = ".section .tdata,\"awT\"", + [1][SecBss] = ".section .tbss,\"awT\"", + }; char *p; if (l->sec) { fprintf(f, ".section %s", l->sec); if (l->secf) - fprintf(f, ", %s", l->secf); - } else { - fputs(s, f); - } + fprintf(f, ",%s", l->secf); + } else + fputs(sec[l->thread != 0][s], f); fputc('\n', f); if (l->align) fprintf(f, ".balign %d\n", l->align); @@ -22,6 +35,12 @@ emitlnk(char *n, Lnk *l, char *s, FILE *f) } void +emitfnlnk(char *n, Lnk *l, FILE *f) +{ + emitlnk(n, l, SecText, f); +} + +void emitdat(Dat *d, FILE *f) { static char *dtoa[] = { @@ -39,7 +58,7 @@ emitdat(Dat *d, FILE *f) break; case DEnd: if (zero != -1) { - emitlnk(d->name, d->lnk, ".bss", f); + emitlnk(d->name, d->lnk, SecBss, f); fprintf(f, "\t.fill %"PRId64",1,0\n", zero); } break; @@ -51,7 +70,7 @@ emitdat(Dat *d, FILE *f) break; default: if (zero != -1) { - emitlnk(d->name, d->lnk, ".data", f); + emitlnk(d->name, d->lnk, SecData, f); if (zero > 0) fprintf(f, "\t.fill %"PRId64",1,0\n", zero); zero = -1; @@ -165,7 +184,7 @@ macho_emitfin(FILE *f) static char *sec[3] = { "__TEXT,__literal4,4byte_literals", "__TEXT,__literal8,8byte_literals", - ".rodata", /* should not happen */ + ".abort \"unreachable\"", }; emitfin(f, sec); |