diff options
Diffstat (limited to 'src/cmd/link/internal/arm/asm.go')
| -rw-r--r-- | src/cmd/link/internal/arm/asm.go | 148 |
1 files changed, 74 insertions, 74 deletions
diff --git a/src/cmd/link/internal/arm/asm.go b/src/cmd/link/internal/arm/asm.go index 53811c02fd..51c2613add 100644 --- a/src/cmd/link/internal/arm/asm.go +++ b/src/cmd/link/internal/arm/asm.go @@ -31,7 +31,7 @@ package arm import ( - "cmd/internal/obj" + "cmd/internal/objabi" "cmd/link/internal/ld" "fmt" "log" @@ -63,14 +63,14 @@ func gentext(ctxt *ld.Link) { return } addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0) - if addmoduledata.Type == obj.STEXT && ld.Buildmode != ld.BuildmodePlugin { + if addmoduledata.Type == objabi.STEXT && ld.Buildmode != ld.BuildmodePlugin { // we're linking a module containing the runtime -> no need for // an init function return } addmoduledata.Attr |= ld.AttrReachable initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0) - initfunc.Type = obj.STEXT + initfunc.Type = objabi.STEXT initfunc.Attr |= ld.AttrLocal initfunc.Attr |= ld.AttrReachable o := func(op uint32) { @@ -84,7 +84,7 @@ func gentext(ctxt *ld.Link) { rel.Off = 8 rel.Siz = 4 rel.Sym = ctxt.Syms.Lookup("runtime.addmoduledata", 0) - rel.Type = obj.R_CALLARM + rel.Type = objabi.R_CALLARM rel.Add = 0xeafffffe // vomit o(0x00000000) @@ -92,7 +92,7 @@ func gentext(ctxt *ld.Link) { rel.Off = 12 rel.Siz = 4 rel.Sym = ctxt.Moduledata - rel.Type = obj.R_PCREL + rel.Type = objabi.R_PCREL rel.Add = 4 if ld.Buildmode == ld.BuildmodePlugin { @@ -102,7 +102,7 @@ func gentext(ctxt *ld.Link) { initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0) initarray_entry.Attr |= ld.AttrReachable initarray_entry.Attr |= ld.AttrLocal - initarray_entry.Type = obj.SINITARR + initarray_entry.Type = objabi.SINITARR ld.Addaddr(ctxt, initarray_entry, initfunc) } @@ -124,9 +124,9 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { // Handle relocations found in ELF object files. case 256 + ld.R_ARM_PLT32: - r.Type = obj.R_CALLARM + r.Type = objabi.R_CALLARM - if targ.Type == obj.SDYNIMPORT { + if targ.Type == objabi.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Add = int64(braddoff(int32(r.Add), targ.Plt/4)) @@ -139,44 +139,44 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { return false case 256 + ld.R_ARM_GOT32: // R_ARM_GOT_BREL - if targ.Type != obj.SDYNIMPORT { + if targ.Type != objabi.SDYNIMPORT { addgotsyminternal(ctxt, targ) } else { addgotsym(ctxt, targ) } - r.Type = obj.R_CONST // write r->add during relocsym + r.Type = objabi.R_CONST // write r->add during relocsym r.Sym = nil r.Add += int64(targ.Got) return true case 256 + ld.R_ARM_GOT_PREL: // GOT(nil) + A - nil - if targ.Type != obj.SDYNIMPORT { + if targ.Type != objabi.SDYNIMPORT { addgotsyminternal(ctxt, targ) } else { addgotsym(ctxt, targ) } - r.Type = obj.R_PCREL + r.Type = objabi.R_PCREL r.Sym = ctxt.Syms.Lookup(".got", 0) r.Add += int64(targ.Got) + 4 return true case 256 + ld.R_ARM_GOTOFF: // R_ARM_GOTOFF32 - r.Type = obj.R_GOTOFF + r.Type = objabi.R_GOTOFF return true case 256 + ld.R_ARM_GOTPC: // R_ARM_BASE_PREL - r.Type = obj.R_PCREL + r.Type = objabi.R_PCREL r.Sym = ctxt.Syms.Lookup(".got", 0) r.Add += 4 return true case 256 + ld.R_ARM_CALL: - r.Type = obj.R_CALLARM - if targ.Type == obj.SDYNIMPORT { + r.Type = objabi.R_CALLARM + if targ.Type == objabi.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Add = int64(braddoff(int32(r.Add), targ.Plt/4)) @@ -185,16 +185,16 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { return true case 256 + ld.R_ARM_REL32: // R_ARM_REL32 - r.Type = obj.R_PCREL + r.Type = objabi.R_PCREL r.Add += 4 return true case 256 + ld.R_ARM_ABS32: - if targ.Type == obj.SDYNIMPORT { + if targ.Type == objabi.SDYNIMPORT { ld.Errorf(s, "unexpected R_ARM_ABS32 relocation for dynamic symbol %s", targ.Name) } - r.Type = obj.R_ADDR + r.Type = objabi.R_ADDR return true // we can just ignore this, because we are targeting ARM V5+ anyway @@ -209,8 +209,8 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { case 256 + ld.R_ARM_PC24, 256 + ld.R_ARM_JUMP24: - r.Type = obj.R_CALLARM - if targ.Type == obj.SDYNIMPORT { + r.Type = objabi.R_CALLARM + if targ.Type == objabi.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Add = int64(braddoff(int32(r.Add), targ.Plt/4)) @@ -220,19 +220,19 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { } // Handle references to ELF symbols from our own object files. - if targ.Type != obj.SDYNIMPORT { + if targ.Type != objabi.SDYNIMPORT { return true } switch r.Type { - case obj.R_CALLARM: + case objabi.R_CALLARM: addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Add = int64(targ.Plt) return true - case obj.R_ADDR: - if s.Type != obj.SDATA { + case objabi.R_ADDR: + if s.Type != objabi.SDATA { break } if ld.Iself { @@ -240,7 +240,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { rel := ctxt.Syms.Lookup(".rel", 0) ld.Addaddrplus(ctxt, rel, s, int64(r.Off)) ld.Adduint32(ctxt, rel, ld.ELF32_R_INFO(uint32(targ.Dynid), ld.R_ARM_GLOB_DAT)) // we need a nil + A dynamic reloc - r.Type = obj.R_CONST // write r->add during relocsym + r.Type = objabi.R_CONST // write r->add during relocsym r.Sym = nil return true } @@ -257,21 +257,21 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { default: return -1 - case obj.R_ADDR: + case objabi.R_ADDR: if r.Siz == 4 { ld.Thearch.Lput(ld.R_ARM_ABS32 | uint32(elfsym)<<8) } else { return -1 } - case obj.R_PCREL: + case objabi.R_PCREL: if r.Siz == 4 { ld.Thearch.Lput(ld.R_ARM_REL32 | uint32(elfsym)<<8) } else { return -1 } - case obj.R_CALLARM: + case objabi.R_CALLARM: if r.Siz == 4 { if r.Add&0xff000000 == 0xeb000000 { // BL ld.Thearch.Lput(ld.R_ARM_CALL | uint32(elfsym)<<8) @@ -282,13 +282,13 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { return -1 } - case obj.R_TLS_LE: + case objabi.R_TLS_LE: ld.Thearch.Lput(ld.R_ARM_TLS_LE32 | uint32(elfsym)<<8) - case obj.R_TLS_IE: + case objabi.R_TLS_IE: ld.Thearch.Lput(ld.R_ARM_TLS_IE32 | uint32(elfsym)<<8) - case obj.R_GOTPCREL: + case objabi.R_GOTPCREL: if r.Siz == 4 { ld.Thearch.Lput(ld.R_ARM_GOT_PREL | uint32(elfsym)<<8) } else { @@ -331,8 +331,8 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { rs := r.Xsym - if r.Type == obj.R_PCREL { - if rs.Type == obj.SHOSTOBJ { + if r.Type == objabi.R_PCREL { + if rs.Type == objabi.SHOSTOBJ { ld.Errorf(s, "pc-relative relocation of external symbol is not supported") return -1 } @@ -361,7 +361,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { return 0 } - if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_CALLARM { + if rs.Type == objabi.SHOSTOBJ || r.Type == objabi.R_CALLARM { if rs.Dynid < 0 { ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) return -1 @@ -381,10 +381,10 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { default: return -1 - case obj.R_ADDR: + case objabi.R_ADDR: v |= ld.MACHO_GENERIC_RELOC_VANILLA << 28 - case obj.R_CALLARM: + case objabi.R_CALLARM: v |= 1 << 24 // pc-relative bit v |= ld.MACHO_ARM_RELOC_BR24 << 28 } @@ -430,7 +430,7 @@ func immrot(v uint32) uint32 { // Convert the direct jump relocation r to refer to a trampoline if the target is too far func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) { switch r.Type { - case obj.R_CALLARM: + case objabi.R_CALLARM: // r.Add is the instruction // low 24-bit encodes the target address t := (ld.Symaddr(r.Sym) + int64(signext24(r.Add&0xffffff)*4) - (s.Value + int64(r.Off))) / 4 @@ -443,7 +443,7 @@ func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) { for i := 0; ; i++ { name := r.Sym.Name + fmt.Sprintf("%+d-tramp%d", offset, i) tramp = ctxt.Syms.Lookup(name, int(r.Sym.Version)) - if tramp.Type == obj.SDYNIMPORT { + if tramp.Type == objabi.SDYNIMPORT { // don't reuse trampoline defined in other module continue } @@ -500,7 +500,7 @@ func gentramp(tramp, target *ld.Symbol, offset int64) { if ld.Linkmode == ld.LinkExternal { r := ld.Addrel(tramp) r.Off = 8 - r.Type = obj.R_ADDR + r.Type = objabi.R_ADDR r.Siz = 4 r.Sym = target r.Add = offset @@ -522,7 +522,7 @@ func gentramppic(tramp, target *ld.Symbol, offset int64) { r := ld.Addrel(tramp) r.Off = 12 - r.Type = obj.R_PCREL + r.Type = objabi.R_PCREL r.Siz = 4 r.Sym = target r.Add = offset + 4 @@ -557,7 +557,7 @@ func gentrampdyn(tramp, target *ld.Symbol, offset int64) { r := ld.Addrel(tramp) r.Off = 16 - r.Type = obj.R_GOTPCREL + r.Type = objabi.R_GOTPCREL r.Siz = 4 r.Sym = target r.Add = 8 @@ -571,7 +571,7 @@ func gentrampdyn(tramp, target *ld.Symbol, offset int64) { func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { if ld.Linkmode == ld.LinkExternal { switch r.Type { - case obj.R_CALLARM: + case objabi.R_CALLARM: r.Done = 0 // set up addend for eventual relocation via outer symbol. @@ -584,7 +584,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { rs = rs.Outer } - if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil { + if rs.Type != objabi.SHOSTOBJ && rs.Type != objabi.SDYNIMPORT && rs.Sect == nil { ld.Errorf(s, "missing section for %s", rs.Name) } r.Xsym = rs @@ -594,7 +594,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { // the section load address. // we need to compensate that by removing the instruction's address // from addend. - if ld.Headtype == obj.Hdarwin { + if ld.Headtype == objabi.Hdarwin { r.Xadd -= ld.Symaddr(s) + int64(r.Off) } @@ -610,34 +610,34 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { } switch r.Type { - case obj.R_CONST: + case objabi.R_CONST: *val = r.Add return 0 - case obj.R_GOTOFF: + case objabi.R_GOTOFF: *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".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 obj.R_PLT0: // add ip, pc, #0xXX00000 + case objabi.R_PLT0: // add ip, pc, #0xXX00000 if ld.Symaddr(ctxt.Syms.Lookup(".got.plt", 0)) < ld.Symaddr(ctxt.Syms.Lookup(".plt", 0)) { ld.Errorf(s, ".got.plt should be placed after .plt section.") } *val = 0xe28fc600 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add)) >> 20)) return 0 - case obj.R_PLT1: // add ip, ip, #0xYY000 + case objabi.R_PLT1: // add ip, ip, #0xYY000 *val = 0xe28cca00 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+4)) >> 12)) return 0 - case obj.R_PLT2: // ldr pc, [ip, #0xZZZ]! + case objabi.R_PLT2: // ldr pc, [ip, #0xZZZ]! *val = 0xe5bcf000 + (0xfff & int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+8))) return 0 - case obj.R_CALLARM: // bl XXXXXX or b YYYYYY + case objabi.R_CALLARM: // bl XXXXXX or b YYYYYY // r.Add is the instruction // low 24-bit encodes the target address t := (ld.Symaddr(r.Sym) + int64(signext24(r.Add&0xffffff)*4) - (s.Value + int64(r.Off))) / 4 @@ -657,7 +657,7 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 { return t } -func addpltreloc(ctxt *ld.Link, plt *ld.Symbol, got *ld.Symbol, sym *ld.Symbol, typ obj.RelocType) *ld.Reloc { +func addpltreloc(ctxt *ld.Link, plt *ld.Symbol, got *ld.Symbol, sym *ld.Symbol, typ objabi.RelocType) *ld.Reloc { r := ld.Addrel(plt) r.Sym = got r.Off = int32(plt.Size) @@ -698,9 +698,9 @@ func addpltsym(ctxt *ld.Link, s *ld.Symbol) { // .plt entry, this depends on the .got entry s.Plt = int32(plt.Size) - addpltreloc(ctxt, plt, got, s, obj.R_PLT0) // add lr, pc, #0xXX00000 - addpltreloc(ctxt, plt, got, s, obj.R_PLT1) // add lr, lr, #0xYY000 - addpltreloc(ctxt, plt, got, s, obj.R_PLT2) // ldr pc, [lr, #0xZZZ]! + addpltreloc(ctxt, plt, got, s, objabi.R_PLT0) // add lr, pc, #0xXX00000 + addpltreloc(ctxt, plt, got, s, objabi.R_PLT1) // add lr, lr, #0xYY000 + addpltreloc(ctxt, plt, got, s, objabi.R_PLT2) // ldr pc, [lr, #0xZZZ]! // rel ld.Addaddrplus(ctxt, rel, got, int64(s.Got)) @@ -748,7 +748,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) { func asmb(ctxt *ld.Link) { if ctxt.Debugvlog != 0 { - ctxt.Logf("%5.2f asmb\n", obj.Cputime()) + ctxt.Logf("%5.2f asmb\n", ld.Cputime()) } if ld.Iself { @@ -765,21 +765,21 @@ func asmb(ctxt *ld.Link) { if ld.Segrodata.Filelen > 0 { if ctxt.Debugvlog != 0 { - ctxt.Logf("%5.2f rodatblk\n", obj.Cputime()) + ctxt.Logf("%5.2f rodatblk\n", ld.Cputime()) } ld.Cseek(int64(ld.Segrodata.Fileoff)) ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen)) } if ld.Segrelrodata.Filelen > 0 { if ctxt.Debugvlog != 0 { - ctxt.Logf("%5.2f relrodatblk\n", obj.Cputime()) + ctxt.Logf("%5.2f relrodatblk\n", ld.Cputime()) } ld.Cseek(int64(ld.Segrelrodata.Fileoff)) ld.Datblk(ctxt, int64(ld.Segrelrodata.Vaddr), int64(ld.Segrelrodata.Filelen)) } if ctxt.Debugvlog != 0 { - ctxt.Logf("%5.2f datblk\n", obj.Cputime()) + ctxt.Logf("%5.2f datblk\n", ld.Cputime()) } ld.Cseek(int64(ld.Segdata.Fileoff)) @@ -789,7 +789,7 @@ func asmb(ctxt *ld.Link) { ld.Dwarfblk(ctxt, int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen)) machlink := uint32(0) - if ld.Headtype == obj.Hdarwin { + if ld.Headtype == objabi.Hdarwin { machlink = uint32(ld.Domacholink(ctxt)) } @@ -801,7 +801,7 @@ func asmb(ctxt *ld.Link) { if !*ld.FlagS { // TODO: rationalize if ctxt.Debugvlog != 0 { - ctxt.Logf("%5.2f sym\n", obj.Cputime()) + ctxt.Logf("%5.2f sym\n", ld.Cputime()) } switch ld.Headtype { default: @@ -810,10 +810,10 @@ func asmb(ctxt *ld.Link) { symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound))) } - case obj.Hplan9: + case objabi.Hplan9: symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen) - case obj.Hdarwin: + case objabi.Hdarwin: symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(*ld.FlagRound))) + uint64(machlink)) } @@ -822,7 +822,7 @@ func asmb(ctxt *ld.Link) { default: if ld.Iself { if ctxt.Debugvlog != 0 { - ctxt.Logf("%5.2f elfsym\n", obj.Cputime()) + ctxt.Logf("%5.2f elfsym\n", ld.Cputime()) } ld.Asmelfsym(ctxt) ld.Cflush() @@ -833,7 +833,7 @@ func asmb(ctxt *ld.Link) { } } - case obj.Hplan9: + case objabi.Hplan9: ld.Asmplan9sym(ctxt) ld.Cflush() @@ -847,7 +847,7 @@ func asmb(ctxt *ld.Link) { ld.Cflush() } - case obj.Hdarwin: + case objabi.Hdarwin: if ld.Linkmode == ld.LinkExternal { ld.Machoemitreloc(ctxt) } @@ -855,12 +855,12 @@ func asmb(ctxt *ld.Link) { } if ctxt.Debugvlog != 0 { - ctxt.Logf("%5.2f header\n", obj.Cputime()) + ctxt.Logf("%5.2f header\n", ld.Cputime()) } ld.Cseek(0) switch ld.Headtype { default: - case obj.Hplan9: /* plan 9 */ + case objabi.Hplan9: /* plan 9 */ ld.Lputb(0x647) /* magic */ ld.Lputb(uint32(ld.Segtext.Filelen)) /* sizes */ ld.Lputb(uint32(ld.Segdata.Filelen)) @@ -870,14 +870,14 @@ func asmb(ctxt *ld.Link) { ld.Lputb(0) ld.Lputb(uint32(ld.Lcsize)) - case obj.Hlinux, - obj.Hfreebsd, - obj.Hnetbsd, - obj.Hopenbsd, - obj.Hnacl: + case objabi.Hlinux, + objabi.Hfreebsd, + objabi.Hnetbsd, + objabi.Hopenbsd, + objabi.Hnacl: ld.Asmbelf(ctxt, int64(symo)) - case obj.Hdarwin: + case objabi.Hdarwin: ld.Asmbmacho(ctxt) } |
