SHIDDEN = 1<<9, // hidden or local symbol
};
+// Reloc.type
+enum
+{
+ R_ADDR = 1,
+ R_SIZE,
+ R_CALL,
+ R_CONST,
+ R_PCREL,
+ R_TLS,
+ R_GOTOFF,
+ R_PLT0,
+ R_PLT1,
+ R_PLT2,
+};
+
+// Auto.type
+enum
+{
+ A_AUTO = 1,
+ A_PARAM,
+};
+
struct Auto
{
LSym* asym;
// TODO: Give these the same values on all systems.
int D_ADDR;
+ int D_AUTO;
int D_BRANCH;
int D_CONST;
int D_EXTERN;
int D_FCONST;
int D_NONE;
- int D_PCREL;
+ int D_PARAM;
int D_SCONST;
- int D_SIZE;
int D_STATIC;
int ACALL;
D_STATIC = (D_NONE+4),
D_AUTO = (D_NONE+5),
D_PARAM = (D_NONE+6),
-
-/* internal only */
- D_SIZE = (D_NONE+40),
- D_PCREL = (D_NONE+41),
- D_GOTOFF = (D_NONE+42), // R_ARM_GOTOFF
- D_PLT0 = (D_NONE+43), // R_ARM_PLT32, 1st inst: add ip, pc, #0xNN00000
- D_PLT1 = (D_NONE+44), // R_ARM_PLT32, 2nd inst: add ip, ip, #0xNN000
- D_PLT2 = (D_NONE+45), // R_ARM_PLT32, 3rd inst: ldr pc, [ip, #0xNNN]!
- D_CALL = (D_NONE+46), // R_ARM_PLT32/R_ARM_CALL/R_ARM_JUMP24, bl xxxxx or b yyyyy
- D_TLS = (D_NONE+47), // R_ARM_TLS_LE32/R_ARM_TLS_IE32
};
/*
// Handle relocations found in ELF object files.
case 256 + R_ARM_PLT32:
- r->type = D_CALL;
+ r->type = R_CALL;
if(targ->type == SDYNIMPORT) {
addpltsym(ctxt, targ);
r->sym = linklookup(ctxt, ".plt", 0);
} else {
addgotsym(ctxt, targ);
}
- r->type = D_CONST; // write r->add during relocsym
+ r->type = R_CONST; // write r->add during relocsym
r->sym = S;
r->add += targ->got;
return;
} else {
addgotsym(ctxt, targ);
}
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->sym = linklookup(ctxt, ".got", 0);
r->add += targ->got + 4;
return;
case 256 + R_ARM_GOTOFF: // R_ARM_GOTOFF32
- r->type = D_GOTOFF;
+ r->type = R_GOTOFF;
return;
case 256 + R_ARM_GOTPC: // R_ARM_BASE_PREL
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->sym = linklookup(ctxt, ".got", 0);
r->add += 4;
return;
case 256 + R_ARM_CALL:
- r->type = D_CALL;
+ r->type = R_CALL;
if(targ->type == SDYNIMPORT) {
addpltsym(ctxt, targ);
r->sym = linklookup(ctxt, ".plt", 0);
return;
case 256 + R_ARM_REL32: // R_ARM_REL32
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->add += 4;
return;
case 256 + R_ARM_ABS32:
if(targ->type == SDYNIMPORT)
diag("unexpected R_ARM_ABS32 relocation for dynamic symbol %s", targ->name);
- r->type = D_ADDR;
+ r->type = R_ADDR;
return;
case 256 + R_ARM_V4BX:
case 256 + R_ARM_PC24:
case 256 + R_ARM_JUMP24:
- r->type = D_CALL;
+ r->type = R_CALL;
if(targ->type == SDYNIMPORT) {
addpltsym(ctxt, targ);
r->sym = linklookup(ctxt, ".plt", 0);
return;
switch(r->type) {
- case D_PCREL:
+ case R_PCREL:
addpltsym(ctxt, targ);
r->sym = linklookup(ctxt, ".plt", 0);
r->add = targ->plt;
return;
- case D_ADDR:
+ case R_ADDR:
if(s->type != SDATA)
break;
if(iself) {
rel = linklookup(ctxt, ".rel", 0);
addaddrplus(ctxt, rel, s, r->off);
adduint32(ctxt, rel, ELF32_R_INFO(targ->dynid, R_ARM_GLOB_DAT)); // we need a S + A dynmic reloc
- r->type = D_CONST; // write r->add during relocsym
+ r->type = R_CONST; // write r->add during relocsym
r->sym = S;
return;
}
default:
return -1;
- case D_ADDR:
+ case R_ADDR:
if(r->siz == 4)
LPUT(R_ARM_ABS32 | elfsym<<8);
else
return -1;
break;
- case D_PCREL:
+ case R_PCREL:
if(r->siz == 4)
LPUT(R_ARM_REL32 | elfsym<<8);
else
return -1;
break;
- case D_CALL:
+ case R_CALL:
if(r->siz == 4) {
if((r->add & 0xff000000) == 0xeb000000) // BL
LPUT(R_ARM_CALL | elfsym<<8);
return -1;
break;
- case D_TLS:
+ case R_TLS:
if(r->siz == 4) {
if(flag_shared)
LPUT(R_ARM_TLS_IE32 | elfsym<<8);
if(linkmode == LinkExternal) {
switch(r->type) {
- case D_CALL:
+ case R_CALL:
r->done = 0;
// set up addend for eventual relocation via outer symbol.
return -1;
}
switch(r->type) {
- case D_CONST:
+ case R_CONST:
*val = r->add;
return 0;
- case D_GOTOFF:
+ case R_GOTOFF:
*val = symaddr(r->sym) + r->add - symaddr(linklookup(ctxt, ".got", 0));
return 0;
// The following three arch specific relocations are only for generation of
// Linux/ARM ELF's PLT entry (3 assembler instruction)
- case D_PLT0: // add ip, pc, #0xXX00000
+ case R_PLT0: // add ip, pc, #0xXX00000
if (symaddr(linklookup(ctxt, ".got.plt", 0)) < symaddr(linklookup(ctxt, ".plt", 0)))
diag(".got.plt should be placed after .plt section.");
*val = 0xe28fc600U +
(0xff & ((uint32)(symaddr(r->sym) - (symaddr(linklookup(ctxt, ".plt", 0)) + r->off) + r->add) >> 20));
return 0;
- case D_PLT1: // add ip, ip, #0xYY000
+ case R_PLT1: // add ip, ip, #0xYY000
*val = 0xe28cca00U +
(0xff & ((uint32)(symaddr(r->sym) - (symaddr(linklookup(ctxt, ".plt", 0)) + r->off) + r->add + 4) >> 12));
return 0;
- case D_PLT2: // ldr pc, [ip, #0xZZZ]!
+ case R_PLT2: // ldr pc, [ip, #0xZZZ]!
*val = 0xe5bcf000U +
(0xfff & (uint32)(symaddr(r->sym) - (symaddr(linklookup(ctxt, ".plt", 0)) + r->off) + r->add + 8));
return 0;
- case D_CALL: // bl XXXXXX or b YYYYYY
+ case R_CALL: // bl XXXXXX or b YYYYYY
*val = braddoff((0xff000000U & (uint32)r->add),
(0xffffff & (uint32)
((symaddr(r->sym) + ((uint32)r->add) * 4 - (s->value + r->off)) / 4)));
// .plt entry, this depends on the .got entry
s->plt = plt->size;
- addpltreloc(ctxt, plt, got, s, D_PLT0); // add lr, pc, #0xXX00000
- addpltreloc(ctxt, plt, got, s, D_PLT1); // add lr, lr, #0xYY000
- addpltreloc(ctxt, plt, got, s, D_PLT2); // ldr pc, [lr, #0xZZZ]!
+ addpltreloc(ctxt, plt, got, s, R_PLT0); // add lr, pc, #0xXX00000
+ addpltreloc(ctxt, plt, got, s, R_PLT1); // add lr, lr, #0xYY000
+ addpltreloc(ctxt, plt, got, s, R_PLT2); // ldr pc, [lr, #0xZZZ]!
// rel
addaddrplus(ctxt, rel, got, s->got);
D_INDIR, /* additive */
- D_SIZE = D_INDIR + D_INDIR, /* 6l internal */
- D_PCREL,
- D_TLS,
-
T_TYPE = 1<<0,
T_INDEX = 1<<1,
T_OFFSET = 1<<2,
diag("unexpected R_X86_64_PC32 relocation for dynamic symbol %s", targ->name);
if(targ->type == 0 || targ->type == SXREF)
diag("unknown symbol %s in pcrel", targ->name);
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->add += 4;
return;
case 256 + R_X86_64_PLT32:
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->add += 4;
if(targ->type == SDYNIMPORT) {
addpltsym(targ);
if(r->off >= 2 && s->p[r->off-2] == 0x8b) {
// turn MOVQ of GOT entry into LEAQ of symbol itself
s->p[r->off-2] = 0x8d;
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->add += 4;
return;
}
// TODO: just needs relocation, no need to put in .dynsym
}
addgotsym(targ);
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->sym = linklookup(ctxt, ".got", 0);
r->add += 4;
r->add += targ->got;
case 256 + R_X86_64_64:
if(targ->type == SDYNIMPORT)
diag("unexpected R_X86_64_64 relocation for dynamic symbol %s", targ->name);
- r->type = D_ADDR;
+ r->type = R_ADDR;
return;
// Handle relocations found in Mach-O object files.
case 512 + MACHO_X86_64_RELOC_SIGNED*2 + 0:
case 512 + MACHO_X86_64_RELOC_BRANCH*2 + 0:
// TODO: What is the difference between all these?
- r->type = D_ADDR;
+ r->type = R_ADDR;
if(targ->type == SDYNIMPORT)
diag("unexpected reloc for dynamic symbol %s", targ->name);
return;
addpltsym(targ);
r->sym = linklookup(ctxt, ".plt", 0);
r->add = targ->plt;
- r->type = D_PCREL;
+ r->type = R_PCREL;
return;
}
// fall through
case 512 + MACHO_X86_64_RELOC_SIGNED_1*2 + 1:
case 512 + MACHO_X86_64_RELOC_SIGNED_2*2 + 1:
case 512 + MACHO_X86_64_RELOC_SIGNED_4*2 + 1:
- r->type = D_PCREL;
+ r->type = R_PCREL;
if(targ->type == SDYNIMPORT)
diag("unexpected pc-relative reloc for dynamic symbol %s", targ->name);
return;
return;
}
s->p[r->off-2] = 0x8d;
- r->type = D_PCREL;
+ r->type = R_PCREL;
return;
}
// fall through
if(targ->type != SDYNIMPORT)
diag("unexpected GOT reloc for non-dynamic symbol %s", targ->name);
addgotsym(targ);
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->sym = linklookup(ctxt, ".got", 0);
r->add += targ->got;
return;
return;
switch(r->type) {
- case D_PCREL:
+ case R_PCREL:
addpltsym(targ);
r->sym = linklookup(ctxt, ".plt", 0);
r->add = targ->plt;
return;
- case D_ADDR:
+ case R_ADDR:
if(s->type == STEXT && iself) {
// The code is asking for the address of an external
// function. We provide it with the address of the
default:
return -1;
- case D_ADDR:
+ case R_ADDR:
if(r->siz == 4)
VPUT(R_X86_64_32 | (uint64)elfsym<<32);
else if(r->siz == 8)
return -1;
break;
- case D_PCREL:
+ case R_PCREL:
if(r->siz == 4) {
if(r->xsym->type == SDYNIMPORT)
VPUT(R_X86_64_GOTPCREL | (uint64)elfsym<<32);
return -1;
break;
- case D_TLS:
+ case R_TLS:
if(r->siz == 4) {
if(flag_shared)
VPUT(R_X86_64_GOTTPOFF | (uint64)elfsym<<32);
switch(r->type) {
default:
return -1;
- case D_ADDR:
+ case R_ADDR:
v |= MACHO_X86_64_RELOC_UNSIGNED<<28;
break;
- case D_PCREL:
+ case R_PCREL:
v |= 1<<24; // pc-relative bit
v |= MACHO_X86_64_RELOC_BRANCH<<28;
break;
D_INDIR, /* additive */
D_CONST2 = D_INDIR+D_INDIR,
- D_SIZE, /* 8l internal */
- D_PCREL,
- D_GOTOFF,
- D_GOTREL,
- D_TLS,
T_TYPE = 1<<0,
T_INDEX = 1<<1,
diag("unexpected R_386_PC32 relocation for dynamic symbol %s", targ->name);
if(targ->type == 0 || targ->type == SXREF)
diag("unknown symbol %s in pcrel", targ->name);
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->add += 4;
return;
case 256 + R_386_PLT32:
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->add += 4;
if(targ->type == SDYNIMPORT) {
addpltsym(ctxt, targ);
return;
}
s->p[r->off-2] = 0x8d;
- r->type = D_GOTOFF;
+ r->type = R_GOTOFF;
return;
}
addgotsym(ctxt, targ);
- r->type = D_CONST; // write r->add during relocsym
+ r->type = R_CONST; // write r->add during relocsym
r->sym = S;
r->add += targ->got;
return;
case 256 + R_386_GOTOFF:
- r->type = D_GOTOFF;
+ r->type = R_GOTOFF;
return;
case 256 + R_386_GOTPC:
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->sym = linklookup(ctxt, ".got", 0);
r->add += 4;
return;
case 256 + R_386_32:
if(targ->type == SDYNIMPORT)
diag("unexpected R_386_32 relocation for dynamic symbol %s", targ->name);
- r->type = D_ADDR;
+ r->type = R_ADDR;
return;
case 512 + MACHO_GENERIC_RELOC_VANILLA*2 + 0:
- r->type = D_ADDR;
+ r->type = R_ADDR;
if(targ->type == SDYNIMPORT)
diag("unexpected reloc for dynamic symbol %s", targ->name);
return;
addpltsym(ctxt, targ);
r->sym = linklookup(ctxt, ".plt", 0);
r->add = targ->plt;
- r->type = D_PCREL;
+ r->type = R_PCREL;
return;
}
- r->type = D_PCREL;
+ r->type = R_PCREL;
return;
case 512 + MACHO_FAKE_GOTPCREL:
return;
}
s->p[r->off-2] = 0x8d;
- r->type = D_PCREL;
+ r->type = R_PCREL;
return;
}
addgotsym(ctxt, targ);
r->sym = linklookup(ctxt, ".got", 0);
r->add += targ->got;
- r->type = D_PCREL;
+ r->type = R_PCREL;
return;
}
return;
switch(r->type) {
- case D_PCREL:
+ case R_PCREL:
addpltsym(ctxt, targ);
r->sym = linklookup(ctxt, ".plt", 0);
r->add = targ->plt;
return;
- case D_ADDR:
+ case R_ADDR:
if(s->type != SDATA)
break;
if(iself) {
rel = linklookup(ctxt, ".rel", 0);
addaddrplus(ctxt, rel, s, r->off);
adduint32(ctxt, rel, ELF32_R_INFO(targ->dynid, R_386_32));
- r->type = D_CONST; // write r->add during relocsym
+ r->type = R_CONST; // write r->add during relocsym
r->sym = S;
return;
}
default:
return -1;
- case D_ADDR:
+ case R_ADDR:
if(r->siz == 4)
LPUT(R_386_32 | elfsym<<8);
else
return -1;
break;
- case D_PCREL:
+ case R_PCREL:
if(r->siz == 4)
LPUT(R_386_PC32 | elfsym<<8);
else
return -1;
break;
- case D_TLS:
+ case R_TLS:
if(r->siz == 4)
LPUT(R_386_TLS_LE | elfsym<<8);
else
switch(r->type) {
default:
return -1;
- case D_ADDR:
+ case R_ADDR:
v |= MACHO_GENERIC_RELOC_VANILLA<<28;
break;
- case D_PCREL:
+ case R_PCREL:
v |= 1<<24; // pc-relative bit
v |= MACHO_GENERIC_RELOC_VANILLA<<28;
break;
if(linkmode == LinkExternal)
return -1;
switch(r->type) {
- case D_CONST:
+ case R_CONST:
*val = r->add;
return 0;
- case D_GOTOFF:
+ case R_GOTOFF:
*val = symaddr(r->sym) + r->add - symaddr(linklookup(ctxt, ".got", 0));
return 0;
}
if(archreloc(r, s, &o) < 0)
diag("unknown reloc %d", r->type);
break;
- case D_TLS:
+ case R_TLS:
if(linkmode == LinkInternal && iself && thechar == '5') {
// On ELF ARM, the thread pointer is 8 bytes before
// the start of the thread-local data block, so add 8
if(thechar != '6')
o = r->add;
break;
- case D_ADDR:
+ case R_ADDR:
if(linkmode == LinkExternal && r->sym->type != SCONST) {
r->done = 0;
}
o = symaddr(r->sym) + r->add;
break;
- case D_PCREL:
+ case R_PCREL:
// r->sym can be null when CALL $(constant) is transformed from absolute PC to relative PC call.
if(linkmode == LinkExternal && r->sym && r->sym->type != SCONST && r->sym->sect != ctxt->cursym->sect) {
r->done = 0;
// the standard host compiler (gcc on most other systems).
o += r->add - (s->value + r->off + (int32)r->siz);
break;
- case D_SIZE:
+ case R_SIZE:
o = r->sym->size + r->add;
break;
}
ctxt->cursym = s;
diag("bad reloc size %#ux for %s", siz, r->sym->name);
case 4:
- if(r->type == D_PCREL) {
+ if(r->type == R_PCREL) {
if(o != (int32)o)
diag("pc-relative relocation address is too big: %#llx", o);
} else {
rsname = r->sym->name;
typ = "?";
switch(r->type) {
- case D_ADDR:
+ case R_ADDR:
typ = "addr";
break;
- case D_PCREL:
+ case R_PCREL:
typ = "pcrel";
break;
}
r->xsym = sym;
r->off = cpos() - offsetbase;
r->siz = siz;
- r->type = D_ADDR;
+ r->type = R_ADDR;
r->add = addend;
r->xadd = addend;
if(iself && thechar == '6')
memset(varhash, 0, sizeof varhash);
for(a = s->autom; a; a = a->link) {
switch (a->type) {
- case D_AUTO:
+ case A_AUTO:
dt = DW_ABRV_AUTO;
offs = a->aoffset - PtrSize;
break;
- case D_PARAM:
+ case A_PARAM:
dt = DW_ABRV_PARAM;
offs = a->aoffset;
break;
// want to make it pc-relative aka relative to rp->off+4
// but the scatter asks for relative to off = (rel+1)->value - sect->addr.
// adjust rp->add accordingly.
- rp->type = D_PCREL;
+ rp->type = R_PCREL;
rp->add += (rp->off+4) - ((rel+1)->value - sect->addr);
// now consider the desired symbol.
case IMAGE_REL_AMD64_REL32:
case IMAGE_REL_AMD64_ADDR32: // R_X86_64_PC32
case IMAGE_REL_AMD64_ADDR32NB:
- rp->type = D_PCREL;
+ rp->type = R_PCREL;
rp->add = (int32)le32(rsect->base+rp->off);
break;
case IMAGE_REL_I386_DIR32NB:
case IMAGE_REL_I386_DIR32:
- rp->type = D_ADDR;
+ rp->type = R_ADDR;
// load addend from image
rp->add = le32(rsect->base+rp->off);
break;
case IMAGE_REL_AMD64_ADDR64: // R_X86_64_64
rp->siz = 8;
- rp->type = D_ADDR;
+ rp->type = R_ADDR;
// load addend from image
rp->add = le64(rsect->base+rp->off);
break;
for(a=s->autom; a; a=a->link) {
// Emit a or p according to actual offset, even if label is wrong.
// This avoids negative offsets, which cannot be encoded.
- if(a->type != D_AUTO && a->type != D_PARAM)
+ if(a->type != A_AUTO && a->type != A_PARAM)
continue;
// compute offset relative to FP
- if(a->type == D_PARAM)
+ if(a->type == A_PARAM)
off = a->aoffset;
else
off = a->aoffset - PtrSize;
}
}
-// TODO(rsc): These are the relocation types and should be
-// loaded from debug/goobj. They are not in debug/goobj
-// because they are different for each architecture.
-// The symbol file format needs to be revised to use an
-// architecture-independent set of numbers, and then
-// those should be fetched from debug/goobj instead of
-// defined here. These are the amd64 numbers.
+// TODO(rsc): Define full enumeration for relocation types.
const (
- D_ADDR = 120
- D_SIZE = 246
- D_PCREL = 247
+ R_ADDR = 1
+ R_SIZE = 2
+ R_PCREL = 5
)
// relocateSym applies relocations to sym's data.
switch r.Type {
default:
p.errorf("%v: unknown relocation type %d", sym, r.Type)
- case D_ADDR:
+ case R_ADDR:
// ok
- case D_PCREL:
+ case R_PCREL:
val -= sym.Addr + Addr(r.Offset+r.Size)
}
frag := data[r.Offset : r.Offset+r.Size]
Size: b.ptrsize,
Sym: sym,
Add: int(symoff),
- Type: D_ADDR,
+ Type: R_ADDR,
})
return off + b.ptrsize
}
rel->siz = 4;
rel->sym = p->to.sym;
rel->add = o1 | ((v >> 2) & 0xffffff);
- rel->type = D_CALL;
+ rel->type = R_CALL;
break;
}
if(p->pcond != nil)
// to the thread-local g and m pointers.
// Emit a TLS relocation instead of a standard one.
if(rel->sym == ctxt->gmsym) {
- rel->type = D_TLS;
+ rel->type = R_TLS;
if(ctxt->flag_shared)
rel->add += ctxt->pc - p->pcrel->pc - 8 - rel->siz;
rel->xadd = rel->add;
rel->xsym = rel->sym;
} else if(ctxt->flag_shared) {
- rel->type = D_PCREL;
+ rel->type = R_PCREL;
rel->add += ctxt->pc - p->pcrel->pc - 8;
} else
- rel->type = D_ADDR;
+ rel->type = R_ADDR;
o1 = 0;
}
break;
rel->add = p->pcond->pc;
}
if(o->flag & LPCREL) {
- rel->type = D_PCREL;
+ rel->type = R_PCREL;
rel->add += ctxt->pc - p->pcrel->pc - 16 + rel->siz;
} else
- rel->type = D_ADDR;
+ rel->type = R_ADDR;
o1 = 0;
}
break;
if(ctxt->flag_shared || ctxt->headtype == Hnacl) {
if(s->type == STLSBSS) {
r->xadd = r->add - r->siz;
- r->type = D_TLS;
+ r->type = R_TLS;
r->xsym = s;
} else
- r->type = D_PCREL;
+ r->type = R_PCREL;
} else
- r->type = D_ADDR;
+ r->type = R_ADDR;
}
return v;
}
r->off = p->pc + ctxt->andptr - ctxt->and;
r->sym = p->to.sym;
r->add = p->to.offset;
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->siz = 4;
put4(ctxt, 0);
break;
r = addrel(ctxt->cursym);
r->off = p->pc + ctxt->andptr - ctxt->and;
r->sym = p->to.sym;
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->siz = 4;
put4(ctxt, 0);
break;
break;
if(ctxt->rexflag)
r->off++;
- if(r->type == D_PCREL)
+ if(r->type == R_PCREL)
r->add -= p->pc + n - (r->off + r->siz);
}
ctxt->diag("need reloc for %D", a);
sysfatal("bad code");
}
- r->type = D_ADDR;
+ r->type = R_ADDR;
r->siz = 4;
r->off = -1;
r->sym = s;
*ctxt->andptr++ = op;
r = addrel(ctxt->cursym);
r->off = p->pc + ctxt->andptr - ctxt->and;
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->siz = 4;
r->sym = p->to.sym;
r->add = p->to.offset;
r = addrel(ctxt->cursym);
r->off = p->pc + ctxt->andptr - ctxt->and;
r->sym = p->to.sym;
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->siz = 4;
put4(ctxt, 0);
break;
*ctxt->andptr++ = o->op[z+1];
r = addrel(ctxt->cursym);
r->off = p->pc + ctxt->andptr - ctxt->and;
- r->type = D_PCREL;
+ r->type = R_PCREL;
r->siz = 4;
r->add = p->to.offset;
put4(ctxt, 0);
*ctxt->andptr++ = o->op[z+1];
r = addrel(ctxt->cursym);
r->off = p->pc + ctxt->andptr - ctxt->and;
- r->type = D_ADDR;
+ r->type = R_ADDR;
r->siz = 4;
r->add = p->to.offset;
r->sym = p->to.sym;
s->p[off+i] = cast[inuxi8[i]];
break;
}
- } else if(p->to.type == ctxt->arch->D_ADDR || p->to.type == ctxt->arch->D_SIZE) {
+ } else if(p->to.type == ctxt->arch->D_ADDR) {
addr:
r = addrel(s);
r->off = off;
r->siz = siz;
r->sym = p->to.sym;
- r->type = p->to.type;
- if(r->type != ctxt->arch->D_SIZE)
- r->type = ctxt->arch->D_ADDR;
+ r->type = R_ADDR;
r->add = p->to.offset;
} else {
ctxt->diag("bad data: %P", p);
r->sym = t;
r->off = i;
r->siz = ctxt->arch->ptrsize;
- r->type = ctxt->arch->D_ADDR;
+ r->type = R_ADDR;
r->add = add;
return i + r->siz;
}
r->sym = t;
r->off = i;
r->add = add;
- r->type = ctxt->arch->D_PCREL;
+ r->type = R_PCREL;
r->siz = 4;
return i + r->siz;
}
r->sym = t;
r->off = off;
r->siz = ctxt->arch->ptrsize;
- r->type = ctxt->arch->D_ADDR;
+ r->type = R_ADDR;
r->add = add;
return off + r->siz;
}
r->sym = t;
r->off = i;
r->siz = ctxt->arch->ptrsize;
- r->type = ctxt->arch->D_SIZE;
+ r->type = R_SIZE;
return i + r->siz;
}
r->sym = t;
r->off = i;
r->siz = 4;
- r->type = ctxt->arch->D_ADDR;
+ r->type = R_ADDR;
r->add = add;
return i + r->siz;
}
.regsize = 4,
.D_ADDR = D_ADDR,
+ .D_AUTO = D_AUTO,
.D_BRANCH = D_BRANCH,
.D_CONST = D_CONST,
.D_EXTERN = D_EXTERN,
.D_FCONST = D_FCONST,
.D_NONE = D_NONE,
- .D_PCREL = D_PCREL,
+ .D_PARAM = D_PARAM,
.D_SCONST = D_SCONST,
- .D_SIZE = D_SIZE,
.D_STATIC = D_STATIC,
.ACALL = ABL,
.regsize = 8,
.D_ADDR = D_ADDR,
+ .D_AUTO = D_AUTO,
.D_BRANCH = D_BRANCH,
.D_CONST = D_CONST,
.D_EXTERN = D_EXTERN,
.D_FCONST = D_FCONST,
.D_NONE = D_NONE,
- .D_PCREL = D_PCREL,
+ .D_PARAM = D_PARAM,
.D_SCONST = D_SCONST,
- .D_SIZE = D_SIZE,
.D_STATIC = D_STATIC,
.ACALL = ACALL,
.regsize = 8,
.D_ADDR = D_ADDR,
+ .D_AUTO = D_AUTO,
.D_BRANCH = D_BRANCH,
.D_CONST = D_CONST,
.D_EXTERN = D_EXTERN,
.D_FCONST = D_FCONST,
.D_NONE = D_NONE,
- .D_PCREL = D_PCREL,
+ .D_PARAM = D_PARAM,
.D_SCONST = D_SCONST,
- .D_SIZE = D_SIZE,
.D_STATIC = D_STATIC,
.ACALL = ACALL,
.regsize = 4,
.D_ADDR = D_ADDR,
+ .D_AUTO = D_AUTO,
.D_BRANCH = D_BRANCH,
.D_CONST = D_CONST,
.D_EXTERN = D_EXTERN,
.D_FCONST = D_FCONST,
.D_NONE = D_NONE,
- .D_PCREL = D_PCREL,
+ .D_PARAM = D_PARAM,
.D_SCONST = D_SCONST,
- .D_SIZE = D_SIZE,
.D_STATIC = D_STATIC,
.ACALL = ACALL,
// - nfile [int]
// - file [nfile symbol references]
//
-// The file layout is architecture-independent.
-// The meaning is almost architecture-independent:
-// the only field with architecture-dependent meaning is the
-// relocation's type field.
+// The file layout and meaning of type integers are architecture-independent.
//
// TODO(rsc): The file format is good for a first pass but needs work.
// - There are SymID in the object file that should really just be strings.
for(a = s->autom; a != nil; a = a->link) {
wrsym(b, a->asym);
wrint(b, a->aoffset);
- wrint(b, a->type);
+ if(a->type == ctxt->arch->D_AUTO)
+ wrint(b, A_AUTO);
+ else if(a->type == ctxt->arch->D_PARAM)
+ wrint(b, A_PARAM);
+ else
+ sysfatal("%s: invalid local variable type %d", s->name, a->type);
wrsym(b, a->gotype);
}