]> Cypherpunks repositories - gostls13.git/commitdiff
liblink: remove arch-specific constants from file format
authorRuss Cox <rsc@golang.org>
Mon, 14 Apr 2014 19:54:20 +0000 (15:54 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 14 Apr 2014 19:54:20 +0000 (15:54 -0400)
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

28 files changed:
include/link.h
src/cmd/5l/5.out.h
src/cmd/5l/asm.c
src/cmd/6l/6.out.h
src/cmd/6l/asm.c
src/cmd/8l/8.out.h
src/cmd/8l/asm.c
src/cmd/ld/data.c
src/cmd/ld/dwarf.c
src/cmd/ld/ldmacho.c
src/cmd/ld/ldpe.c
src/cmd/ld/lib.c
src/cmd/link/load.go
src/cmd/link/pclntab.go
src/cmd/link/testdata/autosection.6
src/cmd/link/testdata/autoweak.6
src/cmd/link/testdata/dead.6
src/cmd/link/testdata/hello.6
src/cmd/link/testdata/layout.6
src/cmd/link/testdata/pclntab.6
src/liblink/asm5.c
src/liblink/asm6.c
src/liblink/asm8.c
src/liblink/data.c
src/liblink/obj5.c
src/liblink/obj6.c
src/liblink/obj8.c
src/liblink/objfile.c

index a762424d228cb5327e327c45a8ed483e82992e4d..92b8b73b6b4cfb805878e397d0e66aa5ae8b70e0 100644 (file)
@@ -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;
index 4e71818f91597785f74a92487b95613748451187..bcee45163d48659adabb0635687962a48d24c4df 100644 (file)
@@ -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
 };
 
 /*
index 096d321cb98ea34d81e7bc475914333bf188dd05..0c2ee6f18770e3b815a5879cda40ff83962ea591 100644 (file)
@@ -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);
index 5fca297b0f89f515c9d95c24bd74d18b42b47e5d..a8e11a10d27c9366503fc24a3bd5136477392edb 100644 (file)
@@ -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,
index 9474aff168c4743299724b56deb1c0e4870b1845..eced1a1441053e6a44e97af45da599bb1f1dfe1d 100644 (file)
@@ -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;
index 3d3c40c7553b2c3268a0d8ad9f86a191ff95a613..0dcd74a61d35a99c64686975ac2e775062c4b951 100644 (file)
@@ -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,
index cc4ec564bdf3e2e0947f87341c42d04628c7c554..6bd2c1fdb7f39780cc034201973f8aa06772ab29 100644 (file)
@@ -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;
        }
index 7c4c9853240ee9d1d989236d50bd782d5d9f356f..f4fcc68812bf8f3ca5bfc4ec43fd2f3adaf3d2ec 100644 (file)
@@ -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;
                                }
index 9966cc8d1f9ee389b6562dee22b67b0f8540bae5..ff67223ad28e57faef01a5085228301b61e35713 100644 (file)
@@ -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;
index 14db811277618057b81e047e88030f6a1081c7d9..7fd366a258ae116546d1a8c72a783d4d3a6dc2a7 100644 (file)
@@ -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.
index f7e4bfcdb25e4f4d0afa51cd56cb53e8de10c9bc..57ef61c57e9e5d065d1e5558de0f37392eb1bba7 100644 (file)
@@ -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;
index d49e6bcf8fbfa4f6b548860a163c1fc175e7ca33..bfbdcd145b52872b4ca4c8fd06b9e107af23c8dc 100644 (file)
@@ -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;
index 5b757faf00d5983160886f22e92bfcba3cb55c7e..f1df3abf900be1c2b6c8f99ddfe62ae9dfd89af1 100644 (file)
@@ -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]
index f3b6ceb40326bda79445d81629e7fc53de34112d..b0b19ad53c07b5f549134667215175d057399333 100644 (file)
@@ -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
 }
index 996268061bb8eae0b015b2c5796f6f755b66f40f..3a2e35a5b227ebca6093cb358a0762e802a51680 100644 (file)
Binary files a/src/cmd/link/testdata/autosection.6 and b/src/cmd/link/testdata/autosection.6 differ
index 7bf428b51dcc62577675796ecc31b1ede76c5cff..1fd54ed7e60d52f1247958df3b85dadb9369d70f 100644 (file)
Binary files a/src/cmd/link/testdata/autoweak.6 and b/src/cmd/link/testdata/autoweak.6 differ
index a512543cba614b4497add9f81ef6d5883635fce4..e0cdecea96b934cdb54ef1416a675cd3d4dca273 100644 (file)
Binary files a/src/cmd/link/testdata/dead.6 and b/src/cmd/link/testdata/dead.6 differ
index c6435a5e6fd6d964cd87e456a99f087a97fe0e0a..9ec799b4f39e5c1f2944573a46c7f7a091cbe895 100644 (file)
Binary files a/src/cmd/link/testdata/hello.6 and b/src/cmd/link/testdata/hello.6 differ
index 0a600d7c74994a8ea741b7891f1d1e8b021fd93e..c5121ff154a5b12ba4f13ff087a3d8c37ef4f345 100644 (file)
Binary files a/src/cmd/link/testdata/layout.6 and b/src/cmd/link/testdata/layout.6 differ
index 722a7f806e8ddf84997c425a963fd77a06a718c4..0f7ab6dd78b59ff505d186408427dc18c909d305 100644 (file)
Binary files a/src/cmd/link/testdata/pclntab.6 and b/src/cmd/link/testdata/pclntab.6 differ
index 39aded0339af162edd3d7800fa2e14a2c74dc1c4..c11287c8bfe0ff449dd4b48d5abb5cecfcf0eac9 100644 (file)
@@ -1302,7 +1302,7 @@ if(0 /*debug['G']*/) print("%ux: %s: arm %d\n", (uint32)(p->pc), 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;
index 07ca35edae0a1c35db80716bbf9d9f1a9ce3449f..213b1b55d780462174541f5a4e88732d830e4f90 100644 (file)
@@ -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);
        }
 
index 4d209cbdfafb1c31ecde2058ac09b19423541ec8..2bf6707e1eb7eb421a8bd359408b2602f09a7f6f 100644 (file)
@@ -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;
index 58d6d6b5e8f58eb66cb54d89531a479b72f59ca9..4504f4171e156ca2850e1cd0839d321a87b40db5 100644 (file)
@@ -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;
 }
index 96d7aa052dda87c0acf2a9e8de77c93b1239995b..1b1c7df5feb3ec6cf51490de9b1d195c3ba1ee4d 100644 (file)
@@ -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,
index 6cfa67f09e952c78af22b66c5da14751c64dde7c..b4329e886204bc5f68403b96378358d85d45aab1 100644 (file)
@@ -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,
index 6e40d04a56ba255cbf402c244a207b2248ff25a9..d36db84705e0cd255a4eff226621047b88fd6d44 100644 (file)
@@ -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,
index f0f3f7622349359daef0e63ad7cdc700ccaaf4b1..2b11add3b674c16262738a9590c8062dd7d485b3 100644 (file)
 //     - 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);
                }