summaryrefslogtreecommitdiff
path: root/src/cmd/5l
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-04-14 15:54:20 -0400
committerRuss Cox <rsc@golang.org>2014-04-14 15:54:20 -0400
commite8f7d40d36ebd0302f979efce335b531d67c7f3d (patch)
tree5c77311f9f013dcd93f6e07e7ced2b13ee2aab03 /src/cmd/5l
parentea39a747252398dd95baa554526c3801e928d075 (diff)
downloadgo-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/5l')
-rw-r--r--src/cmd/5l/5.out.h10
-rw-r--r--src/cmd/5l/asm.c52
2 files changed, 26 insertions, 36 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);