This commit is contained in:
Quentin Carbonneaux 2026-04-28 15:56:15 +02:00
parent fee64f4341
commit 5ac78c67c9
2 changed files with 18 additions and 25 deletions

View File

@ -196,10 +196,8 @@ emitcon(Con *con, E *e)
l = str(con->sym.id); l = str(con->sym.id);
p = l[0] == '"' ? "" : T.assym; p = l[0] == '"' ? "" : T.assym;
if (con->sym.type & SThr) { if (con->sym.type & SThr) {
if (T.apple) assert(!T.apple);
fprintf(e->f, "%s%s@TLVP", p, l); fprintf(e->f, "%%fs:%s%s@tpoff", p, l);
else
fprintf(e->f, "%%fs:%s%s@tpoff", p, l);
} else } else
fprintf(e->f, "%s%s", p, l); fprintf(e->f, "%s%s", p, l);
if (con->bits.i) if (con->bits.i)
@ -532,14 +530,14 @@ emitins(Ins i, E *e)
emitf("mov%k %0, %=", &i, e); emitf("mov%k %0, %=", &i, e);
break; break;
case Oaddr: case Oaddr:
if (!T.apple if (rtype(i.arg[0]) != RCon)
&& rtype(i.arg[0]) == RCon goto Table;
&& e->fn->con[i.arg[0].val].sym.type == SThr) { assert(isreg(i.to));
con = &e->fn->con[i.arg[0].val];
sym = str(con->sym.id);
if (!T.apple && con->sym.type == SThr) {
/* derive the symbol address from the TCB /* derive the symbol address from the TCB
* address at offset 0 of %fs */ * address at offset 0 of %fs */
assert(isreg(i.to));
con = &e->fn->con[i.arg[0].val];
sym = str(con->sym.id);
emitf("movq %%fs:0, %L=", &i, e); emitf("movq %%fs:0, %L=", &i, e);
fprintf(e->f, "\tleaq %s%s@tpoff", fprintf(e->f, "\tleaq %s%s@tpoff",
sym[0] == '"' ? "" : T.assym, sym); sym[0] == '"' ? "" : T.assym, sym);
@ -551,14 +549,16 @@ emitins(Ins i, E *e)
regtoa(i.to.val, SLong)); regtoa(i.to.val, SLong));
break; break;
} }
if (!T.apple if (T.apple && con->sym.type == SThr) {
&& rtype(i.arg[0]) == RCon fprintf(e->f,
&& e->fn->con[i.arg[0].val].sym.type == SExtThr) { "\tmovq %s%s@TLVP(%%rip), %%%s\n",
sym[0] == '"' ? "" : T.assym, sym,
regtoa(i.to.val, SLong));
break;
}
if (!T.apple && con->sym.type == SExtThr) {
/* initial-exec TLS: load offset from /* initial-exec TLS: load offset from
* GOT, add to thread-base register */ * GOT, add to thread-base register */
assert(isreg(i.to));
con = &e->fn->con[i.arg[0].val];
sym = str(con->sym.id);
assert(!con->bits.i); assert(!con->bits.i);
emitf("movq %%fs:0, %L=", &i, e); emitf("movq %%fs:0, %L=", &i, e);
fprintf(e->f, fprintf(e->f,
@ -567,12 +567,8 @@ emitins(Ins i, E *e)
regtoa(i.to.val, SLong)); regtoa(i.to.val, SLong));
break; break;
} }
if (rtype(i.arg[0]) == RCon if (con->sym.type == SExt) {
&& e->fn->con[i.arg[0].val].sym.type == SExt) {
/* load address from the GOT */ /* load address from the GOT */
assert(isreg(i.to));
con = &e->fn->con[i.arg[0].val];
sym = str(con->sym.id);
assert(!con->bits.i); assert(!con->bits.i);
fprintf(e->f, fprintf(e->f,
"\tmovq %s%s@gotpcrel(%%rip), %%%s\n", "\tmovq %s%s@gotpcrel(%%rip), %%%s\n",

View File

@ -143,10 +143,7 @@ fixarg(Ref *r, int k, Ins *i, Fn *fn)
cc = *c; cc = *c;
cc.bits.i = 0; cc.bits.i = 0;
r3 = newcon(&cc, fn); r3 = newcon(&cc, fn);
if (T.apple && (c->sym.type & SThr)) emit(Oaddr, Kl, r2, r3, R);
emit(Oload, Kl, r2, r3, R);
else
emit(Oaddr, Kl, r2, r3, R);
if (rtype(r0) == RMem) { if (rtype(r0) == RMem) {
m = &fn->mem[r0.val]; m = &fn->mem[r0.val];
m->offset.type = CUndef; m->offset.type = CUndef;