mirror of
git://c9x.me/qbe.git
synced 2026-05-26 23:44:40 +00:00
Compare commits
3 Commits
6abea36b9b
...
f36c06c3ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f36c06c3ee | ||
|
|
8c16de02ed | ||
|
|
63bb04f759 |
13
all.h
13
all.h
@ -292,16 +292,11 @@ struct Use {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Sym {
|
struct Sym {
|
||||||
/* SGlo = 0 (direct access)
|
|
||||||
* SThr = 1 (local-exec TLS)
|
|
||||||
* SExt = 2 (GOT/PLT access)
|
|
||||||
* SExt|SThr = 3 (initial-exec TLS)
|
|
||||||
*/
|
|
||||||
enum {
|
enum {
|
||||||
SGlo = 0,
|
SGlo = 0, /* direct access */
|
||||||
SThr = 1,
|
SThr = 1, /* local-exec TLS */
|
||||||
SExt = 2,
|
SExt = 2, /* GOT/PLT access */
|
||||||
SExtThr = SExt|SThr,
|
SExtThr = SExt|SThr, /* initial-exec TLS */
|
||||||
} type;
|
} type;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -534,12 +534,12 @@ emitins(Ins i, E *e)
|
|||||||
case Oaddr:
|
case Oaddr:
|
||||||
if (rtype(i.arg[0]) != RCon)
|
if (rtype(i.arg[0]) != RCon)
|
||||||
goto Table;
|
goto Table;
|
||||||
assert(isreg(i.to));
|
|
||||||
con = &e->fn->con[i.arg[0].val];
|
con = &e->fn->con[i.arg[0].val];
|
||||||
|
assert(isreg(i.to) && con->type == CAddr);
|
||||||
sym = str(con->sym.id);
|
sym = str(con->sym.id);
|
||||||
if (T.apple && (con->sym.type & SThr)) {
|
if (T.apple && (con->sym.type & SThr)) {
|
||||||
fprintf(e->f,
|
fprintf(e->f,
|
||||||
"\tmovq %s%s@TLVP(%%rip), %%%s\n",
|
"\tmovq %s%s@tlvp(%%rip), %%%s\n",
|
||||||
sym[0] == '"' ? "" : T.assym, sym,
|
sym[0] == '"' ? "" : T.assym, sym,
|
||||||
regtoa(i.to.val, SLong));
|
regtoa(i.to.val, SLong));
|
||||||
break;
|
break;
|
||||||
|
|||||||
15
doc/il.txt
15
doc/il.txt
@ -228,14 +228,13 @@ symbol's numeric value is resolved at runtime in the
|
|||||||
thread-local storage.
|
thread-local storage.
|
||||||
|
|
||||||
When the `extern` keyword prefixes a symbol name, the
|
When the `extern` keyword prefixes a symbol name, the
|
||||||
symbol is accessed indirectly through the Global Offset
|
symbol is accessed indirectly through a table edited
|
||||||
Table (GOT). Function calls to extern symbols use the
|
by the dynamic linker (e.g., GOT/PLT). This enables
|
||||||
Procedure Linkage Table (PLT). This enables PIE and
|
PIE/PIC code generation. When `extern` is combined
|
||||||
PIC code generation for symbols that are not part of
|
with `thread`, the symbol is accessed using the
|
||||||
the main executable. When `extern` is combined with
|
initial-exec TLS model, suitable for thread-local
|
||||||
`thread`, the symbol is accessed using the initial-exec
|
variables defined in shared objects available at
|
||||||
TLS model, suitable for thread-local variables defined
|
startup time (i.e., not loaded through dlopen).
|
||||||
in shared libraries.
|
|
||||||
|
|
||||||
Vals are used as arguments in regular, phi, and jump
|
Vals are used as arguments in regular, phi, and jump
|
||||||
instructions within function definitions. They are
|
instructions within function definitions. They are
|
||||||
|
|||||||
27
parse.c
27
parse.c
@ -429,11 +429,10 @@ static Ref
|
|||||||
parseref()
|
parseref()
|
||||||
{
|
{
|
||||||
Con c;
|
Con c;
|
||||||
|
int tok;
|
||||||
|
|
||||||
memset(&c, 0, sizeof c);
|
memset(&c, 0, sizeof c);
|
||||||
switch (next()) {
|
switch ((tok = next())) {
|
||||||
default:
|
|
||||||
return R;
|
|
||||||
case Ttmp:
|
case Ttmp:
|
||||||
return tmpref(tokval.str);
|
return tmpref(tokval.str);
|
||||||
case Tint:
|
case Tint:
|
||||||
@ -450,20 +449,22 @@ parseref()
|
|||||||
c.bits.d = tokval.fltd;
|
c.bits.d = tokval.fltd;
|
||||||
c.flt = 2;
|
c.flt = 2;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
for (;; tok=next()) {
|
||||||
|
switch (tok) {
|
||||||
case Textern:
|
case Textern:
|
||||||
c.sym.type = SExt;
|
c.sym.type |= SExt;
|
||||||
if (peek() == Tthread) {
|
continue;
|
||||||
next();
|
|
||||||
c.sym.type |= SThr;
|
|
||||||
}
|
|
||||||
expect(Tglo);
|
|
||||||
goto Glo;
|
|
||||||
case Tthread:
|
case Tthread:
|
||||||
c.sym.type = SThr;
|
c.sym.type |= SThr;
|
||||||
expect(Tglo);
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (tok != Tglo)
|
||||||
|
return R;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case Tglo:
|
case Tglo:
|
||||||
Glo:
|
|
||||||
c.type = CAddr;
|
c.type = CAddr;
|
||||||
c.sym.id = intern(tokval.str);
|
c.sym.id = intern(tokval.str);
|
||||||
break;
|
break;
|
||||||
|
|||||||
25
rv64/emit.c
25
rv64/emit.c
@ -131,7 +131,7 @@ slot(Ref r, Fn *fn)
|
|||||||
static void
|
static void
|
||||||
emitaddr(Con *c, FILE *f)
|
emitaddr(Con *c, FILE *f)
|
||||||
{
|
{
|
||||||
assert(c->sym.type == SGlo || c->sym.type == SExt);
|
assert((c->sym.type & ~SExt) == SGlo);
|
||||||
fputs(str(c->sym.id), f);
|
fputs(str(c->sym.id), f);
|
||||||
if (c->bits.i)
|
if (c->bits.i)
|
||||||
fprintf(f, "+%"PRIi64, c->bits.i);
|
fprintf(f, "+%"PRIi64, c->bits.i);
|
||||||
@ -232,6 +232,18 @@ loadaddr(Con *c, char *rn, FILE *f)
|
|||||||
char off[32];
|
char off[32];
|
||||||
|
|
||||||
switch (c->sym.type) {
|
switch (c->sym.type) {
|
||||||
|
case SGlo:
|
||||||
|
fprintf(f, "\tlui %s, %%hi(", rn);
|
||||||
|
emitaddr(c, f);
|
||||||
|
fprintf(f, ")\n\taddi %s, %s, %%lo(", rn, rn);
|
||||||
|
emitaddr(c, f);
|
||||||
|
fputs(")\n", f);
|
||||||
|
break;
|
||||||
|
case SExt:
|
||||||
|
fprintf(f, "\tla %s, ", rn);
|
||||||
|
emitaddr(c, f);
|
||||||
|
fputc('\n', f);
|
||||||
|
break;
|
||||||
case SThr:
|
case SThr:
|
||||||
if (c->bits.i)
|
if (c->bits.i)
|
||||||
sprintf(off, "+%"PRIi64, c->bits.i);
|
sprintf(off, "+%"PRIi64, c->bits.i);
|
||||||
@ -244,19 +256,8 @@ loadaddr(Con *c, char *rn, FILE *f)
|
|||||||
fprintf(f, "\taddi %s, %s, %%tprel_lo(%s)%s\n",
|
fprintf(f, "\taddi %s, %s, %%tprel_lo(%s)%s\n",
|
||||||
rn, rn, str(c->sym.id), off);
|
rn, rn, str(c->sym.id), off);
|
||||||
break;
|
break;
|
||||||
case SExt:
|
|
||||||
fprintf(f, "\tla %s, ", rn);
|
|
||||||
emitaddr(c, f);
|
|
||||||
fputc('\n', f);
|
|
||||||
break;
|
|
||||||
case SExtThr:
|
case SExtThr:
|
||||||
die("extern thread unavailable on rv64");
|
die("extern thread unavailable on rv64");
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(f, "\tla %s, ", rn);
|
|
||||||
emitaddr(c, f);
|
|
||||||
fputc('\n', f);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user