diff options
author | Russ Cox <rsc@golang.org> | 2014-04-14 15:54:20 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-04-14 15:54:20 -0400 |
commit | e8f7d40d36ebd0302f979efce335b531d67c7f3d (patch) | |
tree | 5c77311f9f013dcd93f6e07e7ced2b13ee2aab03 /src/cmd | |
parent | ea39a747252398dd95baa554526c3801e928d075 (diff) | |
download | go-e8f7d40d36ebd0302f979efce335b531d67c7f3d.tar.gz |
liblink: remove arch-specific constants from file format
The relocation and automatic variable types were using
arch-specific numbers. Introduce portable enumerations
instead.
To the best of my knowledge, these are the only arch-specific
bits left in the new object file format.
Remove now, before Go 1.3, because file formats are forever.
LGTM=iant
R=iant
CC=golang-codereviews
https://codereview.appspot.com/87670044
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/5l/5.out.h | 10 | ||||
-rw-r--r-- | src/cmd/5l/asm.c | 52 | ||||
-rw-r--r-- | src/cmd/6l/6.out.h | 4 | ||||
-rw-r--r-- | src/cmd/6l/asm.c | 34 | ||||
-rw-r--r-- | src/cmd/8l/8.out.h | 5 | ||||
-rw-r--r-- | src/cmd/8l/asm.c | 44 | ||||
-rw-r--r-- | src/cmd/ld/data.c | 14 | ||||
-rw-r--r-- | src/cmd/ld/dwarf.c | 6 | ||||
-rw-r--r-- | src/cmd/ld/ldmacho.c | 2 | ||||
-rw-r--r-- | src/cmd/ld/ldpe.c | 6 | ||||
-rw-r--r-- | src/cmd/ld/lib.c | 4 | ||||
-rw-r--r-- | src/cmd/link/load.go | 18 | ||||
-rw-r--r-- | src/cmd/link/pclntab.go | 2 | ||||
-rw-r--r-- | src/cmd/link/testdata/autosection.6 | bin | 912 -> 888 bytes | |||
-rw-r--r-- | src/cmd/link/testdata/autoweak.6 | bin | 431 -> 425 bytes | |||
-rw-r--r-- | src/cmd/link/testdata/dead.6 | bin | 1065 -> 1054 bytes | |||
-rw-r--r-- | src/cmd/link/testdata/hello.6 | bin | 272 -> 271 bytes | |||
-rw-r--r-- | src/cmd/link/testdata/layout.6 | bin | 434 -> 429 bytes | |||
-rw-r--r-- | src/cmd/link/testdata/pclntab.6 | bin | 4607 -> 4603 bytes |
19 files changed, 88 insertions, 113 deletions
diff --git a/src/cmd/5l/5.out.h b/src/cmd/5l/5.out.h index 4e71818f9..bcee45163 100644 --- a/src/cmd/5l/5.out.h +++ b/src/cmd/5l/5.out.h @@ -271,16 +271,6 @@ enum 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 }; /* diff --git a/src/cmd/5l/asm.c b/src/cmd/5l/asm.c index 096d321cb..0c2ee6f18 100644 --- a/src/cmd/5l/asm.c +++ b/src/cmd/5l/asm.c @@ -102,7 +102,7 @@ adddynrel(LSym *s, Reloc *r) // 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); @@ -121,7 +121,7 @@ adddynrel(LSym *s, Reloc *r) } 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; @@ -132,23 +132,23 @@ adddynrel(LSym *s, Reloc *r) } 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); @@ -157,14 +157,14 @@ adddynrel(LSym *s, Reloc *r) 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: @@ -178,7 +178,7 @@ adddynrel(LSym *s, Reloc *r) 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); @@ -192,13 +192,13 @@ adddynrel(LSym *s, Reloc *r) 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) { @@ -206,7 +206,7 @@ adddynrel(LSym *s, Reloc *r) 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; } @@ -229,21 +229,21 @@ elfreloc1(Reloc *r, vlong sectoff) 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); @@ -253,7 +253,7 @@ elfreloc1(Reloc *r, vlong sectoff) return -1; break; - case D_TLS: + case R_TLS: if(r->siz == 4) { if(flag_shared) LPUT(R_ARM_TLS_IE32 | elfsym<<8); @@ -310,7 +310,7 @@ archreloc(Reloc *r, LSym *s, vlong *val) if(linkmode == LinkExternal) { switch(r->type) { - case D_CALL: + case R_CALL: r->done = 0; // set up addend for eventual relocation via outer symbol. @@ -335,29 +335,29 @@ archreloc(Reloc *r, LSym *s, vlong *val) 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))); @@ -411,9 +411,9 @@ addpltsym(Link *ctxt, LSym *s) // .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); diff --git a/src/cmd/6l/6.out.h b/src/cmd/6l/6.out.h index 5fca297b0..a8e11a10d 100644 --- a/src/cmd/6l/6.out.h +++ b/src/cmd/6l/6.out.h @@ -867,10 +867,6 @@ enum 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, diff --git a/src/cmd/6l/asm.c b/src/cmd/6l/asm.c index 9474aff16..eced1a144 100644 --- a/src/cmd/6l/asm.c +++ b/src/cmd/6l/asm.c @@ -103,12 +103,12 @@ adddynrel(LSym *s, Reloc *r) 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); @@ -123,7 +123,7 @@ adddynrel(LSym *s, Reloc *r) 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; } @@ -131,7 +131,7 @@ adddynrel(LSym *s, Reloc *r) // 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; @@ -140,7 +140,7 @@ adddynrel(LSym *s, Reloc *r) 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. @@ -148,7 +148,7 @@ adddynrel(LSym *s, Reloc *r) 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; @@ -158,7 +158,7 @@ adddynrel(LSym *s, Reloc *r) addpltsym(targ); r->sym = linklookup(ctxt, ".plt", 0); r->add = targ->plt; - r->type = D_PCREL; + r->type = R_PCREL; return; } // fall through @@ -167,7 +167,7 @@ adddynrel(LSym *s, Reloc *r) 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; @@ -181,7 +181,7 @@ adddynrel(LSym *s, Reloc *r) return; } s->p[r->off-2] = 0x8d; - r->type = D_PCREL; + r->type = R_PCREL; return; } // fall through @@ -189,7 +189,7 @@ adddynrel(LSym *s, Reloc *r) 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; @@ -200,13 +200,13 @@ adddynrel(LSym *s, Reloc *r) 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 @@ -272,7 +272,7 @@ elfreloc1(Reloc *r, vlong sectoff) 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) @@ -281,7 +281,7 @@ elfreloc1(Reloc *r, vlong sectoff) 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); @@ -291,7 +291,7 @@ elfreloc1(Reloc *r, vlong sectoff) return -1; break; - case D_TLS: + case R_TLS: if(r->siz == 4) { if(flag_shared) VPUT(R_X86_64_GOTTPOFF | (uint64)elfsym<<32); @@ -332,10 +332,10 @@ machoreloc1(Reloc *r, vlong sectoff) 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; diff --git a/src/cmd/8l/8.out.h b/src/cmd/8l/8.out.h index 3d3c40c75..0dcd74a61 100644 --- a/src/cmd/8l/8.out.h +++ b/src/cmd/8l/8.out.h @@ -655,11 +655,6 @@ enum 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, diff --git a/src/cmd/8l/asm.c b/src/cmd/8l/asm.c index cc4ec564b..6bd2c1fdb 100644 --- a/src/cmd/8l/asm.c +++ b/src/cmd/8l/asm.c @@ -100,12 +100,12 @@ adddynrel(LSym *s, Reloc *r) 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); @@ -123,21 +123,21 @@ adddynrel(LSym *s, Reloc *r) 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; @@ -145,11 +145,11 @@ adddynrel(LSym *s, Reloc *r) 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; @@ -159,10 +159,10 @@ adddynrel(LSym *s, Reloc *r) 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: @@ -174,13 +174,13 @@ adddynrel(LSym *s, Reloc *r) 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; } @@ -189,13 +189,13 @@ adddynrel(LSym *s, Reloc *r) 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) { @@ -203,7 +203,7 @@ adddynrel(LSym *s, Reloc *r) 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; } @@ -249,21 +249,21 @@ elfreloc1(Reloc *r, vlong sectoff) 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 @@ -299,10 +299,10 @@ machoreloc1(Reloc *r, vlong sectoff) 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; @@ -337,10 +337,10 @@ archreloc(Reloc *r, LSym *s, vlong *val) 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; } diff --git a/src/cmd/ld/data.c b/src/cmd/ld/data.c index 7c4c98532..f4fcc6881 100644 --- a/src/cmd/ld/data.c +++ b/src/cmd/ld/data.c @@ -166,7 +166,7 @@ relocsym(LSym *s) 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 @@ -183,7 +183,7 @@ relocsym(LSym *s) if(thechar != '6') o = r->add; break; - case D_ADDR: + case R_ADDR: if(linkmode == LinkExternal && r->sym->type != SCONST) { r->done = 0; @@ -212,7 +212,7 @@ relocsym(LSym *s) } 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; @@ -253,7 +253,7 @@ relocsym(LSym *s) // 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; } @@ -263,7 +263,7 @@ relocsym(LSym *s) 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 { @@ -524,10 +524,10 @@ datblk(int32 addr, int32 size) 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; } diff --git a/src/cmd/ld/dwarf.c b/src/cmd/ld/dwarf.c index 9966cc8d1..ff67223ad 100644 --- a/src/cmd/ld/dwarf.c +++ b/src/cmd/ld/dwarf.c @@ -603,7 +603,7 @@ adddwarfrel(LSym* sec, LSym* sym, vlong offsetbase, int siz, vlong addend) 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') @@ -1638,11 +1638,11 @@ writelines(void) 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; diff --git a/src/cmd/ld/ldmacho.c b/src/cmd/ld/ldmacho.c index 14db81127..7fd366a25 100644 --- a/src/cmd/ld/ldmacho.c +++ b/src/cmd/ld/ldmacho.c @@ -744,7 +744,7 @@ ldmacho(Biobuf *f, char *pkg, int64 len, char *pn) // 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. diff --git a/src/cmd/ld/ldpe.c b/src/cmd/ld/ldpe.c index f7e4bfcdb..57ef61c57 100644 --- a/src/cmd/ld/ldpe.c +++ b/src/cmd/ld/ldpe.c @@ -290,18 +290,18 @@ ldpe(Biobuf *f, char *pkg, int64 len, char *pn) 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; diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c index d49e6bcf8..bfbdcd145 100644 --- a/src/cmd/ld/lib.c +++ b/src/cmd/ld/lib.c @@ -1358,11 +1358,11 @@ genasmsym(void (*put)(LSym*, char*, int, vlong, vlong, int, LSym*)) 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; diff --git a/src/cmd/link/load.go b/src/cmd/link/load.go index 5b757faf0..f1df3abf9 100644 --- a/src/cmd/link/load.go +++ b/src/cmd/link/load.go @@ -73,17 +73,11 @@ func (p *Prog) loadPackage(pkg *Package) { } } -// 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. @@ -99,9 +93,9 @@ func (p *Prog) relocateSym(sym *Sym, data []byte) { 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] diff --git a/src/cmd/link/pclntab.go b/src/cmd/link/pclntab.go index f3b6ceb40..b0b19ad53 100644 --- a/src/cmd/link/pclntab.go +++ b/src/cmd/link/pclntab.go @@ -371,7 +371,7 @@ func (b *SymBuffer) Addr(off int, sym goobj.SymID, symoff int64) int { Size: b.ptrsize, Sym: sym, Add: int(symoff), - Type: D_ADDR, + Type: R_ADDR, }) return off + b.ptrsize } diff --git a/src/cmd/link/testdata/autosection.6 b/src/cmd/link/testdata/autosection.6 Binary files differindex 996268061..3a2e35a5b 100644 --- a/src/cmd/link/testdata/autosection.6 +++ b/src/cmd/link/testdata/autosection.6 diff --git a/src/cmd/link/testdata/autoweak.6 b/src/cmd/link/testdata/autoweak.6 Binary files differindex 7bf428b51..1fd54ed7e 100644 --- a/src/cmd/link/testdata/autoweak.6 +++ b/src/cmd/link/testdata/autoweak.6 diff --git a/src/cmd/link/testdata/dead.6 b/src/cmd/link/testdata/dead.6 Binary files differindex a512543cb..e0cdecea9 100644 --- a/src/cmd/link/testdata/dead.6 +++ b/src/cmd/link/testdata/dead.6 diff --git a/src/cmd/link/testdata/hello.6 b/src/cmd/link/testdata/hello.6 Binary files differindex c6435a5e6..9ec799b4f 100644 --- a/src/cmd/link/testdata/hello.6 +++ b/src/cmd/link/testdata/hello.6 diff --git a/src/cmd/link/testdata/layout.6 b/src/cmd/link/testdata/layout.6 Binary files differindex 0a600d7c7..c5121ff15 100644 --- a/src/cmd/link/testdata/layout.6 +++ b/src/cmd/link/testdata/layout.6 diff --git a/src/cmd/link/testdata/pclntab.6 b/src/cmd/link/testdata/pclntab.6 Binary files differindex 722a7f806..0f7ab6dd7 100644 --- a/src/cmd/link/testdata/pclntab.6 +++ b/src/cmd/link/testdata/pclntab.6 |