summary refs log tree commit diff
path: root/amd64
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2022-09-09 17:40:31 +0200
committerQuentin Carbonneaux <quentin@c9x.me>2022-10-08 21:48:42 +0200
commit00a30954aca97004cb6f586bdeeabb488f1e3c3f (patch)
tree951dc4c0a5be04fe7d5aed13f4201eb90c60f841 /amd64
parent5cea0c20ee3573949a2c24e4b3dea65fcbf6e48b (diff)
downloadroux-00a30954aca97004cb6f586bdeeabb488f1e3c3f.tar.gz
add support for thread-local storage
The apple targets are not done yet.
Diffstat (limited to 'amd64')
-rw-r--r--amd64/emit.c11
-rw-r--r--amd64/isel.c3
2 files changed, 8 insertions, 6 deletions
diff --git a/amd64/emit.c b/amd64/emit.c
index db6ead8..cf36ebe 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -166,8 +166,11 @@ emitcon(Con *con, FILE *f)
 	switch (con->type) {
 	case CAddr:
 		l = str(con->label);
-		p = con->local ? T.asloc : l[0] == '"' ? "" : T.assym;
-		fprintf(f, "%s%s", p, l);
+		p = l[0] == '"' ? "" : T.assym;
+		if (con->rel == RelThr)
+			fprintf(f, "%%fs:%s%s@tpoff", p, l);
+		else
+			fprintf(f, "%s%s", p, l);
 		if (con->bits.i)
 			fprintf(f, "%+"PRId64, con->bits.i);
 		break;
@@ -337,7 +340,7 @@ Next:
 		case RCon:
 			off = fn->con[ref.val];
 			emitcon(&off, f);
-			if (off.type == CAddr)
+			if (off.type == CAddr && off.rel != RelThr)
 				fprintf(f, "(%%rip)");
 			break;
 		case RTmp:
@@ -549,7 +552,7 @@ emitfn(Fn *fn, FILE *f)
 	int *r, c, o, n, lbl;
 	uint64_t fs;
 
-	emitlnk(fn->name, &fn->lnk, ".text", f);
+	emitfnlnk(fn->name, &fn->lnk, f);
 	fputs("\tpushq %rbp\n\tmovq %rsp, %rbp\n", f);
 	fs = framesz(fn);
 	if (fs)
diff --git a/amd64/isel.c b/amd64/isel.c
index 640bf12..a562441 100644
--- a/amd64/isel.c
+++ b/amd64/isel.c
@@ -78,9 +78,8 @@ fixarg(Ref *r, int k, Ins *i, Fn *fn)
 		vgrow(&fn->mem, ++fn->nmem);
 		memset(&a, 0, sizeof a);
 		a.offset.type = CAddr;
-		a.offset.local = 1;
 		n = stashbits(&fn->con[r0.val].bits, KWIDE(k) ? 8 : 4);
-		sprintf(buf, "fp%d", n);
+		sprintf(buf, "\"%sfp%d\"", T.asloc, n);
 		a.offset.label = intern(buf);
 		fn->mem[fn->nmem-1] = a;
 	}