2015-03-08 04:32:55 -04:00
|
|
|
// Inferno utils/5l/asm.c
|
|
|
|
|
// http://code.google.com/p/inferno-os/source/browse/utils/5l/asm.c
|
|
|
|
|
//
|
|
|
|
|
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
|
|
|
|
|
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
|
|
|
|
|
// Portions Copyright © 1997-1999 Vita Nuova Limited
|
|
|
|
|
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
|
|
|
|
|
// Portions Copyright © 2004,2006 Bruce Ellis
|
|
|
|
|
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
|
|
|
|
|
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
|
|
|
|
|
// Portions Copyright © 2009 The Go Authors. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
2015-05-21 13:28:10 -04:00
|
|
|
package arm64
|
2015-03-08 04:32:55 -04:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cmd/internal/obj"
|
2015-05-21 13:28:10 -04:00
|
|
|
"cmd/link/internal/ld"
|
2015-04-03 04:37:18 -04:00
|
|
|
"encoding/binary"
|
2015-03-08 04:32:55 -04:00
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
)
|
|
|
|
|
|
2015-06-24 22:31:24 +12:00
|
|
|
func gentext() {
|
|
|
|
|
if !ld.DynlinkingGo() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
addmoduledata := ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0)
|
|
|
|
|
if addmoduledata.Type == obj.STEXT {
|
|
|
|
|
// we're linking a module containing the runtime -> no need for
|
|
|
|
|
// an init function
|
|
|
|
|
return
|
|
|
|
|
}
|
2016-03-02 07:59:49 -05:00
|
|
|
addmoduledata.Attr |= ld.AttrReachable
|
2015-06-24 22:31:24 +12:00
|
|
|
initfunc := ld.Linklookup(ld.Ctxt, "go.link.addmoduledata", 0)
|
|
|
|
|
initfunc.Type = obj.STEXT
|
2016-03-02 07:59:49 -05:00
|
|
|
initfunc.Attr |= ld.AttrLocal
|
|
|
|
|
initfunc.Attr |= ld.AttrReachable
|
2015-06-24 22:31:24 +12:00
|
|
|
o := func(op uint32) {
|
|
|
|
|
ld.Adduint32(ld.Ctxt, initfunc, op)
|
|
|
|
|
}
|
|
|
|
|
// 0000000000000000 <local.dso_init>:
|
|
|
|
|
// 0: 90000000 adrp x0, 0 <runtime.firstmoduledata>
|
|
|
|
|
// 0: R_AARCH64_ADR_PREL_PG_HI21 local.moduledata
|
|
|
|
|
// 4: 91000000 add x0, x0, #0x0
|
|
|
|
|
// 4: R_AARCH64_ADD_ABS_LO12_NC local.moduledata
|
|
|
|
|
o(0x90000000)
|
|
|
|
|
o(0x91000000)
|
|
|
|
|
rel := ld.Addrel(initfunc)
|
|
|
|
|
rel.Off = 0
|
|
|
|
|
rel.Siz = 8
|
|
|
|
|
rel.Sym = ld.Ctxt.Moduledata
|
|
|
|
|
rel.Type = obj.R_ADDRARM64
|
|
|
|
|
|
|
|
|
|
// 8: 14000000 bl 0 <runtime.addmoduledata>
|
|
|
|
|
// 8: R_AARCH64_CALL26 runtime.addmoduledata
|
|
|
|
|
o(0x14000000)
|
|
|
|
|
rel = ld.Addrel(initfunc)
|
|
|
|
|
rel.Off = 8
|
|
|
|
|
rel.Siz = 4
|
|
|
|
|
rel.Sym = ld.Linklookup(ld.Ctxt, "runtime.addmoduledata", 0)
|
|
|
|
|
rel.Type = obj.R_CALLARM64 // Really should be R_AARCH64_JUMP26 but doesn't seem to make any difference
|
|
|
|
|
|
2016-04-19 14:02:21 -04:00
|
|
|
ld.Ctxt.Textp = append(ld.Ctxt.Textp, initfunc)
|
2015-06-24 22:31:24 +12:00
|
|
|
initarray_entry := ld.Linklookup(ld.Ctxt, "go.link.addmoduledatainit", 0)
|
2016-03-02 07:59:49 -05:00
|
|
|
initarray_entry.Attr |= ld.AttrReachable
|
|
|
|
|
initarray_entry.Attr |= ld.AttrLocal
|
2015-06-24 22:31:24 +12:00
|
|
|
initarray_entry.Type = obj.SINITARR
|
|
|
|
|
ld.Addaddr(ld.Ctxt, initarray_entry, initfunc)
|
|
|
|
|
}
|
2015-03-08 14:14:53 +01:00
|
|
|
|
2015-03-08 04:32:55 -04:00
|
|
|
func adddynrel(s *ld.LSym, r *ld.Reloc) {
|
2015-03-08 14:14:53 +01:00
|
|
|
log.Fatalf("adddynrel not implemented")
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func elfreloc1(r *ld.Reloc, sectoff int64) int {
|
2015-04-03 04:37:11 -04:00
|
|
|
ld.Thearch.Vput(uint64(sectoff))
|
|
|
|
|
|
2015-10-29 12:17:43 +13:00
|
|
|
elfsym := r.Xsym.ElfsymForReloc()
|
2015-04-03 04:37:11 -04:00
|
|
|
switch r.Type {
|
|
|
|
|
default:
|
|
|
|
|
return -1
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.R_ADDR:
|
2015-04-03 04:37:11 -04:00
|
|
|
switch r.Siz {
|
|
|
|
|
case 4:
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_ABS32 | uint64(elfsym)<<32)
|
|
|
|
|
case 8:
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_ABS64 | uint64(elfsym)<<32)
|
|
|
|
|
default:
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.R_ADDRARM64:
|
2015-04-03 04:37:18 -04:00
|
|
|
// two relocations: R_AARCH64_ADR_PREL_PG_HI21 and R_AARCH64_ADD_ABS_LO12_NC
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_ADR_PREL_PG_HI21 | uint64(elfsym)<<32)
|
|
|
|
|
ld.Thearch.Vput(uint64(r.Xadd))
|
|
|
|
|
ld.Thearch.Vput(uint64(sectoff + 4))
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_ADD_ABS_LO12_NC | uint64(elfsym)<<32)
|
|
|
|
|
|
2015-08-11 14:10:03 +12:00
|
|
|
case obj.R_ARM64_TLS_LE:
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_TLSLE_MOVW_TPREL_G0 | uint64(elfsym)<<32)
|
|
|
|
|
|
2015-10-28 15:27:51 +13:00
|
|
|
case obj.R_ARM64_TLS_IE:
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 | uint64(elfsym)<<32)
|
|
|
|
|
ld.Thearch.Vput(uint64(r.Xadd))
|
|
|
|
|
ld.Thearch.Vput(uint64(sectoff + 4))
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC | uint64(elfsym)<<32)
|
|
|
|
|
|
2015-08-27 21:09:46 +12:00
|
|
|
case obj.R_ARM64_GOTPCREL:
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_ADR_GOT_PAGE | uint64(elfsym)<<32)
|
|
|
|
|
ld.Thearch.Vput(uint64(r.Xadd))
|
|
|
|
|
ld.Thearch.Vput(uint64(sectoff + 4))
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_LD64_GOT_LO12_NC | uint64(elfsym)<<32)
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.R_CALLARM64:
|
2015-04-03 04:37:11 -04:00
|
|
|
if r.Siz != 4 {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
ld.Thearch.Vput(ld.R_AARCH64_CALL26 | uint64(elfsym)<<32)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
ld.Thearch.Vput(uint64(r.Xadd))
|
|
|
|
|
|
|
|
|
|
return 0
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func elfsetupplt() {
|
2015-03-08 14:14:53 +01:00
|
|
|
// TODO(aram)
|
|
|
|
|
return
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func machoreloc1(r *ld.Reloc, sectoff int64) int {
|
2015-04-10 21:28:09 -04:00
|
|
|
var v uint32
|
|
|
|
|
|
|
|
|
|
rs := r.Xsym
|
|
|
|
|
|
|
|
|
|
// ld64 has a bug handling MACHO_ARM64_RELOC_UNSIGNED with !extern relocation.
|
2016-02-24 11:55:20 +01:00
|
|
|
// see cmd/internal/ld/data.go for details. The workaround is that don't use !extern
|
2015-04-10 21:28:09 -04:00
|
|
|
// UNSIGNED relocation at all.
|
2015-04-19 19:33:58 -07:00
|
|
|
if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_CALLARM64 || r.Type == obj.R_ADDRARM64 || r.Type == obj.R_ADDR {
|
2015-04-10 21:28:09 -04:00
|
|
|
if rs.Dynid < 0 {
|
|
|
|
|
ld.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v = uint32(rs.Dynid)
|
|
|
|
|
v |= 1 << 27 // external relocation
|
|
|
|
|
} else {
|
2015-05-27 12:04:25 +12:00
|
|
|
v = uint32(rs.Sect.Extnum)
|
2015-04-10 21:28:09 -04:00
|
|
|
if v == 0 {
|
2015-05-27 12:04:25 +12:00
|
|
|
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
|
2015-04-10 21:28:09 -04:00
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch r.Type {
|
|
|
|
|
default:
|
|
|
|
|
return -1
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.R_ADDR:
|
2015-04-10 21:28:09 -04:00
|
|
|
v |= ld.MACHO_ARM64_RELOC_UNSIGNED << 28
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.R_CALLARM64:
|
2015-04-10 21:28:09 -04:00
|
|
|
if r.Xadd != 0 {
|
|
|
|
|
ld.Diag("ld64 doesn't allow BR26 reloc with non-zero addend: %s+%d", rs.Name, r.Xadd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v |= 1 << 24 // pc-relative bit
|
|
|
|
|
v |= ld.MACHO_ARM64_RELOC_BRANCH26 << 28
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.R_ADDRARM64:
|
2015-04-10 21:28:09 -04:00
|
|
|
r.Siz = 4
|
|
|
|
|
// Two relocation entries: MACHO_ARM64_RELOC_PAGEOFF12 MACHO_ARM64_RELOC_PAGE21
|
|
|
|
|
// if r.Xadd is non-zero, add two MACHO_ARM64_RELOC_ADDEND.
|
|
|
|
|
if r.Xadd != 0 {
|
|
|
|
|
ld.Thearch.Lput(uint32(sectoff + 4))
|
|
|
|
|
ld.Thearch.Lput((ld.MACHO_ARM64_RELOC_ADDEND << 28) | (2 << 25) | uint32(r.Xadd&0xffffff))
|
|
|
|
|
}
|
|
|
|
|
ld.Thearch.Lput(uint32(sectoff + 4))
|
|
|
|
|
ld.Thearch.Lput(v | (ld.MACHO_ARM64_RELOC_PAGEOFF12 << 28) | (2 << 25))
|
|
|
|
|
if r.Xadd != 0 {
|
|
|
|
|
ld.Thearch.Lput(uint32(sectoff))
|
|
|
|
|
ld.Thearch.Lput((ld.MACHO_ARM64_RELOC_ADDEND << 28) | (2 << 25) | uint32(r.Xadd&0xffffff))
|
|
|
|
|
}
|
|
|
|
|
v |= 1 << 24 // pc-relative bit
|
|
|
|
|
v |= ld.MACHO_ARM64_RELOC_PAGE21 << 28
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch r.Siz {
|
|
|
|
|
default:
|
|
|
|
|
return -1
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
v |= 0 << 25
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
v |= 1 << 25
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
v |= 2 << 25
|
|
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
|
v |= 3 << 25
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ld.Thearch.Lput(uint32(sectoff))
|
|
|
|
|
ld.Thearch.Lput(v)
|
|
|
|
|
return 0
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
|
|
|
|
|
if ld.Linkmode == ld.LinkExternal {
|
2015-04-03 04:37:11 -04:00
|
|
|
switch r.Type {
|
|
|
|
|
default:
|
|
|
|
|
return -1
|
|
|
|
|
|
2015-11-03 10:23:56 +13:00
|
|
|
case obj.R_ARM64_GOTPCREL:
|
|
|
|
|
var o1, o2 uint32
|
|
|
|
|
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
|
|
|
|
|
o1 = uint32(*val >> 32)
|
|
|
|
|
o2 = uint32(*val)
|
|
|
|
|
} else {
|
|
|
|
|
o1 = uint32(*val)
|
|
|
|
|
o2 = uint32(*val >> 32)
|
|
|
|
|
}
|
|
|
|
|
// Any relocation against a function symbol is redirected to
|
|
|
|
|
// be against a local symbol instead (see putelfsym in
|
|
|
|
|
// symtab.go) but unfortunately the system linker was buggy
|
|
|
|
|
// when confronted with a R_AARCH64_ADR_GOT_PAGE relocation
|
|
|
|
|
// against a local symbol until May 2015
|
|
|
|
|
// (https://sourceware.org/bugzilla/show_bug.cgi?id=18270). So
|
|
|
|
|
// we convert the adrp; ld64 + R_ARM64_GOTPCREL into adrp;
|
|
|
|
|
// add + R_ADDRARM64.
|
2016-03-02 07:59:49 -05:00
|
|
|
if !(r.Sym.Version != 0 || (r.Sym.Type&obj.SHIDDEN != 0) || r.Sym.Attr.Local()) && r.Sym.Type == obj.STEXT && ld.DynlinkingGo() {
|
2015-11-03 10:23:56 +13:00
|
|
|
if o2&0xffc00000 != 0xf9400000 {
|
|
|
|
|
ld.Ctxt.Diag("R_ARM64_GOTPCREL against unexpected instruction %x", o2)
|
|
|
|
|
}
|
|
|
|
|
o2 = 0x91000000 | (o2 & 0x000003ff)
|
|
|
|
|
r.Type = obj.R_ADDRARM64
|
|
|
|
|
}
|
|
|
|
|
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
|
|
|
|
|
*val = int64(o1)<<32 | int64(o2)
|
|
|
|
|
} else {
|
|
|
|
|
*val = int64(o2)<<32 | int64(o1)
|
|
|
|
|
}
|
|
|
|
|
fallthrough
|
|
|
|
|
|
|
|
|
|
case obj.R_ADDRARM64:
|
2015-04-03 04:37:18 -04:00
|
|
|
r.Done = 0
|
|
|
|
|
|
|
|
|
|
// set up addend for eventual relocation via outer symbol.
|
|
|
|
|
rs := r.Sym
|
|
|
|
|
r.Xadd = r.Add
|
|
|
|
|
for rs.Outer != nil {
|
|
|
|
|
r.Xadd += ld.Symaddr(rs) - ld.Symaddr(rs.Outer)
|
|
|
|
|
rs = rs.Outer
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-27 21:09:46 +12:00
|
|
|
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
|
2015-04-03 04:37:18 -04:00
|
|
|
ld.Diag("missing section for %s", rs.Name)
|
|
|
|
|
}
|
|
|
|
|
r.Xsym = rs
|
|
|
|
|
|
2015-04-10 21:28:09 -04:00
|
|
|
// Note: ld64 currently has a bug that any non-zero addend for BR26 relocation
|
|
|
|
|
// will make the linking fail because it thinks the code is not PIC even though
|
|
|
|
|
// the BR26 relocation should be fully resolved at link time.
|
|
|
|
|
// That is the reason why the next if block is disabled. When the bug in ld64
|
|
|
|
|
// is fixed, we can enable this block and also enable duff's device in cmd/7g.
|
2015-04-19 19:33:58 -07:00
|
|
|
if false && ld.HEADTYPE == obj.Hdarwin {
|
2015-08-03 14:08:17 +12:00
|
|
|
var o0, o1 uint32
|
|
|
|
|
|
|
|
|
|
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
|
|
|
|
|
o0 = uint32(*val >> 32)
|
|
|
|
|
o1 = uint32(*val)
|
|
|
|
|
} else {
|
|
|
|
|
o0 = uint32(*val)
|
|
|
|
|
o1 = uint32(*val >> 32)
|
|
|
|
|
}
|
2015-04-10 21:28:09 -04:00
|
|
|
// Mach-O wants the addend to be encoded in the instruction
|
|
|
|
|
// Note that although Mach-O supports ARM64_RELOC_ADDEND, it
|
|
|
|
|
// can only encode 24-bit of signed addend, but the instructions
|
|
|
|
|
// supports 33-bit of signed addend, so we always encode the
|
|
|
|
|
// addend in place.
|
|
|
|
|
o0 |= (uint32((r.Xadd>>12)&3) << 29) | (uint32((r.Xadd>>12>>2)&0x7ffff) << 5)
|
|
|
|
|
o1 |= uint32(r.Xadd&0xfff) << 10
|
|
|
|
|
r.Xadd = 0
|
|
|
|
|
|
2015-08-03 14:08:17 +12:00
|
|
|
// when laid out, the instruction order must always be o1, o2.
|
|
|
|
|
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
|
|
|
|
|
*val = int64(o0)<<32 | int64(o1)
|
|
|
|
|
} else {
|
|
|
|
|
*val = int64(o1)<<32 | int64(o0)
|
|
|
|
|
}
|
2015-04-10 21:28:09 -04:00
|
|
|
}
|
|
|
|
|
|
2015-04-03 04:37:18 -04:00
|
|
|
return 0
|
|
|
|
|
|
2015-08-11 14:10:03 +12:00
|
|
|
case obj.R_CALLARM64,
|
2015-10-28 15:27:51 +13:00
|
|
|
obj.R_ARM64_TLS_LE,
|
|
|
|
|
obj.R_ARM64_TLS_IE:
|
2015-04-03 04:37:11 -04:00
|
|
|
r.Done = 0
|
|
|
|
|
r.Xsym = r.Sym
|
2015-08-03 14:08:17 +12:00
|
|
|
r.Xadd = r.Add
|
2015-04-03 04:37:11 -04:00
|
|
|
return 0
|
|
|
|
|
}
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch r.Type {
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.R_CONST:
|
2015-03-08 04:32:55 -04:00
|
|
|
*val = r.Add
|
|
|
|
|
return 0
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.R_GOTOFF:
|
2015-03-08 04:32:55 -04:00
|
|
|
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0))
|
|
|
|
|
return 0
|
|
|
|
|
|
2015-11-13 08:32:33 +00:00
|
|
|
case obj.R_ADDRARM64:
|
|
|
|
|
t := ld.Symaddr(r.Sym) + r.Add - ((s.Value + int64(r.Off)) &^ 0xfff)
|
|
|
|
|
if t >= 1<<32 || t < -1<<32 {
|
|
|
|
|
ld.Diag("program too large, address relocation distance = %d", t)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var o0, o1 uint32
|
|
|
|
|
|
|
|
|
|
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
|
|
|
|
|
o0 = uint32(*val >> 32)
|
|
|
|
|
o1 = uint32(*val)
|
|
|
|
|
} else {
|
|
|
|
|
o0 = uint32(*val)
|
|
|
|
|
o1 = uint32(*val >> 32)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
o0 |= (uint32((t>>12)&3) << 29) | (uint32((t>>12>>2)&0x7ffff) << 5)
|
|
|
|
|
o1 |= uint32(t&0xfff) << 10
|
|
|
|
|
|
|
|
|
|
// when laid out, the instruction order must always be o1, o2.
|
|
|
|
|
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
|
|
|
|
|
*val = int64(o0)<<32 | int64(o1)
|
|
|
|
|
} else {
|
|
|
|
|
*val = int64(o1)<<32 | int64(o0)
|
|
|
|
|
}
|
|
|
|
|
return 0
|
2015-04-03 04:37:18 -04:00
|
|
|
|
2015-08-11 14:10:03 +12:00
|
|
|
case obj.R_ARM64_TLS_LE:
|
|
|
|
|
r.Done = 0
|
|
|
|
|
if ld.HEADTYPE != obj.Hlinux {
|
|
|
|
|
ld.Diag("TLS reloc on unsupported OS %s", ld.Headstr(int(ld.HEADTYPE)))
|
|
|
|
|
}
|
|
|
|
|
// The TCB is two pointers. This is not documented anywhere, but is
|
|
|
|
|
// de facto part of the ABI.
|
2016-04-06 12:01:40 -07:00
|
|
|
v := r.Sym.Value + int64(2*ld.SysArch.PtrSize)
|
2015-08-11 14:10:03 +12:00
|
|
|
if v < 0 || v >= 32678 {
|
|
|
|
|
ld.Diag("TLS offset out of range %d", v)
|
|
|
|
|
}
|
|
|
|
|
*val |= v << 5
|
|
|
|
|
return 0
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.R_CALLARM64:
|
2015-08-03 14:08:17 +12:00
|
|
|
t := (ld.Symaddr(r.Sym) + r.Add) - (s.Value + int64(r.Off))
|
|
|
|
|
if t >= 1<<27 || t < -1<<27 {
|
|
|
|
|
ld.Diag("program too large, call relocation distance = %d", t)
|
|
|
|
|
}
|
|
|
|
|
*val |= (t >> 2) & 0x03ffffff
|
2015-03-08 04:32:55 -04:00
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func archrelocvariant(r *ld.Reloc, s *ld.LSym, t int64) int64 {
|
2015-03-08 14:14:53 +01:00
|
|
|
log.Fatalf("unexpected relocation variant")
|
|
|
|
|
return -1
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func asmb() {
|
|
|
|
|
if ld.Debug['v'] != 0 {
|
2016-04-09 12:54:45 +10:00
|
|
|
fmt.Fprintf(ld.Bso, "%5.2f asmb\n", obj.Cputime())
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
2015-05-02 12:44:49 +10:00
|
|
|
ld.Bso.Flush()
|
2015-03-08 04:32:55 -04:00
|
|
|
|
|
|
|
|
if ld.Iself {
|
|
|
|
|
ld.Asmbelfsetup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sect := ld.Segtext.Sect
|
|
|
|
|
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
|
|
|
|
ld.Codeblk(int64(sect.Vaddr), int64(sect.Length))
|
|
|
|
|
for sect = sect.Next; sect != nil; sect = sect.Next {
|
|
|
|
|
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
|
|
|
|
|
ld.Datblk(int64(sect.Vaddr), int64(sect.Length))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ld.Segrodata.Filelen > 0 {
|
|
|
|
|
if ld.Debug['v'] != 0 {
|
2016-04-09 12:54:45 +10:00
|
|
|
fmt.Fprintf(ld.Bso, "%5.2f rodatblk\n", obj.Cputime())
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
2015-05-02 12:44:49 +10:00
|
|
|
ld.Bso.Flush()
|
2015-03-08 04:32:55 -04:00
|
|
|
|
|
|
|
|
ld.Cseek(int64(ld.Segrodata.Fileoff))
|
|
|
|
|
ld.Datblk(int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ld.Debug['v'] != 0 {
|
2016-04-09 12:54:45 +10:00
|
|
|
fmt.Fprintf(ld.Bso, "%5.2f datblk\n", obj.Cputime())
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
2015-05-02 12:44:49 +10:00
|
|
|
ld.Bso.Flush()
|
2015-03-08 04:32:55 -04:00
|
|
|
|
|
|
|
|
ld.Cseek(int64(ld.Segdata.Fileoff))
|
|
|
|
|
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
|
|
|
|
|
|
2016-03-14 09:23:04 -07:00
|
|
|
ld.Cseek(int64(ld.Segdwarf.Fileoff))
|
|
|
|
|
ld.Dwarfblk(int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
|
|
|
|
|
|
2015-04-10 21:28:09 -04:00
|
|
|
machlink := uint32(0)
|
2015-04-19 19:33:58 -07:00
|
|
|
if ld.HEADTYPE == obj.Hdarwin {
|
2015-04-10 21:28:09 -04:00
|
|
|
machlink = uint32(ld.Domacholink())
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 04:32:55 -04:00
|
|
|
/* output symbol table */
|
|
|
|
|
ld.Symsize = 0
|
|
|
|
|
|
|
|
|
|
ld.Lcsize = 0
|
|
|
|
|
symo := uint32(0)
|
|
|
|
|
if ld.Debug['s'] == 0 {
|
|
|
|
|
// TODO: rationalize
|
|
|
|
|
if ld.Debug['v'] != 0 {
|
2016-04-09 12:54:45 +10:00
|
|
|
fmt.Fprintf(ld.Bso, "%5.2f sym\n", obj.Cputime())
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
2015-05-02 12:44:49 +10:00
|
|
|
ld.Bso.Flush()
|
2015-03-08 04:32:55 -04:00
|
|
|
switch ld.HEADTYPE {
|
|
|
|
|
default:
|
|
|
|
|
if ld.Iself {
|
2016-03-14 09:23:04 -07:00
|
|
|
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
|
2015-03-08 04:32:55 -04:00
|
|
|
symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND)))
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.Hplan9:
|
2015-03-08 04:32:55 -04:00
|
|
|
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
|
2015-04-10 21:28:09 -04:00
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.Hdarwin:
|
2015-04-08 12:55:34 -07:00
|
|
|
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(ld.INITRND))) + uint64(machlink))
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ld.Cseek(int64(symo))
|
|
|
|
|
switch ld.HEADTYPE {
|
|
|
|
|
default:
|
|
|
|
|
if ld.Iself {
|
|
|
|
|
if ld.Debug['v'] != 0 {
|
2016-04-09 12:54:45 +10:00
|
|
|
fmt.Fprintf(ld.Bso, "%5.2f elfsym\n", obj.Cputime())
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
ld.Asmelfsym()
|
|
|
|
|
ld.Cflush()
|
|
|
|
|
ld.Cwrite(ld.Elfstrdat)
|
|
|
|
|
|
|
|
|
|
if ld.Linkmode == ld.LinkExternal {
|
|
|
|
|
ld.Elfemitreloc()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.Hplan9:
|
2015-03-08 04:32:55 -04:00
|
|
|
ld.Asmplan9sym()
|
|
|
|
|
ld.Cflush()
|
|
|
|
|
|
|
|
|
|
sym := ld.Linklookup(ld.Ctxt, "pclntab", 0)
|
|
|
|
|
if sym != nil {
|
|
|
|
|
ld.Lcsize = int32(len(sym.P))
|
|
|
|
|
for i := 0; int32(i) < ld.Lcsize; i++ {
|
2016-04-14 19:04:45 -07:00
|
|
|
ld.Cput(sym.P[i])
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ld.Cflush()
|
|
|
|
|
}
|
2015-04-10 21:28:09 -04:00
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.Hdarwin:
|
2015-04-10 21:28:09 -04:00
|
|
|
if ld.Linkmode == ld.LinkExternal {
|
|
|
|
|
ld.Machoemitreloc()
|
|
|
|
|
}
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ld.Ctxt.Cursym = nil
|
|
|
|
|
if ld.Debug['v'] != 0 {
|
2016-04-09 12:54:45 +10:00
|
|
|
fmt.Fprintf(ld.Bso, "%5.2f header\n", obj.Cputime())
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
2015-05-02 12:44:49 +10:00
|
|
|
ld.Bso.Flush()
|
2015-03-08 04:32:55 -04:00
|
|
|
ld.Cseek(0)
|
|
|
|
|
switch ld.HEADTYPE {
|
|
|
|
|
default:
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.Hplan9: /* plan 9 */
|
2015-03-08 04:32:55 -04:00
|
|
|
ld.Thearch.Lput(0x647) /* magic */
|
|
|
|
|
ld.Thearch.Lput(uint32(ld.Segtext.Filelen)) /* sizes */
|
|
|
|
|
ld.Thearch.Lput(uint32(ld.Segdata.Filelen))
|
|
|
|
|
ld.Thearch.Lput(uint32(ld.Segdata.Length - ld.Segdata.Filelen))
|
|
|
|
|
ld.Thearch.Lput(uint32(ld.Symsize)) /* nsyms */
|
|
|
|
|
ld.Thearch.Lput(uint32(ld.Entryvalue())) /* va of entry */
|
|
|
|
|
ld.Thearch.Lput(0)
|
|
|
|
|
ld.Thearch.Lput(uint32(ld.Lcsize))
|
|
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.Hlinux,
|
|
|
|
|
obj.Hfreebsd,
|
|
|
|
|
obj.Hnetbsd,
|
|
|
|
|
obj.Hopenbsd,
|
|
|
|
|
obj.Hnacl:
|
2015-03-08 04:32:55 -04:00
|
|
|
ld.Asmbelf(int64(symo))
|
2015-04-10 21:28:09 -04:00
|
|
|
|
2015-04-19 19:33:58 -07:00
|
|
|
case obj.Hdarwin:
|
2015-04-10 21:28:09 -04:00
|
|
|
ld.Asmbmacho()
|
2015-03-08 04:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ld.Cflush()
|
|
|
|
|
if ld.Debug['c'] != 0 {
|
|
|
|
|
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
|
|
|
|
|
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
|
|
|
|
|
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)
|
|
|
|
|
fmt.Printf("symsize=%d\n", ld.Symsize)
|
|
|
|
|
fmt.Printf("lcsize=%d\n", ld.Lcsize)
|
|
|
|
|
fmt.Printf("total=%d\n", ld.Segtext.Filelen+ld.Segdata.Length+uint64(ld.Symsize)+uint64(ld.Lcsize))
|
|
|
|
|
}
|
|
|
|
|
}
|