From 8d39e55c6516be5ee3267b8ce101b324a4f09986 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 14 Apr 2014 15:54:20 -0400 Subject: [PATCH] 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://golang.org/cl/87670044 --- include/link.h | 26 ++++++++++++-- src/cmd/5l/5.out.h | 10 ------ src/cmd/5l/asm.c | 52 ++++++++++++++-------------- src/cmd/6l/6.out.h | 4 --- src/cmd/6l/asm.c | 34 +++++++++--------- src/cmd/8l/8.out.h | 5 --- src/cmd/8l/asm.c | 44 +++++++++++------------ src/cmd/ld/data.c | 14 ++++---- src/cmd/ld/dwarf.c | 6 ++-- src/cmd/ld/ldmacho.c | 2 +- src/cmd/ld/ldpe.c | 6 ++-- src/cmd/ld/lib.c | 4 +-- src/cmd/link/load.go | 18 ++++------ src/cmd/link/pclntab.go | 2 +- src/cmd/link/testdata/autosection.6 | Bin 912 -> 888 bytes src/cmd/link/testdata/autoweak.6 | Bin 431 -> 425 bytes src/cmd/link/testdata/dead.6 | Bin 1065 -> 1054 bytes src/cmd/link/testdata/hello.6 | Bin 272 -> 271 bytes src/cmd/link/testdata/layout.6 | Bin 434 -> 429 bytes src/cmd/link/testdata/pclntab.6 | Bin 4607 -> 4603 bytes src/liblink/asm5.c | 12 +++---- src/liblink/asm6.c | 12 +++---- src/liblink/asm8.c | 10 +++--- src/liblink/data.c | 16 ++++----- src/liblink/obj5.c | 4 +-- src/liblink/obj6.c | 8 ++--- src/liblink/obj8.c | 4 +-- src/liblink/objfile.c | 12 ++++--- 28 files changed, 151 insertions(+), 154 deletions(-) diff --git a/include/link.h b/include/link.h index a762424d22..92b8b73b6b 100644 --- a/include/link.h +++ b/include/link.h @@ -223,6 +223,28 @@ enum 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; @@ -420,14 +442,14 @@ struct LinkArch // 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; diff --git a/src/cmd/5l/5.out.h b/src/cmd/5l/5.out.h index 4e71818f91..bcee45163d 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 096d321cb9..0c2ee6f187 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 5fca297b0f..a8e11a10d2 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 9474aff168..eced1a1441 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 3d3c40c755..0dcd74a61d 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 cc4ec564bd..6bd2c1fdb7 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 7c4c985324..f4fcc68812 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 9966cc8d1f..ff67223ad2 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 14db811277..7fd366a258 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 f7e4bfcdb2..57ef61c57e 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 d49e6bcf8f..bfbdcd145b 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 5b757faf00..f1df3abf90 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 f3b6ceb403..b0b19ad53c 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 index 996268061bb8eae0b015b2c5796f6f755b66f40f..3a2e35a5b227ebca6093cb358a0762e802a51680 100644 GIT binary patch literal 888 zcmdT@OHKko5G^`FCdA-`7~`_t0@^bJh+(A%FmdDFfoTW|(`35+#1%*I2pqwsOA;@@ z5jcV;0INR&;t8yzCwcX%YTmrA=?f}4_q?lU5@*kYl*Xgvyg?KG#D}!n3ZgJ-Ui3Px zs7|j%O0UKl4I4D9x1*rl3~3Y~It>~@K&!=*B0yh+^9;*!T3gZBvKzwsbM|qMb1tdt1-AbNGmdP&bv%X+5>$2`BVZ%ZC zz!aA%iB-(>Xo+7m5b2pD%Zm5PGXdb^2w2w28l}R#i<(qrBW8ip^!Z;=10OYeioYln z?rY%82cQOV#|1uK$C|q|ZQ3(zyU}3d1l-w1$BupCK`9lf^%5pIO&2;+V(Xg$&Ssce z#4Y!Z$cGtu~tVmI+C{sWvK;;9_%;)of zcwaeyQuL^Vih9T&Zi$J?kXWM~0ThUDPN|Y7c~U?J>9bqOGs!X;vjH0jCbO8ut<-sw7eo)43(SX(-ZjNmfXM zVdcI-ZU6w(Lhif)LJAx2r47}M!_XUpw*7!R7wr5KgdUVqk=mZZG-m{bo|G8=W|3<+ z%pBy_`>vr6Ki;|Zmdz|&{)OdE+y!n-u(b3s-_>F+oo-({C8i?ZNL^W$+MPVi9A{Iy y0yRhBmu_x#1)e7Oz{MYmRdw4B52t{W(0jI57jB=wSu70EOKSIB%hzlB=X?VyhQO%+ diff --git a/src/cmd/link/testdata/autoweak.6 b/src/cmd/link/testdata/autoweak.6 index 7bf428b51dcc62577675796ecc31b1ede76c5cff..1fd54ed7e60d52f1247958df3b85dadb9369d70f 100644 GIT binary patch delta 125 zcmZ3_ypnl>oUFNlk)e^PMOu=%k+Fhrex8D3L6L%?iGrcAm65?jYfC{U1_r*w(vtj= z#3Tj=1|ANkiS2W2fP!M_`FiE4iP?I^mAOC(0Rf;G8-%R@VynR9b2E#JGxO3RQVs%4 Ilam>J0Co}{DF6Tf delta 131 zcmZ32r5m8T|V>lIh#0;L25K!R)#jslpY0#lKjSzMf%mkyD0 L0Lo2{W%L06J$57} diff --git a/src/cmd/link/testdata/dead.6 b/src/cmd/link/testdata/dead.6 index a512543cba614b4497add9f81ef6d5883635fce4..e0cdecea96b934cdb54ef1416a675cd3d4dca273 100644 GIT binary patch delta 168 zcmZ3C%!y*Crog3+Glv5JY~n7P diff --git a/src/cmd/link/testdata/hello.6 b/src/cmd/link/testdata/hello.6 index c6435a5e6fd6d964cd87e456a99f087a97fe0e0a..9ec799b4f39e5c1f2944573a46c7f7a091cbe895 100644 GIT binary patch delta 44 zcmbQh)Xy|QPS)JO$k52tA}z_>$XLNQKTpB2ph&^cM8VM5%E(}%bpRvN#NK8A{sRlH delta 45 zcmeBYn!q$cPS(=YFxk{J%`hp&%s|06KTpB2ph&^cM8VL=%Gh|KbpX=`#)&=602z@D A0ssI2 diff --git a/src/cmd/link/testdata/layout.6 b/src/cmd/link/testdata/layout.6 index 0a600d7c74994a8ea741b7891f1d1e8b021fd93e..c5121ff154a5b12ba4f13ff087a3d8c37ef4f345 100644 GIT binary patch delta 118 zcmdnQyq0-_oUFNlk)e^PMOu=%k+Fhrex8D3L6L%?iGrcAm65?jYhQ0B1_qI${FKC! t#Q5UMTm}XP9uA<8R9=2TNfDB$7)VqANk9Q4z?W294ArK^!8Gy4EdcW<9m4yoq^&oUEm(VX~=dnqg9knSp|Dex8D3L6L%?iGrb#m9gz@MJTnr3cX{C9| c1`G@gJRC5dA&@5q=NSQc3LH$6lLhAh0P)`w{Qv*} delta 92 zcmeyZ{9k#3oUEm(VX~=dnqg9knSp|Dex8D3L6L%?iGrb#m9gz@Mp@0b}FxYA1V ek_{Lb7pc), p->from.sym->na 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) @@ -1372,16 +1372,16 @@ if(0 /*debug['G']*/) print("%ux: %s: arm %d\n", (uint32)(p->pc), p->from.sym->na // 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; @@ -1720,10 +1720,10 @@ if(0 /*debug['G']*/) print("%ux: %s: arm %d\n", (uint32)(p->pc), p->from.sym->na 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; diff --git a/src/liblink/asm6.c b/src/liblink/asm6.c index 07ca35edae..213b1b55d7 100644 --- a/src/liblink/asm6.c +++ b/src/liblink/asm6.c @@ -2272,12 +2272,12 @@ vaddr(Link *ctxt, Addr *a, Reloc *r) 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; } @@ -3024,7 +3024,7 @@ found: 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; @@ -3042,7 +3042,7 @@ found: 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; @@ -3461,7 +3461,7 @@ asmins(Link *ctxt, Prog *p) 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); } diff --git a/src/liblink/asm8.c b/src/liblink/asm8.c index 4d209cbdfa..2bf6707e1e 100644 --- a/src/liblink/asm8.c +++ b/src/liblink/asm8.c @@ -1717,7 +1717,7 @@ vaddr(Link *ctxt, Addr *a, Reloc *r) 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; @@ -2360,7 +2360,7 @@ found: *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; @@ -2379,7 +2379,7 @@ found: 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; @@ -2445,7 +2445,7 @@ found: *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); @@ -2456,7 +2456,7 @@ found: *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; diff --git a/src/liblink/data.c b/src/liblink/data.c index 58d6d6b5e8..4504f4171e 100644 --- a/src/liblink/data.c +++ b/src/liblink/data.c @@ -130,15 +130,13 @@ savedata(Link *ctxt, LSym *s, Prog *p, char *pn) 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); @@ -271,7 +269,7 @@ addaddrplus(Link *ctxt, LSym *s, LSym *t, vlong add) 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; } @@ -292,7 +290,7 @@ addpcrelplus(Link *ctxt, LSym *s, LSym *t, vlong add) 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; } @@ -319,7 +317,7 @@ setaddrplus(Link *ctxt, LSym *s, vlong off, LSym *t, vlong add) 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; } @@ -346,7 +344,7 @@ addsize(Link *ctxt, LSym *s, LSym *t) 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; } @@ -366,7 +364,7 @@ addaddrplus4(Link *ctxt, LSym *s, LSym *t, vlong add) 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; } diff --git a/src/liblink/obj5.c b/src/liblink/obj5.c index 96d7aa052d..1b1c7df5fe 100644 --- a/src/liblink/obj5.c +++ b/src/liblink/obj5.c @@ -1039,14 +1039,14 @@ LinkArch linkarm = { .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, diff --git a/src/liblink/obj6.c b/src/liblink/obj6.c index 6cfa67f09e..b4329e8862 100644 --- a/src/liblink/obj6.c +++ b/src/liblink/obj6.c @@ -1121,14 +1121,14 @@ LinkArch linkamd64 = { .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, @@ -1166,14 +1166,14 @@ LinkArch linkamd64p32 = { .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, diff --git a/src/liblink/obj8.c b/src/liblink/obj8.c index 6e40d04a56..d36db84705 100644 --- a/src/liblink/obj8.c +++ b/src/liblink/obj8.c @@ -875,14 +875,14 @@ LinkArch link386 = { .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, diff --git a/src/liblink/objfile.c b/src/liblink/objfile.c index f0f3f76223..2b11add3b6 100644 --- a/src/liblink/objfile.c +++ b/src/liblink/objfile.c @@ -83,10 +83,7 @@ // - 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. @@ -346,7 +343,12 @@ writesym(Link *ctxt, Biobuf *b, LSym *s) 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); } -- 2.48.1