// Defined SymKind values.
//
// TODO(rsc): Give idiomatic Go names.
-// TODO(rsc): Reduce the number of symbol types in the object files.
//go:generate stringer -type=SymKind
const (
+ // An otherwise invalid zero value for the type
Sxxx SymKind = iota
+ // Executable instructions
STEXT
- SELFRXSECT
-
- // Read-only sections.
- STYPE
- SSTRING
- SGOSTRING
- SGOFUNC
- SGCBITS
+ // Read only static data
SRODATA
- SFUNCTAB
-
- SELFROSECT
- SMACHOPLT
-
- // Read-only sections with relocations.
- //
- // Types STYPE-SFUNCTAB above are written to the .rodata section by default.
- // When linking a shared object, some conceptually "read only" types need to
- // be written to by relocations and putting them in a section called
- // ".rodata" interacts poorly with the system linkers. The GNU linkers
- // support this situation by arranging for sections of the name
- // ".data.rel.ro.XXX" to be mprotected read only by the dynamic linker after
- // relocations have applied, so when the Go linker is creating a shared
- // object it checks all objects of the above types and bumps any object that
- // has a relocation to it to the corresponding type below, which are then
- // written to sections with appropriate magic names.
- STYPERELRO
- SSTRINGRELRO
- SGOSTRINGRELRO
- SGOFUNCRELRO
- SGCBITSRELRO
- SRODATARELRO
- SFUNCTABRELRO
-
- // Part of .data.rel.ro if it exists, otherwise part of .rodata.
- STYPELINK
- SITABLINK
- SSYMTAB
- SPCLNTAB
-
- // Writable sections.
- SELFSECT
- SMACHO
- SMACHOGOT
- SWINDOWS
- SELFGOT
+ // Static data that does not contain any pointers
SNOPTRDATA
- SINITARR
+ // Static data
SDATA
+ // Statically data that is initially all 0s
SBSS
+ // Statically data that is initially all 0s and does not contain pointers
SNOPTRBSS
+ // Thread-local data that is initally all 0s
STLSBSS
+ // TODO(mwhudson): outside of the linker, these values are
+ // only checked for, not set, so they should be removed.
SXREF
- SMACHOSYMSTR
- SMACHOSYMTAB
- SMACHOINDIRECTPLT
- SMACHOINDIRECTGOT
- SFILE
- SFILEPATH
SCONST
- SDYNIMPORT
- SHOSTOBJ
- SDWARFSECT
+ // Debugging data
SDWARFINFO
- SSUB = SymKind(1 << 8)
- SMASK = SymKind(SSUB - 1)
- SHIDDEN = SymKind(1 << 9)
- SCONTAINER = SymKind(1 << 10) // has a sub-symbol
)
-
-// ReadOnly are the symbol kinds that form read-only sections. In some
-// cases, if they will require relocations, they are transformed into
-// rel-ro sections using RelROMap.
-var ReadOnly = []SymKind{
- STYPE,
- SSTRING,
- SGOSTRING,
- SGOFUNC,
- SGCBITS,
- SRODATA,
- SFUNCTAB,
-}
-
-// RelROMap describes the transformation of read-only symbols to rel-ro
-// symbols.
-var RelROMap = map[SymKind]SymKind{
- STYPE: STYPERELRO,
- SSTRING: SSTRINGRELRO,
- SGOSTRING: SGOSTRINGRELRO,
- SGOFUNC: SGOFUNCRELRO,
- SGCBITS: SGCBITSRELRO,
- SRODATA: SRODATARELRO,
- SFUNCTAB: SFUNCTABRELRO,
-}
import "fmt"
-const _SymKind_name = "SxxxSTEXTSELFRXSECTSTYPESSTRINGSGOSTRINGSGOFUNCSGCBITSSRODATASFUNCTABSELFROSECTSMACHOPLTSTYPERELROSSTRINGRELROSGOSTRINGRELROSGOFUNCRELROSGCBITSRELROSRODATARELROSFUNCTABRELROSTYPELINKSITABLINKSSYMTABSPCLNTABSELFSECTSMACHOSMACHOGOTSWINDOWSSELFGOTSNOPTRDATASINITARRSDATASBSSSNOPTRBSSSTLSBSSSXREFSMACHOSYMSTRSMACHOSYMTABSMACHOINDIRECTPLTSMACHOINDIRECTGOTSFILESFILEPATHSCONSTSDYNIMPORTSHOSTOBJSDWARFSECTSDWARFINFO"
+const _SymKind_name = "SxxxSTEXTSRODATASNOPTRDATASDATASBSSSNOPTRBSSSTLSBSSSXREFSCONSTSDWARFINFO"
-var _SymKind_index = [...]uint16{0, 4, 9, 19, 24, 31, 40, 47, 54, 61, 69, 79, 88, 98, 110, 124, 136, 148, 160, 173, 182, 191, 198, 206, 214, 220, 229, 237, 244, 254, 262, 267, 271, 280, 287, 292, 304, 316, 333, 350, 355, 364, 370, 380, 388, 398, 408}
+var _SymKind_index = [...]uint8{0, 4, 9, 16, 26, 31, 35, 44, 51, 56, 62, 72}
func (i SymKind) String() string {
if i < 0 || i >= SymKind(len(_SymKind_index)-1) {
seen[s.SymID] = true
sym := Sym{Addr: uint64(s.Data.Offset), Name: goobjName(s.SymID), Size: int64(s.Size), Type: s.Type.Name, Code: '?'}
switch s.Kind {
- case objabi.STEXT, objabi.SELFRXSECT:
+ case objabi.STEXT:
sym.Code = 'T'
- case objabi.STYPE, objabi.SSTRING, objabi.SGOSTRING, objabi.SGOFUNC, objabi.SRODATA, objabi.SFUNCTAB, objabi.STYPELINK, objabi.SITABLINK, objabi.SSYMTAB, objabi.SPCLNTAB, objabi.SELFROSECT:
+ case objabi.SRODATA:
sym.Code = 'R'
- case objabi.SMACHOPLT, objabi.SELFSECT, objabi.SMACHO, objabi.SMACHOGOT, objabi.SNOPTRDATA, objabi.SINITARR, objabi.SDATA, objabi.SWINDOWS:
+ case objabi.SDATA:
sym.Code = 'D'
case objabi.SBSS, objabi.SNOPTRBSS, objabi.STLSBSS:
sym.Code = 'B'
- case objabi.SXREF, objabi.SMACHOSYMSTR, objabi.SMACHOSYMTAB, objabi.SMACHOINDIRECTPLT, objabi.SMACHOINDIRECTGOT, objabi.SFILE, objabi.SFILEPATH, objabi.SCONST, objabi.SDYNIMPORT, objabi.SHOSTOBJ:
+ case objabi.SXREF, objabi.SCONST:
sym.Code = 'X' // should not see
}
if s.Version != 0 {
return
}
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0)
- if addmoduledata.Type == objabi.STEXT && ld.Buildmode != ld.BuildmodePlugin {
+ if addmoduledata.Type == ld.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 = objabi.STEXT
+ initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
o := func(op ...uint8) {
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
- initarray_entry.Type = objabi.SINITARR
+ initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc)
}
// Handle relocations found in ELF object files.
case 256 + ld.R_X86_64_PC32:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_X86_64_PC32 relocation for dynamic symbol %s", targ.Name)
}
- if targ.Type == 0 || targ.Type == objabi.SXREF {
+ if targ.Type == 0 || targ.Type == ld.SXREF {
ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
}
r.Type = objabi.R_PCREL
case 256 + ld.R_X86_64_PLT32:
r.Type = objabi.R_PCREL
r.Add += 4
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add += int64(targ.Plt)
return true
case 256 + ld.R_X86_64_GOTPCREL, 256 + ld.R_X86_64_GOTPCRELX, 256 + ld.R_X86_64_REX_GOTPCRELX:
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
// have symbol
if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
// turn MOVQ of GOT entry into LEAQ of symbol itself
return true
case 256 + ld.R_X86_64_64:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_X86_64_64 relocation for dynamic symbol %s", targ.Name)
}
r.Type = objabi.R_ADDR
// TODO: What is the difference between all these?
r.Type = objabi.R_ADDR
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected reloc for dynamic symbol %s", targ.Name)
}
return true
case 512 + ld.MACHO_X86_64_RELOC_BRANCH*2 + 1:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(targ.Plt)
512 + ld.MACHO_X86_64_RELOC_SIGNED_4*2 + 1:
r.Type = objabi.R_PCREL
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected pc-relative reloc for dynamic symbol %s", targ.Name)
}
return true
case 512 + ld.MACHO_X86_64_RELOC_GOT_LOAD*2 + 1:
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
// have symbol
// turn MOVQ of GOT entry into LEAQ of symbol itself
if r.Off < 2 || s.P[r.Off-2] != 0x8b {
// fall through
case 512 + ld.MACHO_X86_64_RELOC_GOT*2 + 1:
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
ld.Errorf(s, "unexpected GOT reloc for non-dynamic symbol %s", targ.Name)
}
addgotsym(ctxt, targ)
switch r.Type {
case objabi.R_CALL,
objabi.R_PCREL:
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
// nothing to do, the relocation will be laid out in reloc
return true
}
}
case objabi.R_ADDR:
- if s.Type == objabi.STEXT && ld.Iself {
+ if s.Type == ld.STEXT && ld.Iself {
if ld.Headtype == objabi.Hsolaris {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
// linking, in which case the relocation will be
// prepared in the 'reloc' phase and passed to the
// external linker in the 'asmb' phase.
- if s.Type != objabi.SDATA && s.Type != objabi.SRODATA {
+ if s.Type != ld.SDATA && s.Type != ld.SRODATA {
break
}
}
ld.Adddynsym(ctxt, targ)
got := ctxt.Syms.Lookup(".got", 0)
- s.Type = got.Type | objabi.SSUB
+ s.Type = got.Type | ld.SSUB
s.Outer = got
s.Sub = got.Sub
got.Sub = s
case objabi.R_CALL:
if r.Siz == 4 {
- if r.Xsym.Type == objabi.SDYNIMPORT {
+ if r.Xsym.Type == ld.SDYNIMPORT {
if ctxt.DynlinkingGo() {
ld.Thearch.Vput(ld.R_X86_64_PLT32 | uint64(elfsym)<<32)
} else {
case objabi.R_PCREL:
if r.Siz == 4 {
- if r.Xsym.Type == objabi.SDYNIMPORT && r.Xsym.ElfType == elf.STT_FUNC {
+ if r.Xsym.Type == ld.SDYNIMPORT && r.Xsym.ElfType == elf.STT_FUNC {
ld.Thearch.Vput(ld.R_X86_64_PLT32 | uint64(elfsym)<<32)
} else {
ld.Thearch.Vput(ld.R_X86_64_PC32 | uint64(elfsym)<<32)
rs := r.Xsym
- if rs.Type == objabi.SHOSTOBJ || r.Type == objabi.R_PCREL || r.Type == objabi.R_GOTPCREL {
+ if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_PCREL || r.Type == objabi.R_GOTPCREL {
if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1
return
}
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0)
- if addmoduledata.Type == objabi.STEXT && ld.Buildmode != ld.BuildmodePlugin {
+ if addmoduledata.Type == ld.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 = objabi.STEXT
+ initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
o := func(op uint32) {
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
- initarray_entry.Type = objabi.SINITARR
+ initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc)
}
case 256 + ld.R_ARM_PLT32:
r.Type = objabi.R_CALLARM
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(braddoff(int32(r.Add), targ.Plt/4))
return false
case 256 + ld.R_ARM_GOT32: // R_ARM_GOT_BREL
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
addgotsyminternal(ctxt, targ)
} else {
addgotsym(ctxt, targ)
return true
case 256 + ld.R_ARM_GOT_PREL: // GOT(nil) + A - nil
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
addgotsyminternal(ctxt, targ)
} else {
addgotsym(ctxt, targ)
case 256 + ld.R_ARM_CALL:
r.Type = objabi.R_CALLARM
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(braddoff(int32(r.Add), targ.Plt/4))
return true
case 256 + ld.R_ARM_ABS32:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_ARM_ABS32 relocation for dynamic symbol %s", targ.Name)
}
r.Type = objabi.R_ADDR
case 256 + ld.R_ARM_PC24,
256 + ld.R_ARM_JUMP24:
r.Type = objabi.R_CALLARM
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(braddoff(int32(r.Add), targ.Plt/4))
}
// Handle references to ELF symbols from our own object files.
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
return true
}
return true
case objabi.R_ADDR:
- if s.Type != objabi.SDATA {
+ if s.Type != ld.SDATA {
break
}
if ld.Iself {
rs := r.Xsym
if r.Type == objabi.R_PCREL {
- if rs.Type == objabi.SHOSTOBJ {
+ if rs.Type == ld.SHOSTOBJ {
ld.Errorf(s, "pc-relative relocation of external symbol is not supported")
return -1
}
return 0
}
- if rs.Type == objabi.SHOSTOBJ || r.Type == objabi.R_CALLARM {
+ if rs.Type == ld.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
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 == objabi.SDYNIMPORT {
+ if tramp.Type == ld.SDYNIMPORT {
// don't reuse trampoline defined in other module
continue
}
rs = rs.Outer
}
- if rs.Type != objabi.SHOSTOBJ && rs.Type != objabi.SDYNIMPORT && rs.Sect == nil {
+ if rs.Type != ld.SHOSTOBJ && rs.Type != ld.SDYNIMPORT && rs.Sect == nil {
ld.Errorf(s, "missing section for %s", rs.Name)
}
r.Xsym = rs
return
}
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0)
- if addmoduledata.Type == objabi.STEXT {
+ if addmoduledata.Type == ld.STEXT {
// 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 = objabi.STEXT
+ initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
o := func(op uint32) {
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
- initarray_entry.Type = objabi.SINITARR
+ initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc)
}
// ld64 has a bug handling MACHO_ARM64_RELOC_UNSIGNED with !extern relocation.
// see cmd/internal/ld/data.go for details. The workaround is that don't use !extern
// UNSIGNED relocation at all.
- if rs.Type == objabi.SHOSTOBJ || r.Type == objabi.R_CALLARM64 || r.Type == objabi.R_ADDRARM64 || r.Type == objabi.R_ADDR {
+ if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_CALLARM64 || r.Type == objabi.R_ADDRARM64 || r.Type == objabi.R_ADDR {
if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1
// (https://sourceware.org/bugzilla/show_bug.cgi?id=18270). So
// we convert the adrp; ld64 + R_ARM64_GOTPCREL into adrp;
// add + R_ADDRARM64.
- if !(r.Sym.Version != 0 || (r.Sym.Type&objabi.SHIDDEN != 0) || r.Sym.Attr.Local()) && r.Sym.Type == objabi.STEXT && ctxt.DynlinkingGo() {
+ if !(r.Sym.Version != 0 || (r.Sym.Type&ld.SHIDDEN != 0) || r.Sym.Attr.Local()) && r.Sym.Type == ld.STEXT && ctxt.DynlinkingGo() {
if o2&0xffc00000 != 0xf9400000 {
ld.Errorf(s, "R_ARM64_GOTPCREL against unexpected instruction %x", o2)
}
rs = rs.Outer
}
- if rs.Type != objabi.SHOSTOBJ && rs.Type != objabi.SDYNIMPORT && rs.Sect == nil {
+ if rs.Type != ld.SHOSTOBJ && rs.Type != ld.SDYNIMPORT && rs.Sect == nil {
ld.Errorf(s, "missing section for %s", rs.Name)
}
r.Xsym = rs
var load []uint64
for _, s := range ctxt.Syms.Allsym {
for _, r := range s.R {
- if r.Sym != nil && r.Sym.Type&objabi.SMASK == objabi.SXREF {
+ if r.Sym != nil && r.Sym.Type&SMASK == SXREF {
if off := armap[r.Sym.Name]; off != 0 && !loaded[off] {
load = append(load, off)
loaded[off] = true
func setuintxx(ctxt *Link, s *Symbol, off int64, v uint64, wid int64) int64 {
if s.Type == 0 {
- s.Type = objabi.SDATA
+ s.Type = SDATA
}
s.Attr |= AttrReachable
if s.Size < off+wid {
func Addbytes(s *Symbol, bytes []byte) int64 {
if s.Type == 0 {
- s.Type = objabi.SDATA
+ s.Type = SDATA
}
s.Attr |= AttrReachable
s.P = append(s.P, bytes...)
func Adduint8(ctxt *Link, s *Symbol, v uint8) int64 {
off := s.Size
if s.Type == 0 {
- s.Type = objabi.SDATA
+ s.Type = SDATA
}
s.Attr |= AttrReachable
s.Size++
func Addaddrplus(ctxt *Link, s *Symbol, t *Symbol, add int64) int64 {
if s.Type == 0 {
- s.Type = objabi.SDATA
+ s.Type = SDATA
}
s.Attr |= AttrReachable
i := s.Size
func Addpcrelplus(ctxt *Link, s *Symbol, t *Symbol, add int64) int64 {
if s.Type == 0 {
- s.Type = objabi.SDATA
+ s.Type = SDATA
}
s.Attr |= AttrReachable
i := s.Size
func setaddrplus(ctxt *Link, s *Symbol, off int64, t *Symbol, add int64) int64 {
if s.Type == 0 {
- s.Type = objabi.SDATA
+ s.Type = SDATA
}
s.Attr |= AttrReachable
if off+int64(ctxt.Arch.PtrSize) > s.Size {
func addsize(ctxt *Link, s *Symbol, t *Symbol) int64 {
if s.Type == 0 {
- s.Type = objabi.SDATA
+ s.Type = SDATA
}
s.Attr |= AttrReachable
i := s.Size
func addaddrplus4(ctxt *Link, s *Symbol, t *Symbol, add int64) int64 {
if s.Type == 0 {
- s.Type = objabi.SDATA
+ s.Type = SDATA
}
s.Attr |= AttrReachable
i := s.Size
if !r.Type.IsDirectJump() {
continue
}
- if Symaddr(r.Sym) == 0 && r.Sym.Type != objabi.SDYNIMPORT {
+ if Symaddr(r.Sym) == 0 && r.Sym.Type != SDYNIMPORT {
if r.Sym.File != s.File {
if !isRuntimeDepPkg(s.File) || !isRuntimeDepPkg(r.Sym.File) {
Errorf(s, "unresolved inter-package jump to %s(%s)", r.Sym, r.Sym.File)
continue
}
- if r.Sym != nil && (r.Sym.Type&(objabi.SMASK|objabi.SHIDDEN) == 0 || r.Sym.Type&objabi.SMASK == objabi.SXREF) {
+ if r.Sym != nil && (r.Sym.Type&(SMASK|SHIDDEN) == 0 || r.Sym.Type&SMASK == SXREF) {
// When putting the runtime but not main into a shared library
// these symbols are undefined and that's OK.
if Buildmode == BuildmodeShared {
if r.Sym.Name == "main.main" || r.Sym.Name == "main.init" {
- r.Sym.Type = objabi.SDYNIMPORT
+ r.Sym.Type = SDYNIMPORT
} else if strings.HasPrefix(r.Sym.Name, "go.info.") {
// Skip go.info symbols. They are only needed to communicate
// DWARF info between the compiler and linker.
// We need to be able to reference dynimport symbols when linking against
// shared libraries, and Solaris needs it always
- if Headtype != objabi.Hsolaris && r.Sym != nil && r.Sym.Type == objabi.SDYNIMPORT && !ctxt.DynlinkingGo() {
+ if Headtype != objabi.Hsolaris && r.Sym != nil && r.Sym.Type == SDYNIMPORT && !ctxt.DynlinkingGo() {
if !(SysArch.Family == sys.PPC64 && Linkmode == LinkExternal && r.Sym.Name == ".TOC.") {
Errorf(s, "unhandled relocation for %s (type %d rtype %d)", r.Sym.Name, r.Sym.Type, r.Type)
}
}
- if r.Sym != nil && r.Sym.Type != objabi.STLSBSS && r.Type != objabi.R_WEAKADDROFF && !r.Sym.Attr.Reachable() {
+ if r.Sym != nil && r.Sym.Type != STLSBSS && r.Type != objabi.R_WEAKADDROFF && !r.Sym.Attr.Reachable() {
Errorf(s, "unreachable sym in relocation: %s", r.Sym.Name)
}
}
case objabi.R_ADDR:
- if Linkmode == LinkExternal && r.Sym.Type != objabi.SCONST {
+ if Linkmode == LinkExternal && r.Sym.Type != SCONST {
r.Done = 0
// set up addend for eventual relocation via outer symbol.
rs = rs.Outer
}
- if rs.Type != objabi.SHOSTOBJ && rs.Type != objabi.SDYNIMPORT && rs.Sect == nil {
+ if rs.Type != SHOSTOBJ && rs.Type != SDYNIMPORT && rs.Sect == nil {
Errorf(s, "missing section for relocation target %s", rs.Name)
}
r.Xsym = rs
// table, then it will add o twice into the relocated value.
// The workaround is that on arm64 don't ever add symaddr to o and always use
// extern relocation by requiring rs->dynid >= 0.
- if rs.Type != objabi.SHOSTOBJ {
+ if rs.Type != SHOSTOBJ {
if SysArch.Family == sys.ARM64 && rs.Dynid < 0 {
Errorf(s, "R_ADDR reloc to %s+%d is not supported on darwin/arm64", rs.Name, o)
}
// r->sym can be null when CALL $(constant) is transformed from absolute PC to relative PC call.
case objabi.R_GOTPCREL:
- if ctxt.DynlinkingGo() && Headtype == objabi.Hdarwin && r.Sym != nil && r.Sym.Type != objabi.SCONST {
+ if ctxt.DynlinkingGo() && Headtype == objabi.Hdarwin && r.Sym != nil && r.Sym.Type != SCONST {
r.Done = 0
r.Xadd = r.Add
r.Xadd -= int64(r.Siz) // relative to address after the relocated chunk
}
fallthrough
case objabi.R_CALL, objabi.R_PCREL:
- if Linkmode == LinkExternal && r.Sym != nil && r.Sym.Type != objabi.SCONST && (r.Sym.Sect != s.Sect || r.Type == objabi.R_GOTPCREL) {
+ if Linkmode == LinkExternal && r.Sym != nil && r.Sym.Type != SCONST && (r.Sym.Sect != s.Sect || r.Type == objabi.R_GOTPCREL) {
r.Done = 0
// set up addend for eventual relocation via outer symbol.
}
r.Xadd -= int64(r.Siz) // relative to address after the relocated chunk
- if rs.Type != objabi.SHOSTOBJ && rs.Type != objabi.SDYNIMPORT && rs.Sect == nil {
+ if rs.Type != SHOSTOBJ && rs.Type != SDYNIMPORT && rs.Sect == nil {
Errorf(s, "missing section for relocation target %s", rs.Name)
}
r.Xsym = rs
}
} else if Headtype == objabi.Hdarwin {
if r.Type == objabi.R_CALL {
- if rs.Type != objabi.SHOSTOBJ {
+ if rs.Type != SHOSTOBJ {
o += int64(uint64(Symaddr(rs)) - rs.Sect.Vaddr)
}
o -= int64(r.Off) // relative to section offset, not symbol
Thearch.Adddynrel(ctxt, s, r)
continue
}
- if r.Sym != nil && r.Sym.Type == objabi.SDYNIMPORT || r.Type >= 256 {
+ if r.Sym != nil && r.Sym.Type == SDYNIMPORT || r.Type >= 256 {
if r.Sym != nil && !r.Sym.Attr.Reachable() {
Errorf(s, "dynamic relocation to unreachable symbol %s", r.Sym.Name)
}
}
}
-func dynreloc(ctxt *Link, data *[objabi.SXREF][]*Symbol) {
+func dynreloc(ctxt *Link, data *[SXREF][]*Symbol) {
// -d suppresses dynamic loader format, so we may as well not
// compute these sections or mark their symbols as reachable.
if *FlagD && Headtype != objabi.Hwindows {
func blk(ctxt *Link, syms []*Symbol, addr, size int64, pad []byte) {
for i, s := range syms {
- if s.Type&objabi.SSUB == 0 && s.Value >= addr {
+ if s.Type&SSUB == 0 && s.Value >= addr {
syms = syms[i:]
break
}
eaddr := addr + size
for _, s := range syms {
- if s.Type&objabi.SSUB != 0 {
+ if s.Type&SSUB != 0 {
continue
}
if s.Value >= eaddr {
sp := ctxt.Syms.Lookup(p, 0)
Addstring(sp, value)
- sp.Type = objabi.SRODATA
+ sp.Type = SRODATA
s := ctxt.Syms.Lookup(name, 0)
s.Size = 0
func (ctxt *Link) checkstrdata() {
for _, s := range strdata {
- if s.Type == objabi.STEXT {
+ if s.Type == STEXT {
Errorf(s, "cannot use -X with text symbol")
} else if s.Gotype != nil && s.Gotype.Name != "type.string" {
Errorf(s, "cannot use -X with non-string symbol")
func Addstring(s *Symbol, str string) int64 {
if s.Type == 0 {
- s.Type = objabi.SNOPTRDATA
+ s.Type = SNOPTRDATA
}
s.Attr |= AttrReachable
r := s.Size
// symbol used to define the string data and must be unique per linked object.
func addgostring(ctxt *Link, s *Symbol, symname, str string) {
sym := ctxt.Syms.Lookup(symname, 0)
- if sym.Type != objabi.Sxxx {
+ if sym.Type != Sxxx {
Errorf(s, "duplicate symname in addgostring: %s", symname)
}
sym.Attr |= AttrReachable
sym.Attr |= AttrLocal
- sym.Type = objabi.SRODATA
+ sym.Type = SRODATA
sym.Size = int64(len(str))
sym.P = []byte(str)
Addaddr(ctxt, s, sym)
func addinitarrdata(ctxt *Link, s *Symbol) {
p := s.Name + ".ptr"
sp := ctxt.Syms.Lookup(p, 0)
- sp.Type = objabi.SINITARR
+ sp.Type = SINITARR
sp.Size = 0
sp.Attr |= AttrDuplicateOK
Addaddr(ctxt, sp, s)
func dosymtype(ctxt *Link) {
for _, s := range ctxt.Syms.Allsym {
if len(s.P) > 0 {
- if s.Type == objabi.SBSS {
- s.Type = objabi.SDATA
+ if s.Type == SBSS {
+ s.Type = SDATA
}
- if s.Type == objabi.SNOPTRBSS {
- s.Type = objabi.SNOPTRDATA
+ if s.Type == SNOPTRBSS {
+ s.Type = SNOPTRDATA
}
}
// Create a new entry in the .init_array section that points to the
const cutoff int64 = 2e9 // 2 GB (or so; looks better in errors than 2^31)
-func checkdatsize(ctxt *Link, datsize int64, symn objabi.SymKind) {
+func checkdatsize(ctxt *Link, datsize int64, symn SymKind) {
if datsize > cutoff {
Errorf(nil, "too much data in section %v (over %d bytes)", symn, cutoff)
}
ctxt.Syms.Lookup("runtime.edata", 0).Attr.Set(AttrSpecial, false)
types := ctxt.Syms.Lookup("runtime.types", 0)
- types.Type = objabi.STYPE
+ types.Type = STYPE
types.Size = 8
types.Attr.Set(AttrSpecial, false)
etypes := ctxt.Syms.Lookup("runtime.etypes", 0)
- etypes.Type = objabi.SFUNCTAB
+ etypes.Type = SFUNCTAB
etypes.Attr.Set(AttrSpecial, false)
}
// Collect data symbols by type into data.
- var data [objabi.SXREF][]*Symbol
+ var data [SXREF][]*Symbol
for _, s := range ctxt.Syms.Allsym {
if !s.Attr.Reachable() || s.Attr.Special() {
continue
}
- if s.Type <= objabi.STEXT || s.Type >= objabi.SXREF {
+ if s.Type <= STEXT || s.Type >= SXREF {
continue
}
data[s.Type] = append(data[s.Type], s)
// "read only" data with relocations needs to go in its own section
// when building a shared library. We do this by boosting objects of
// type SXXX with relocations to type SXXXRELRO.
- for _, symnro := range objabi.ReadOnly {
- symnrelro := objabi.RelROMap[symnro]
+ for _, symnro := range ReadOnly {
+ symnrelro := RelROMap[symnro]
ro := []*Symbol{}
relro := data[symnrelro]
for _, s := range data[symnro] {
isRelro := len(s.R) > 0
switch s.Type {
- case objabi.STYPE, objabi.STYPERELRO, objabi.SGOFUNCRELRO:
+ case STYPE, STYPERELRO, SGOFUNCRELRO:
// Symbols are not sorted yet, so it is possible
// that an Outer symbol has been changed to a
// relro Type before it reaches here.
}
// Sort symbols.
- var dataMaxAlign [objabi.SXREF]int32
+ var dataMaxAlign [SXREF]int32
var wg sync.WaitGroup
for symn := range data {
- symn := objabi.SymKind(symn)
+ symn := SymKind(symn)
wg.Add(1)
go func() {
data[symn], dataMaxAlign[symn] = dodataSect(ctxt, symn, data[symn])
datsize := int64(0)
// Writable data sections that do not need any specialized handling.
- writable := []objabi.SymKind{
- objabi.SELFSECT,
- objabi.SMACHO,
- objabi.SMACHOGOT,
- objabi.SWINDOWS,
+ writable := []SymKind{
+ SELFSECT,
+ SMACHO,
+ SMACHOGOT,
+ SWINDOWS,
}
for _, symn := range writable {
for _, s := range data[symn] {
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
s.Sect = sect
- s.Type = objabi.SDATA
+ s.Type = SDATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
sect.Length = uint64(datsize) - sect.Vaddr
}
// .got (and .toc on ppc64)
- if len(data[objabi.SELFGOT]) > 0 {
+ if len(data[SELFGOT]) > 0 {
sect := addsection(&Segdata, ".got", 06)
- sect.Align = dataMaxAlign[objabi.SELFGOT]
+ sect.Align = dataMaxAlign[SELFGOT]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
var toc *Symbol
- for _, s := range data[objabi.SELFGOT] {
+ for _, s := range data[SELFGOT] {
datsize = aligndatsize(datsize, s)
s.Sect = sect
- s.Type = objabi.SDATA
+ s.Type = SDATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
// Resolve .TOC. symbol for this object file (ppc64)
datsize += s.Size
}
- checkdatsize(ctxt, datsize, objabi.SELFGOT)
+ checkdatsize(ctxt, datsize, SELFGOT)
sect.Length = uint64(datsize) - sect.Vaddr
}
/* pointer-free data */
sect := addsection(&Segdata, ".noptrdata", 06)
- sect.Align = dataMaxAlign[objabi.SNOPTRDATA]
+ sect.Align = dataMaxAlign[SNOPTRDATA]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
ctxt.Syms.Lookup("runtime.noptrdata", 0).Sect = sect
ctxt.Syms.Lookup("runtime.enoptrdata", 0).Sect = sect
- for _, s := range data[objabi.SNOPTRDATA] {
+ for _, s := range data[SNOPTRDATA] {
datsize = aligndatsize(datsize, s)
s.Sect = sect
- s.Type = objabi.SDATA
+ s.Type = SDATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
}
- checkdatsize(ctxt, datsize, objabi.SNOPTRDATA)
+ checkdatsize(ctxt, datsize, SNOPTRDATA)
sect.Length = uint64(datsize) - sect.Vaddr
hasinitarr := *FlagLinkshared
}
if hasinitarr {
sect := addsection(&Segdata, ".init_array", 06)
- sect.Align = dataMaxAlign[objabi.SINITARR]
+ sect.Align = dataMaxAlign[SINITARR]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
- for _, s := range data[objabi.SINITARR] {
+ for _, s := range data[SINITARR] {
datsize = aligndatsize(datsize, s)
s.Sect = sect
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
}
sect.Length = uint64(datsize) - sect.Vaddr
- checkdatsize(ctxt, datsize, objabi.SINITARR)
+ checkdatsize(ctxt, datsize, SINITARR)
}
/* data */
sect = addsection(&Segdata, ".data", 06)
- sect.Align = dataMaxAlign[objabi.SDATA]
+ sect.Align = dataMaxAlign[SDATA]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
ctxt.Syms.Lookup("runtime.data", 0).Sect = sect
ctxt.Syms.Lookup("runtime.edata", 0).Sect = sect
var gc GCProg
gc.Init(ctxt, "runtime.gcdata")
- for _, s := range data[objabi.SDATA] {
+ for _, s := range data[SDATA] {
s.Sect = sect
- s.Type = objabi.SDATA
+ s.Type = SDATA
datsize = aligndatsize(datsize, s)
s.Value = int64(uint64(datsize) - sect.Vaddr)
gc.AddSym(s)
datsize += s.Size
}
- checkdatsize(ctxt, datsize, objabi.SDATA)
+ checkdatsize(ctxt, datsize, SDATA)
sect.Length = uint64(datsize) - sect.Vaddr
gc.End(int64(sect.Length))
/* bss */
sect = addsection(&Segdata, ".bss", 06)
- sect.Align = dataMaxAlign[objabi.SBSS]
+ sect.Align = dataMaxAlign[SBSS]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
ctxt.Syms.Lookup("runtime.bss", 0).Sect = sect
ctxt.Syms.Lookup("runtime.ebss", 0).Sect = sect
gc = GCProg{}
gc.Init(ctxt, "runtime.gcbss")
- for _, s := range data[objabi.SBSS] {
+ for _, s := range data[SBSS] {
s.Sect = sect
datsize = aligndatsize(datsize, s)
s.Value = int64(uint64(datsize) - sect.Vaddr)
gc.AddSym(s)
datsize += s.Size
}
- checkdatsize(ctxt, datsize, objabi.SBSS)
+ checkdatsize(ctxt, datsize, SBSS)
sect.Length = uint64(datsize) - sect.Vaddr
gc.End(int64(sect.Length))
/* pointer-free bss */
sect = addsection(&Segdata, ".noptrbss", 06)
- sect.Align = dataMaxAlign[objabi.SNOPTRBSS]
+ sect.Align = dataMaxAlign[SNOPTRBSS]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
ctxt.Syms.Lookup("runtime.noptrbss", 0).Sect = sect
ctxt.Syms.Lookup("runtime.enoptrbss", 0).Sect = sect
- for _, s := range data[objabi.SNOPTRBSS] {
+ for _, s := range data[SNOPTRBSS] {
datsize = aligndatsize(datsize, s)
s.Sect = sect
s.Value = int64(uint64(datsize) - sect.Vaddr)
sect.Length = uint64(datsize) - sect.Vaddr
ctxt.Syms.Lookup("runtime.end", 0).Sect = sect
- checkdatsize(ctxt, datsize, objabi.SNOPTRBSS)
+ checkdatsize(ctxt, datsize, SNOPTRBSS)
- if len(data[objabi.STLSBSS]) > 0 {
+ if len(data[STLSBSS]) > 0 {
var sect *Section
if Iself && (Linkmode == LinkExternal || !*FlagD) {
sect = addsection(&Segdata, ".tbss", 06)
}
datsize = 0
- for _, s := range data[objabi.STLSBSS] {
+ for _, s := range data[STLSBSS] {
datsize = aligndatsize(datsize, s)
s.Sect = sect
s.Value = datsize
datsize += s.Size
}
- checkdatsize(ctxt, datsize, objabi.STLSBSS)
+ checkdatsize(ctxt, datsize, STLSBSS)
if sect != nil {
sect.Length = uint64(datsize)
datsize = 0
/* read-only executable ELF, Mach-O sections */
- if len(data[objabi.STEXT]) != 0 {
- Errorf(nil, "dodata found an STEXT symbol: %s", data[objabi.STEXT][0].Name)
+ if len(data[STEXT]) != 0 {
+ Errorf(nil, "dodata found an STEXT symbol: %s", data[STEXT][0].Name)
}
- for _, s := range data[objabi.SELFRXSECT] {
+ for _, s := range data[SELFRXSECT] {
sect := addsection(&Segtext, s.Name, 04)
sect.Align = symalign(s)
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
sect.Length = uint64(datsize) - sect.Vaddr
- checkdatsize(ctxt, datsize, objabi.SELFRXSECT)
+ checkdatsize(ctxt, datsize, SELFRXSECT)
}
/* read-only data */
ctxt.Syms.Lookup("runtime.types", 0).Sect = sect
ctxt.Syms.Lookup("runtime.etypes", 0).Sect = sect
}
- for _, symn := range objabi.ReadOnly {
+ for _, symn := range ReadOnly {
align := dataMaxAlign[symn]
if sect.Align < align {
sect.Align = align
}
}
datsize = Rnd(datsize, int64(sect.Align))
- for _, symn := range objabi.ReadOnly {
+ for _, symn := range ReadOnly {
for _, s := range data[symn] {
datsize = aligndatsize(datsize, s)
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
}
sect.Length = uint64(datsize) - sect.Vaddr
/* read-only ELF, Mach-O sections */
- for _, s := range data[objabi.SELFROSECT] {
+ for _, s := range data[SELFROSECT] {
sect = addsection(segro, s.Name, 04)
sect.Align = symalign(s)
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
sect.Length = uint64(datsize) - sect.Vaddr
}
- checkdatsize(ctxt, datsize, objabi.SELFROSECT)
+ checkdatsize(ctxt, datsize, SELFROSECT)
- for _, s := range data[objabi.SMACHOPLT] {
+ for _, s := range data[SMACHOPLT] {
sect = addsection(segro, s.Name, 04)
sect.Align = symalign(s)
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
sect.Length = uint64(datsize) - sect.Vaddr
}
- checkdatsize(ctxt, datsize, objabi.SMACHOPLT)
+ checkdatsize(ctxt, datsize, SMACHOPLT)
// There is some data that are conceptually read-only but are written to by
// relocations. On GNU systems, we can arrange for the dynamic linker to
sect.Vaddr = 0
ctxt.Syms.Lookup("runtime.types", 0).Sect = sect
ctxt.Syms.Lookup("runtime.etypes", 0).Sect = sect
- for _, symnro := range objabi.ReadOnly {
- symn := objabi.RelROMap[symnro]
+ for _, symnro := range ReadOnly {
+ symn := RelROMap[symnro]
align := dataMaxAlign[symn]
if sect.Align < align {
sect.Align = align
}
}
datsize = Rnd(datsize, int64(sect.Align))
- for _, symnro := range objabi.ReadOnly {
- symn := objabi.RelROMap[symnro]
+ for _, symnro := range ReadOnly {
+ symn := RelROMap[symnro]
for _, s := range data[symn] {
datsize = aligndatsize(datsize, s)
if s.Outer != nil && s.Outer.Sect != nil && s.Outer.Sect != sect {
Errorf(s, "s.Outer (%s) in different section from s, %s != %s", s.Outer.Name, s.Outer.Sect.Name, sect.Name)
}
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
}
/* typelink */
sect = addrelrosection(".typelink")
- sect.Align = dataMaxAlign[objabi.STYPELINK]
+ sect.Align = dataMaxAlign[STYPELINK]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
typelink := ctxt.Syms.Lookup("runtime.typelink", 0)
typelink.Sect = sect
- typelink.Type = objabi.SRODATA
+ typelink.Type = SRODATA
datsize += typelink.Size
- checkdatsize(ctxt, datsize, objabi.STYPELINK)
+ checkdatsize(ctxt, datsize, STYPELINK)
sect.Length = uint64(datsize) - sect.Vaddr
/* itablink */
sect = addrelrosection(".itablink")
- sect.Align = dataMaxAlign[objabi.SITABLINK]
+ sect.Align = dataMaxAlign[SITABLINK]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
ctxt.Syms.Lookup("runtime.itablink", 0).Sect = sect
ctxt.Syms.Lookup("runtime.eitablink", 0).Sect = sect
- for _, s := range data[objabi.SITABLINK] {
+ for _, s := range data[SITABLINK] {
datsize = aligndatsize(datsize, s)
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
}
- checkdatsize(ctxt, datsize, objabi.SITABLINK)
+ checkdatsize(ctxt, datsize, SITABLINK)
sect.Length = uint64(datsize) - sect.Vaddr
/* gosymtab */
sect = addrelrosection(".gosymtab")
- sect.Align = dataMaxAlign[objabi.SSYMTAB]
+ sect.Align = dataMaxAlign[SSYMTAB]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
ctxt.Syms.Lookup("runtime.symtab", 0).Sect = sect
ctxt.Syms.Lookup("runtime.esymtab", 0).Sect = sect
- for _, s := range data[objabi.SSYMTAB] {
+ for _, s := range data[SSYMTAB] {
datsize = aligndatsize(datsize, s)
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
}
- checkdatsize(ctxt, datsize, objabi.SSYMTAB)
+ checkdatsize(ctxt, datsize, SSYMTAB)
sect.Length = uint64(datsize) - sect.Vaddr
/* gopclntab */
sect = addrelrosection(".gopclntab")
- sect.Align = dataMaxAlign[objabi.SPCLNTAB]
+ sect.Align = dataMaxAlign[SPCLNTAB]
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
ctxt.Syms.Lookup("runtime.pclntab", 0).Sect = sect
ctxt.Syms.Lookup("runtime.epclntab", 0).Sect = sect
- for _, s := range data[objabi.SPCLNTAB] {
+ for _, s := range data[SPCLNTAB] {
datsize = aligndatsize(datsize, s)
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
}
- checkdatsize(ctxt, datsize, objabi.SRODATA)
+ checkdatsize(ctxt, datsize, SRODATA)
sect.Length = uint64(datsize) - sect.Vaddr
// 6g uses 4-byte relocation offsets, so the entire segment must fit in 32 bits.
Errorf(nil, "read-only data segment too large: %d", datsize)
}
- for symn := objabi.SELFRXSECT; symn < objabi.SXREF; symn++ {
+ for symn := SELFRXSECT; symn < SXREF; symn++ {
datap = append(datap, data[symn]...)
}
var s *Symbol
var i int
for i, s = range dwarfp {
- if s.Type != objabi.SDWARFSECT {
+ if s.Type != SDWARFSECT {
break
}
sect = addsection(&Segdwarf, s.Name, 04)
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
sect.Length = uint64(datsize) - sect.Vaddr
}
- checkdatsize(ctxt, datsize, objabi.SDWARFSECT)
+ checkdatsize(ctxt, datsize, SDWARFSECT)
if i < len(dwarfp) {
sect = addsection(&Segdwarf, ".debug_info", 04)
datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize)
for _, s := range dwarfp[i:] {
- if s.Type != objabi.SDWARFINFO {
+ if s.Type != SDWARFINFO {
break
}
s.Sect = sect
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr)
s.Attr |= AttrLocal
datsize += s.Size
}
sect.Length = uint64(datsize) - sect.Vaddr
- checkdatsize(ctxt, datsize, objabi.SDWARFINFO)
+ checkdatsize(ctxt, datsize, SDWARFINFO)
}
/* number the sections */
}
}
-func dodataSect(ctxt *Link, symn objabi.SymKind, syms []*Symbol) (result []*Symbol, maxAlign int32) {
+func dodataSect(ctxt *Link, symn SymKind, syms []*Symbol) (result []*Symbol, maxAlign int32) {
if Headtype == objabi.Hdarwin {
// Some symbols may no longer belong in syms
// due to movement in machosymorder.
}
switch s.Type {
- case objabi.SELFGOT:
+ case SELFGOT:
// For ppc64, we want to interleave the .got and .toc sections
// from input files. Both are type SELFGOT, so in that case
// we skip size comparison and fall through to the name
syms[len(syms)-1] = tail
}
- if Iself && symn == objabi.SELFROSECT {
+ if Iself && symn == SELFROSECT {
// Make .rela and .rela.plt contiguous, the ELF ABI requires this
// and Solaris actually cares.
reli, plti := -1, -1
// The \xff is invalid UTF-8, meant to make it less likely
// to find one of these accidentally.
data := "\xff Go build ID: " + strconv.Quote(*flagBuildid) + "\n \xff"
- sym.Type = objabi.STEXT
+ sym.Type = STEXT
sym.P = []byte(data)
sym.Size = int64(len(sym.P))
// will not need to create new text sections, and so no need to return sect and n.
func assignAddress(ctxt *Link, sect *Section, n int, sym *Symbol, va uint64) (*Section, int, uint64) {
sym.Sect = sect
- if sym.Type&objabi.SSUB != 0 {
+ if sym.Type&SSUB != 0 {
return sect, n, va
}
if sym.Align != 0 {
s.Value = int64(sectSym.Sect.Vaddr + 16)
}
- ctxt.xdefine("runtime.text", objabi.STEXT, int64(text.Vaddr))
- ctxt.xdefine("runtime.etext", objabi.STEXT, int64(lasttext.Vaddr+lasttext.Length))
+ ctxt.xdefine("runtime.text", STEXT, int64(text.Vaddr))
+ ctxt.xdefine("runtime.etext", STEXT, int64(lasttext.Vaddr+lasttext.Length))
// If there are multiple text sections, create runtime.text.n for
// their section Vaddr, using n for index
for _, sect := range Segtext.Sections[1:] {
if sect.Name == ".text" {
symname := fmt.Sprintf("runtime.text.%d", n)
- ctxt.xdefine(symname, objabi.STEXT, int64(sect.Vaddr))
+ ctxt.xdefine(symname, STEXT, int64(sect.Vaddr))
n++
} else {
break
}
}
- ctxt.xdefine("runtime.rodata", objabi.SRODATA, int64(rodata.Vaddr))
- ctxt.xdefine("runtime.erodata", objabi.SRODATA, int64(rodata.Vaddr+rodata.Length))
- ctxt.xdefine("runtime.types", objabi.SRODATA, int64(types.Vaddr))
- ctxt.xdefine("runtime.etypes", objabi.SRODATA, int64(types.Vaddr+types.Length))
- ctxt.xdefine("runtime.itablink", objabi.SRODATA, int64(itablink.Vaddr))
- ctxt.xdefine("runtime.eitablink", objabi.SRODATA, int64(itablink.Vaddr+itablink.Length))
+ ctxt.xdefine("runtime.rodata", SRODATA, int64(rodata.Vaddr))
+ ctxt.xdefine("runtime.erodata", SRODATA, int64(rodata.Vaddr+rodata.Length))
+ ctxt.xdefine("runtime.types", SRODATA, int64(types.Vaddr))
+ ctxt.xdefine("runtime.etypes", SRODATA, int64(types.Vaddr+types.Length))
+ ctxt.xdefine("runtime.itablink", SRODATA, int64(itablink.Vaddr))
+ ctxt.xdefine("runtime.eitablink", SRODATA, int64(itablink.Vaddr+itablink.Length))
sym := ctxt.Syms.Lookup("runtime.gcdata", 0)
sym.Attr |= AttrLocal
- ctxt.xdefine("runtime.egcdata", objabi.SRODATA, Symaddr(sym)+sym.Size)
+ ctxt.xdefine("runtime.egcdata", SRODATA, Symaddr(sym)+sym.Size)
ctxt.Syms.Lookup("runtime.egcdata", 0).Sect = sym.Sect
sym = ctxt.Syms.Lookup("runtime.gcbss", 0)
sym.Attr |= AttrLocal
- ctxt.xdefine("runtime.egcbss", objabi.SRODATA, Symaddr(sym)+sym.Size)
+ ctxt.xdefine("runtime.egcbss", SRODATA, Symaddr(sym)+sym.Size)
ctxt.Syms.Lookup("runtime.egcbss", 0).Sect = sym.Sect
- ctxt.xdefine("runtime.symtab", objabi.SRODATA, int64(symtab.Vaddr))
- ctxt.xdefine("runtime.esymtab", objabi.SRODATA, int64(symtab.Vaddr+symtab.Length))
- ctxt.xdefine("runtime.pclntab", objabi.SRODATA, int64(pclntab.Vaddr))
- ctxt.xdefine("runtime.epclntab", objabi.SRODATA, int64(pclntab.Vaddr+pclntab.Length))
- ctxt.xdefine("runtime.noptrdata", objabi.SNOPTRDATA, int64(noptr.Vaddr))
- ctxt.xdefine("runtime.enoptrdata", objabi.SNOPTRDATA, int64(noptr.Vaddr+noptr.Length))
- ctxt.xdefine("runtime.bss", objabi.SBSS, int64(bss.Vaddr))
- ctxt.xdefine("runtime.ebss", objabi.SBSS, int64(bss.Vaddr+bss.Length))
- ctxt.xdefine("runtime.data", objabi.SDATA, int64(data.Vaddr))
- ctxt.xdefine("runtime.edata", objabi.SDATA, int64(data.Vaddr+data.Length))
- ctxt.xdefine("runtime.noptrbss", objabi.SNOPTRBSS, int64(noptrbss.Vaddr))
- ctxt.xdefine("runtime.enoptrbss", objabi.SNOPTRBSS, int64(noptrbss.Vaddr+noptrbss.Length))
- ctxt.xdefine("runtime.end", objabi.SBSS, int64(Segdata.Vaddr+Segdata.Length))
+ ctxt.xdefine("runtime.symtab", SRODATA, int64(symtab.Vaddr))
+ ctxt.xdefine("runtime.esymtab", SRODATA, int64(symtab.Vaddr+symtab.Length))
+ ctxt.xdefine("runtime.pclntab", SRODATA, int64(pclntab.Vaddr))
+ ctxt.xdefine("runtime.epclntab", SRODATA, int64(pclntab.Vaddr+pclntab.Length))
+ ctxt.xdefine("runtime.noptrdata", SNOPTRDATA, int64(noptr.Vaddr))
+ ctxt.xdefine("runtime.enoptrdata", SNOPTRDATA, int64(noptr.Vaddr+noptr.Length))
+ ctxt.xdefine("runtime.bss", SBSS, int64(bss.Vaddr))
+ ctxt.xdefine("runtime.ebss", SBSS, int64(bss.Vaddr+bss.Length))
+ ctxt.xdefine("runtime.data", SDATA, int64(data.Vaddr))
+ ctxt.xdefine("runtime.edata", SDATA, int64(data.Vaddr+data.Length))
+ ctxt.xdefine("runtime.noptrbss", SNOPTRBSS, int64(noptrbss.Vaddr))
+ ctxt.xdefine("runtime.enoptrbss", SNOPTRBSS, int64(noptrbss.Vaddr+noptrbss.Length))
+ ctxt.xdefine("runtime.end", SBSS, int64(Segdata.Vaddr+Segdata.Length))
}
// add a trampoline with symbol s (to be laid down after the current function)
func (ctxt *Link) AddTramp(s *Symbol) {
- s.Type = objabi.STEXT
+ s.Type = STEXT
s.Attr |= AttrReachable
s.Attr |= AttrOnList
ctxt.tramps = append(ctxt.tramps, s)
// Mark all symbols defined in this library as reachable when
// building a shared library.
for _, s := range d.ctxt.Syms.Allsym {
- if s.Type != 0 && s.Type != objabi.SDYNIMPORT {
+ if s.Type != 0 && s.Type != SDYNIMPORT {
d.mark(s, nil)
}
}
for len(d.markQueue) > 0 {
s := d.markQueue[0]
d.markQueue = d.markQueue[1:]
- if s.Type == objabi.STEXT {
+ if s.Type == STEXT {
if d.ctxt.Debugvlog > 1 {
d.ctxt.Logf("marktext %s\n", s.Name)
}
// Type.commonType.gc
func decodetypeGcprog(ctxt *Link, s *Symbol) []byte {
- if s.Type == objabi.SDYNIMPORT {
+ if s.Type == SDYNIMPORT {
addr := decodetypeGcprogShlib(ctxt, s)
sect := findShlibSection(ctxt, s.File, addr)
if sect != nil {
}
func decodetypeGcmask(ctxt *Link, s *Symbol) []byte {
- if s.Type == objabi.SDYNIMPORT {
+ if s.Type == SDYNIMPORT {
addr := decodetypeGcprogShlib(ctxt, s)
ptrdata := decodetypePtrdata(ctxt.Arch, s)
sect := findShlibSection(ctxt, s.File, addr)
func writeabbrev(ctxt *Link, syms []*Symbol) []*Symbol {
s := ctxt.Syms.Lookup(".debug_abbrev", 0)
- s.Type = objabi.SDWARFSECT
+ s.Type = SDWARFSECT
abbrevsym = s
Addbytes(s, dwarf.GetAbbrev())
return append(syms, s)
if abbrev != dwarf.DW_ABRV_VARIABLE || version == 0 {
sym := ctxt.Syms.Lookup(dwarf.InfoPrefix+name, version)
sym.Attr |= AttrHidden
- sym.Type = objabi.SDWARFINFO
+ sym.Type = SDWARFINFO
die.Sym = sym
}
}
// The string allocation below is optimized away because it is only used in a map lookup.
s := ctxt.Syms.ROLookup(string(n), 0)
prefixBuf = n[:len(dwarf.InfoPrefix)]
- if s != nil && s.Type == objabi.SDWARFINFO {
+ if s != nil && s.Type == SDWARFINFO {
return s
}
return nil
sym := ctxt.Syms.Lookup(dtolsym(def.Sym).Name+"..def", 0)
sym.Attr |= AttrHidden
- sym.Type = objabi.SDWARFINFO
+ sym.Type = SDWARFINFO
def.Sym = sym
// The typedef entry must be created after the def,
name := mkinternaltypename(typename, keyname, valname)
symname := dwarf.InfoPrefix + name
s := ctxt.Syms.ROLookup(symname, 0)
- if s != nil && s.Type == objabi.SDWARFINFO {
+ if s != nil && s.Type == SDWARFINFO {
return s
}
die := newdie(ctxt, &dwtypes, abbrev, name, 0)
if linesec == nil {
linesec = ctxt.Syms.Lookup(".debug_line", 0)
}
- linesec.Type = objabi.SDWARFSECT
+ linesec.Type = SDWARFSECT
linesec.R = linesec.R[:0]
ls := linesec
dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version))
dsym.Attr |= AttrHidden | AttrReachable
- dsym.Type = objabi.SDWARFINFO
+ dsym.Type = SDWARFINFO
for _, r := range dsym.R {
if r.Type == objabi.R_DWARFREF && r.Sym.Size == 0 {
if Buildmode == BuildmodeShared {
if framesec == nil {
framesec = ctxt.Syms.Lookup(".debug_frame", 0)
}
- framesec.Type = objabi.SDWARFSECT
+ framesec.Type = SDWARFSECT
framesec.R = framesec.R[:0]
fs := framesec
syms = append(syms, fs)
infosec = ctxt.Syms.Lookup(".debug_info", 0)
}
infosec.R = infosec.R[:0]
- infosec.Type = objabi.SDWARFINFO
+ infosec.Type = SDWARFINFO
infosec.Attr |= AttrReachable
syms = append(syms, infosec)
func writepub(ctxt *Link, sname string, ispub func(*dwarf.DWDie) bool, syms []*Symbol) []*Symbol {
s := ctxt.Syms.Lookup(sname, 0)
- s.Type = objabi.SDWARFSECT
+ s.Type = SDWARFSECT
syms = append(syms, s)
for compunit := dwroot.Child; compunit != nil; compunit = compunit.Link {
*/
func writearanges(ctxt *Link, syms []*Symbol) []*Symbol {
s := ctxt.Syms.Lookup(".debug_aranges", 0)
- s.Type = objabi.SDWARFSECT
+ s.Type = SDWARFSECT
// The first tuple is aligned to a multiple of the size of a single tuple
// (twice the size of an address)
headersize := int(Rnd(4+2+4+1+1, int64(SysArch.PtrSize*2))) // don't count unit_length field itself
if gdbscript != "" {
s := ctxt.Syms.Lookup(".debug_gdb_scripts", 0)
- s.Type = objabi.SDWARFSECT
+ s.Type = SDWARFSECT
syms = append(syms, s)
Adduint8(ctxt, s, 1) // magic 1 byte?
Addstring(s, gdbscript)
nsym := Nelfsym
s := ctxt.Syms.Lookup(".hash", 0)
- s.Type = objabi.SELFROSECT
+ s.Type = SELFROSECT
s.Attr |= AttrReachable
i := nsym
func addgonote(ctxt *Link, sectionName string, tag uint32, desc []byte) {
s := ctxt.Syms.Lookup(sectionName, 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFROSECT
+ s.Type = SELFROSECT
// namesz
Adduint32(ctxt, s, uint32(len(ELF_NOTE_GO_NAME)))
// descsz
/* predefine strings we need for section headers */
shstrtab := ctxt.Syms.Lookup(".shstrtab", 0)
- shstrtab.Type = objabi.SELFROSECT
+ shstrtab.Type = SELFROSECT
shstrtab.Attr |= AttrReachable
Addstring(shstrtab, "")
/* dynamic symbol table - first entry all zeros */
s := ctxt.Syms.Lookup(".dynsym", 0)
- s.Type = objabi.SELFROSECT
+ s.Type = SELFROSECT
s.Attr |= AttrReachable
if elf64 {
s.Size += ELF64SYMSIZE
/* dynamic string table */
s = ctxt.Syms.Lookup(".dynstr", 0)
- s.Type = objabi.SELFROSECT
+ s.Type = SELFROSECT
s.Attr |= AttrReachable
if s.Size == 0 {
Addstring(s, "")
/* relocation table */
s = ctxt.Syms.Lookup(elfRelType, 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFROSECT
+ s.Type = SELFROSECT
/* global offset table */
s = ctxt.Syms.Lookup(".got", 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFGOT // writable
+ s.Type = SELFGOT // writable
/* ppc64 glink resolver */
if SysArch.Family == sys.PPC64 {
s := ctxt.Syms.Lookup(".glink", 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFRXSECT
+ s.Type = SELFRXSECT
}
/* hash */
s = ctxt.Syms.Lookup(".hash", 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFROSECT
+ s.Type = SELFROSECT
s = ctxt.Syms.Lookup(".got.plt", 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFSECT // writable
+ s.Type = SELFSECT // writable
s = ctxt.Syms.Lookup(".plt", 0)
if SysArch.Family == sys.PPC64 {
// In the ppc64 ABI, .plt is a data section
// written by the dynamic linker.
- s.Type = objabi.SELFSECT
+ s.Type = SELFSECT
} else {
- s.Type = objabi.SELFRXSECT
+ s.Type = SELFRXSECT
}
Thearch.Elfsetupplt(ctxt)
s = ctxt.Syms.Lookup(elfRelType+".plt", 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFROSECT
+ s.Type = SELFROSECT
s = ctxt.Syms.Lookup(".gnu.version", 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFROSECT
+ s.Type = SELFROSECT
s = ctxt.Syms.Lookup(".gnu.version_r", 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFROSECT
+ s.Type = SELFROSECT
/* define dynamic elf table */
s = ctxt.Syms.Lookup(".dynamic", 0)
s.Attr |= AttrReachable
- s.Type = objabi.SELFSECT // writable
+ s.Type = SELFSECT // writable
/*
* .dynamic table
// part of the .note.go.abihash section in data.go:func address().
s := ctxt.Syms.Lookup("go.link.abihashbytes", 0)
s.Attr |= AttrLocal
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Attr |= AttrSpecial
s.Attr |= AttrReachable
s.Size = int64(sha1.Size)
elfshreloc(sect)
}
for _, s := range dwarfp {
- if len(s.R) > 0 || s.Type == objabi.SDWARFINFO {
+ if len(s.R) > 0 || s.Type == SDWARFINFO {
elfshreloc(s.Sect)
}
- if s.Type == objabi.SDWARFINFO {
+ if s.Type == SDWARFINFO {
break
}
}
/* type */
t := STB_GLOBAL << 4
- if s.Attr.CgoExport() && s.Type&objabi.SMASK == objabi.STEXT {
+ if s.Attr.CgoExport() && s.Type&SMASK == STEXT {
t |= STT_FUNC
} else {
t |= STT_OBJECT
Adduint8(ctxt, d, 0)
/* section where symbol is defined */
- if s.Type == objabi.SDYNIMPORT {
+ if s.Type == SDYNIMPORT {
Adduint16(ctxt, d, SHN_UNDEF)
} else {
Adduint16(ctxt, d, 1)
}
/* value */
- if s.Type == objabi.SDYNIMPORT {
+ if s.Type == SDYNIMPORT {
Adduint64(ctxt, d, 0)
} else {
Addaddr(ctxt, d, s)
Adduint32(ctxt, d, uint32(Addstring(ctxt.Syms.Lookup(".dynstr", 0), name)))
/* value */
- if s.Type == objabi.SDYNIMPORT {
+ if s.Type == SDYNIMPORT {
Adduint32(ctxt, d, 0)
} else {
Addaddr(ctxt, d, s)
t := STB_GLOBAL << 4
// TODO(mwhudson): presumably the behavior should actually be the same on both arm and 386.
- if SysArch.Family == sys.I386 && s.Attr.CgoExport() && s.Type&objabi.SMASK == objabi.STEXT {
+ if SysArch.Family == sys.I386 && s.Attr.CgoExport() && s.Type&SMASK == STEXT {
t |= STT_FUNC
- } else if SysArch.Family == sys.ARM && s.Attr.CgoExportDynamic() && s.Type&objabi.SMASK == objabi.STEXT {
+ } else if SysArch.Family == sys.ARM && s.Attr.CgoExportDynamic() && s.Type&SMASK == STEXT {
t |= STT_FUNC
} else {
t |= STT_OBJECT
Adduint8(ctxt, d, 0)
/* shndx */
- if s.Type == objabi.SDYNIMPORT {
+ if s.Type == SDYNIMPORT {
Adduint16(ctxt, d, SHN_UNDEF)
} else {
Adduint16(ctxt, d, 1)
s = ctxt.Syms.Lookup(local, 0)
if local != f[1] {
}
- if s.Type == 0 || s.Type == objabi.SXREF || s.Type == objabi.SHOSTOBJ {
+ if s.Type == 0 || s.Type == SXREF || s.Type == SHOSTOBJ {
s.Dynimplib = lib
s.Extname = remote
s.Dynimpvers = q
- if s.Type != objabi.SHOSTOBJ {
- s.Type = objabi.SDYNIMPORT
+ if s.Type != SHOSTOBJ {
+ s.Type = SDYNIMPORT
}
havedynamic = 1
}
}
local = f[1]
s = ctxt.Syms.Lookup(local, 0)
- s.Type = objabi.SHOSTOBJ
+ s.Type = SHOSTOBJ
s.Size = 0
continue
}
buf.WriteString("\n")
}
- s.Type = objabi.SCONST
+ s.Type = SCONST
s.Value = 0
}
}
return
case ElfSectFlagAlloc:
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
case ElfSectFlagAlloc + ElfSectFlagWrite:
if sect.type_ == ElfSectNobits {
- s.Type = objabi.SNOPTRBSS
+ s.Type = SNOPTRBSS
} else {
- s.Type = objabi.SNOPTRDATA
+ s.Type = SNOPTRDATA
}
case ElfSectFlagAlloc + ElfSectFlagExec:
- s.Type = objabi.STEXT
+ s.Type = STEXT
}
if sect.name == ".got" || sect.name == ".toc" {
- s.Type = objabi.SELFGOT
+ s.Type = SELFGOT
}
if sect.type_ == ElfSectProgbits {
s.P = sect.base
if uint64(s.Size) < sym.size {
s.Size = int64(sym.size)
}
- if s.Type == 0 || s.Type == objabi.SXREF {
- s.Type = objabi.SNOPTRBSS
+ if s.Type == 0 || s.Type == SXREF {
+ s.Type = SNOPTRBSS
}
continue
}
s.Sub = sect.sym.Sub
sect.sym.Sub = s
- s.Type = sect.sym.Type | s.Type&^objabi.SMASK | objabi.SSUB
+ s.Type = sect.sym.Type | s.Type&^SMASK | SSUB
if !s.Attr.CgoExportDynamic() {
s.Dynimplib = "" // satisfy dynimport
}
s.Value = int64(sym.value)
s.Size = int64(sym.size)
s.Outer = sect.sym
- if sect.sym.Type == objabi.STEXT {
+ if sect.sym.Type == STEXT {
if s.Attr.External() && !s.Attr.DuplicateOK() {
Errorf(s, "%s: duplicate symbol definition", pn)
}
if s.Sub != nil {
s.Sub = listsort(s.Sub)
}
- if s.Type == objabi.STEXT {
+ if s.Type == STEXT {
if s.Attr.OnList() {
log.Fatalf("symbol %s listed multiple times", s.Name)
}
// set dupok generally. See http://codereview.appspot.com/5823055/
// comment #5 for details.
if s != nil && sym.other == 2 {
- s.Type |= objabi.SHIDDEN
+ s.Type |= SHIDDEN
s.Attr |= AttrDuplicateOK
}
}
// so put it in the hash table.
if needSym != 0 {
s = ctxt.Syms.Lookup(sym.name, localSymVersion)
- s.Type |= objabi.SHIDDEN
+ s.Type |= SHIDDEN
}
break
// don't bother to add them into the hash table
s = ctxt.Syms.newsym(sym.name, localSymVersion)
- s.Type |= objabi.SHIDDEN
+ s.Type |= SHIDDEN
}
case ElfSymBindWeak:
if needSym != 0 {
s = ctxt.Syms.Lookup(sym.name, 0)
if sym.other == 2 {
- s.Type |= objabi.SHIDDEN
+ s.Type |= SHIDDEN
}
}
}
if s != nil && s.Type == 0 && sym.type_ != ElfSymTypeSection {
- s.Type = objabi.SXREF
+ s.Type = SXREF
}
sym.sym = s
if sect.segname == "__TEXT" {
if sect.name == "__text" {
- s.Type = objabi.STEXT
+ s.Type = STEXT
} else {
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
}
} else {
if sect.name == "__bss" {
- s.Type = objabi.SNOPTRBSS
+ s.Type = SNOPTRBSS
s.P = s.P[:0]
} else {
- s.Type = objabi.SNOPTRDATA
+ s.Type = SNOPTRDATA
}
}
Exitf("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name)
}
- s.Type = outer.Type | objabi.SSUB
+ s.Type = outer.Type | SSUB
s.Sub = outer.Sub
outer.Sub = s
s.Outer = outer
if !s.Attr.CgoExportDynamic() {
s.Dynimplib = "" // satisfy dynimport
}
- if outer.Type == objabi.STEXT {
+ if outer.Type == STEXT {
if s.Attr.External() && !s.Attr.DuplicateOK() {
Errorf(s, "%s: duplicate symbol definition", pn)
}
}
}
- if s.Type == objabi.STEXT {
+ if s.Type == STEXT {
if s.Attr.OnList() {
log.Fatalf("symbol %s listed multiple times", s.Name)
}
switch sect.Characteristics & (IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE) {
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ: //.rdata
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
case IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.bss
- s.Type = objabi.SNOPTRBSS
+ s.Type = SNOPTRBSS
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.data
- s.Type = objabi.SNOPTRDATA
+ s.Type = SNOPTRDATA
case IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ: //.text
- s.Type = objabi.STEXT
+ s.Type = STEXT
default:
return fmt.Errorf("unexpected flags %#06x for PE section %s", sect.Characteristics, sect.Name)
}
if pesym.SectionNumber == 0 { // extern
- if s.Type == objabi.SDYNIMPORT {
+ if s.Type == SDYNIMPORT {
s.Plt = -2 // flag for dynimport in PE object files.
}
- if s.Type == objabi.SXREF && pesym.Value > 0 { // global data
- s.Type = objabi.SNOPTRDATA
+ if s.Type == SXREF && pesym.Value > 0 { // global data
+ s.Type = SNOPTRDATA
s.Size = int64(pesym.Value)
}
sectsym := sectsyms[sect]
s.Sub = sectsym.Sub
sectsym.Sub = s
- s.Type = sectsym.Type | objabi.SSUB
+ s.Type = sectsym.Type | SSUB
s.Value = int64(pesym.Value)
s.Size = 4
s.Outer = sectsym
- if sectsym.Type == objabi.STEXT {
+ if sectsym.Type == STEXT {
if s.Attr.External() && !s.Attr.DuplicateOK() {
Errorf(s, "%s: duplicate symbol definition", pn)
}
if s.Sub != nil {
s.Sub = listsort(s.Sub)
}
- if s.Type == objabi.STEXT {
+ if s.Type == STEXT {
if s.Attr.OnList() {
log.Fatalf("symbol %s listed multiple times", s.Name)
}
}
if s != nil && s.Type == 0 && (sym.StorageClass != IMAGE_SYM_CLASS_STATIC || sym.Value != 0) {
- s.Type = objabi.SXREF
+ s.Type = SXREF
}
if strings.HasPrefix(symname, "__imp_") {
s.Got = -2 // flag for __imp_
if Linkmode == LinkExternal && SysArch.Family == sys.PPC64 {
toc := ctxt.Syms.Lookup(".TOC.", 0)
- toc.Type = objabi.SDYNIMPORT
+ toc.Type = SDYNIMPORT
}
if Linkmode == LinkExternal && !iscgo {
// Drop all the cgo_import_static declarations.
// Turns out we won't be needing them.
for _, s := range ctxt.Syms.Allsym {
- if s.Type == objabi.SHOSTOBJ {
+ if s.Type == SHOSTOBJ {
// If a symbol was marked both
// cgo_import_static and cgo_import_dynamic,
// then we want to make it cgo_import_dynamic
// now.
if s.Extname != "" && s.Dynimplib != "" && !s.Attr.CgoExport() {
- s.Type = objabi.SDYNIMPORT
+ s.Type = SDYNIMPORT
} else {
s.Type = 0
}
// runtime.tlsg is used for external linking on platforms that do not define
// a variable to hold g in assembly (currently only intel).
if tlsg.Type == 0 {
- tlsg.Type = objabi.STLSBSS
+ tlsg.Type = STLSBSS
tlsg.Size = int64(SysArch.PtrSize)
- } else if tlsg.Type != objabi.SDYNIMPORT {
+ } else if tlsg.Type != SDYNIMPORT {
Errorf(nil, "runtime declared tlsg variable %v", tlsg.Type)
}
tlsg.Attr |= AttrReachable
} else {
moduledata = ctxt.Syms.Lookup("runtime.firstmoduledata", 0)
}
- if moduledata.Type != 0 && moduledata.Type != objabi.SDYNIMPORT {
+ if moduledata.Type != 0 && moduledata.Type != SDYNIMPORT {
// If the module (toolchain-speak for "executable or shared
// library") we are linking contains the runtime package, it
// will define the runtime.firstmoduledata symbol and we
// recording the value of GOARM.
if SysArch.Family == sys.ARM {
s := ctxt.Syms.Lookup("runtime.goarm", 0)
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Size = 0
Adduint8(ctxt, s, uint8(objabi.GOARM))
}
if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) {
s := ctxt.Syms.Lookup("runtime.framepointer_enabled", 0)
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Size = 0
Adduint8(ctxt, s, 1)
}
}
// In all cases way we mark the moduledata as noptrdata to hide it from
// the GC.
- moduledata.Type = objabi.SNOPTRDATA
+ moduledata.Type = SNOPTRDATA
moduledata.Attr |= AttrReachable
ctxt.Moduledata = moduledata
any := false
for _, s := range ctxt.Syms.Allsym {
for _, r := range s.R {
- if r.Sym != nil && r.Sym.Type&objabi.SMASK == objabi.SXREF && r.Sym.Name != ".got" {
+ if r.Sym != nil && r.Sym.Type&SMASK == SXREF && r.Sym.Name != ".got" {
any = true
break
}
if SysArch == sys.Arch386 {
if (Buildmode == BuildmodeCArchive && Iself) || Buildmode == BuildmodeCShared || Buildmode == BuildmodePIE || ctxt.DynlinkingGo() {
got := ctxt.Syms.Lookup("_GLOBAL_OFFSET_TABLE_", 0)
- got.Type = objabi.SDYNIMPORT
+ got.Type = SDYNIMPORT
got.Attr |= AttrReachable
}
}
// pcln table entries for these any more so remove them from Textp.
textp := make([]*Symbol, 0, len(ctxt.Textp))
for _, s := range ctxt.Textp {
- if s.Type != objabi.SDYNIMPORT {
+ if s.Type != SDYNIMPORT {
textp = append(textp, s)
}
}
// libraries, any non-dynimport symbols we find that duplicate symbols
// already loaded should be ignored (the symbols from the .a files
// "win").
- if lsym.Type != 0 && lsym.Type != objabi.SDYNIMPORT {
+ if lsym.Type != 0 && lsym.Type != SDYNIMPORT {
continue
}
- lsym.Type = objabi.SDYNIMPORT
+ lsym.Type = SDYNIMPORT
lsym.ElfType = elf.ST_TYPE(elfsym.Info)
lsym.Size = int64(elfsym.Size)
if elfsym.Section != elf.SHN_UNDEF {
// should never be called directly.
// onlyctxt.Diagnose the direct caller.
// TODO(mwhudson): actually think about this.
- if depth == 1 && s.Type != objabi.SXREF && !ctxt.DynlinkingGo() &&
+ if depth == 1 && s.Type != SXREF && !ctxt.DynlinkingGo() &&
Buildmode != BuildmodeCArchive && Buildmode != BuildmodePIE && Buildmode != BuildmodeCShared && Buildmode != BuildmodePlugin {
Errorf(s, "call to external function")
// These symbols won't show up in the first loop below because we
// skip STEXT symbols. Normal STEXT symbols are emitted by walking textp.
s := ctxt.Syms.Lookup("runtime.text", 0)
- if s.Type == objabi.STEXT {
+ if s.Type == STEXT {
put(ctxt, s, s.Name, TextSym, s.Value, nil)
}
if s == nil {
break
}
- if s.Type == objabi.STEXT {
+ if s.Type == STEXT {
put(ctxt, s, s.Name, TextSym, s.Value, nil)
}
n++
}
s = ctxt.Syms.Lookup("runtime.etext", 0)
- if s.Type == objabi.STEXT {
+ if s.Type == STEXT {
put(ctxt, s, s.Name, TextSym, s.Value, nil)
}
if (s.Name == "" || s.Name[0] == '.') && s.Version == 0 && s.Name != ".rathole" && s.Name != ".TOC." {
continue
}
- switch s.Type & objabi.SMASK {
- case objabi.SCONST,
- objabi.SRODATA,
- objabi.SSYMTAB,
- objabi.SPCLNTAB,
- objabi.SINITARR,
- objabi.SDATA,
- objabi.SNOPTRDATA,
- objabi.SELFROSECT,
- objabi.SMACHOGOT,
- objabi.STYPE,
- objabi.SSTRING,
- objabi.SGOSTRING,
- objabi.SGOFUNC,
- objabi.SGCBITS,
- objabi.STYPERELRO,
- objabi.SSTRINGRELRO,
- objabi.SGOSTRINGRELRO,
- objabi.SGOFUNCRELRO,
- objabi.SGCBITSRELRO,
- objabi.SRODATARELRO,
- objabi.STYPELINK,
- objabi.SITABLINK,
- objabi.SWINDOWS:
+ switch s.Type & SMASK {
+ case SCONST,
+ SRODATA,
+ SSYMTAB,
+ SPCLNTAB,
+ SINITARR,
+ SDATA,
+ SNOPTRDATA,
+ SELFROSECT,
+ SMACHOGOT,
+ STYPE,
+ SSTRING,
+ SGOSTRING,
+ SGOFUNC,
+ SGCBITS,
+ STYPERELRO,
+ SSTRINGRELRO,
+ SGOSTRINGRELRO,
+ SGOFUNCRELRO,
+ SGCBITSRELRO,
+ SRODATARELRO,
+ STYPELINK,
+ SITABLINK,
+ SWINDOWS:
if !s.Attr.Reachable() {
continue
}
put(ctxt, s, s.Name, DataSym, Symaddr(s), s.Gotype)
- case objabi.SBSS, objabi.SNOPTRBSS:
+ case SBSS, SNOPTRBSS:
if !s.Attr.Reachable() {
continue
}
}
put(ctxt, s, s.Name, BSSSym, Symaddr(s), s.Gotype)
- case objabi.SFILE:
+ case SFILE:
put(ctxt, nil, s.Name, FileSym, s.Value, nil)
- case objabi.SHOSTOBJ:
+ case SHOSTOBJ:
if Headtype == objabi.Hwindows || Iself {
put(ctxt, s, s.Name, UndefinedSym, s.Value, nil)
}
- case objabi.SDYNIMPORT:
+ case SDYNIMPORT:
if !s.Attr.Reachable() {
continue
}
put(ctxt, s, s.Extname, UndefinedSym, 0, nil)
- case objabi.STLSBSS:
+ case STLSBSS:
if Linkmode == LinkExternal {
put(ctxt, s, s.Name, TLSSym, Symaddr(s), s.Gotype)
}
return s.Value
}
-func (ctxt *Link) xdefine(p string, t objabi.SymKind, v int64) {
+func (ctxt *Link) xdefine(p string, t SymKind, v int64) {
s := ctxt.Syms.Lookup(p, 0)
s.Type = t
s.Value = v
if s.Type == 0 {
return *FlagTextAddr
}
- if s.Type != objabi.STEXT {
+ if s.Type != STEXT {
Errorf(s, "entry not text")
}
return s.Value
if r.Sym == nil { // happens for some external ARM relocs
continue
}
- if r.Sym.Type == objabi.Sxxx || r.Sym.Type == objabi.SXREF {
+ if r.Sym.Type == Sxxx || r.Sym.Type == SXREF {
Errorf(s, "undefined: %q", r.Sym.Name)
}
if !r.Sym.Attr.Reachable() && r.Type != objabi.R_WEAKADDROFF {
if r.Sym == nil {
continue
}
- if (r.Type == objabi.R_CALL || r.Type == objabi.R_CALLARM || r.Type == objabi.R_CALLPOWER || r.Type == objabi.R_CALLMIPS) && r.Sym.Type == objabi.STEXT {
+ if (r.Type == objabi.R_CALL || r.Type == objabi.R_CALLARM || r.Type == objabi.R_CALLPOWER || r.Type == objabi.R_CALLMIPS) && r.Sym.Type == STEXT {
ctxt.Logf("%s calls %s\n", s.Name, r.Sym.Name)
}
}
type Symbol struct {
Name string
Extname string
- Type objabi.SymKind
+ Type SymKind
Version int16
Attr Attribute
Localentry uint8
package ld
import (
- "cmd/internal/objabi"
"cmd/internal/sys"
"sort"
"strings"
// empirically, string table must begin with " \x00".
s := ctxt.Syms.Lookup(".machosymstr", 0)
- s.Type = objabi.SMACHOSYMSTR
+ s.Type = SMACHOSYMSTR
s.Attr |= AttrReachable
Adduint8(ctxt, s, ' ')
Adduint8(ctxt, s, '\x00')
s = ctxt.Syms.Lookup(".machosymtab", 0)
- s.Type = objabi.SMACHOSYMTAB
+ s.Type = SMACHOSYMTAB
s.Attr |= AttrReachable
if Linkmode != LinkExternal {
s := ctxt.Syms.Lookup(".plt", 0) // will be __symbol_stub
- s.Type = objabi.SMACHOPLT
+ s.Type = SMACHOPLT
s.Attr |= AttrReachable
s = ctxt.Syms.Lookup(".got", 0) // will be __nl_symbol_ptr
- s.Type = objabi.SMACHOGOT
+ s.Type = SMACHOGOT
s.Attr |= AttrReachable
s.Align = 4
s = ctxt.Syms.Lookup(".linkedit.plt", 0) // indirect table for .plt
- s.Type = objabi.SMACHOINDIRECTPLT
+ s.Type = SMACHOINDIRECTPLT
s.Attr |= AttrReachable
s = ctxt.Syms.Lookup(".linkedit.got", 0) // indirect table for .got
- s.Type = objabi.SMACHOINDIRECTGOT
+ s.Type = SMACHOINDIRECTGOT
s.Attr |= AttrReachable
}
}
}
func symkind(s *Symbol) int {
- if s.Type == objabi.SDYNIMPORT {
+ if s.Type == SDYNIMPORT {
return SymKindUndef
}
if s.Attr.CgoExport() {
func machogenasmsym(ctxt *Link) {
genasmsym(ctxt, addsym)
for _, s := range ctxt.Syms.Allsym {
- if s.Type == objabi.SDYNIMPORT || s.Type == objabi.SHOSTOBJ {
+ if s.Type == SDYNIMPORT || s.Type == SHOSTOBJ {
if s.Attr.Reachable() {
addsym(ctxt, s, "", DataSym, 0, nil)
}
if strings.HasPrefix(s.Name, "go.link.pkghash") {
return true
}
- return s.Type >= objabi.SELFSECT // only writable sections
+ return s.Type >= SELFSECT // only writable sections
}
func machosymtab(ctxt *Link) {
// replace "·" as ".", because DTrace cannot handle it.
Addstring(symstr, strings.Replace(s.Extname, "·", ".", -1))
- if s.Type == objabi.SDYNIMPORT || s.Type == objabi.SHOSTOBJ {
+ if s.Type == SDYNIMPORT || s.Type == SHOSTOBJ {
Adduint8(ctxt, symtab, 0x01) // type N_EXT, external symbol
Adduint8(ctxt, symtab, 0) // no section
Adduint16(ctxt, symtab, 0) // desc
if c, err := r.rd.ReadByte(); c != symPrefix || err != nil {
log.Fatalln("readSym out of sync")
}
- t := objabi.SymKind(r.readInt())
+ t := abiSymKindToSymKind[r.readInt()]
s := r.readSymIndex()
flags := r.readInt()
dupok := flags&1 != 0
isdup := false
var dup *Symbol
- if s.Type != 0 && s.Type != objabi.SXREF {
- if (t == objabi.SDATA || t == objabi.SBSS || t == objabi.SNOPTRBSS) && len(data) == 0 && nreloc == 0 {
+ if s.Type != 0 && s.Type != SXREF {
+ if (t == SDATA || t == SBSS || t == SNOPTRBSS) && len(data) == 0 && nreloc == 0 {
if s.Size < int64(size) {
s.Size = int64(size)
}
return
}
- if (s.Type == objabi.SDATA || s.Type == objabi.SBSS || s.Type == objabi.SNOPTRBSS) && len(s.P) == 0 && len(s.R) == 0 {
+ if (s.Type == SDATA || s.Type == SBSS || s.Type == SNOPTRBSS) && len(s.P) == 0 && len(s.R) == 0 {
goto overwrite
}
- if s.Type != objabi.SBSS && s.Type != objabi.SNOPTRBSS && !dupok && !s.Attr.DuplicateOK() {
+ if s.Type != SBSS && s.Type != SNOPTRBSS && !dupok && !s.Attr.DuplicateOK() {
log.Fatalf("duplicate symbol %s (types %d and %d) in %s and %s", s.Name, s.Type, t, s.File, r.pn)
}
if len(s.P) > 0 {
if dupok {
s.Attr |= AttrDuplicateOK
}
- if t == objabi.SXREF {
+ if t == SXREF {
log.Fatalf("bad sxref")
}
if t == 0 {
log.Fatalf("missing type for %s in %s", s.Name, r.pn)
}
- if t == objabi.SBSS && (s.Type == objabi.SRODATA || s.Type == objabi.SNOPTRBSS) {
+ if t == SBSS && (s.Type == SRODATA || s.Type == SNOPTRBSS) {
t = s.Type
}
s.Type = t
}
}
- if s.Type == objabi.STEXT {
+ if s.Type == STEXT {
s.FuncInfo = new(FuncInfo)
pc := s.FuncInfo
}
}
}
- if s.Type == objabi.SDWARFINFO {
+ if s.Type == SDWARFINFO {
r.patchDWARFName(s)
}
}
if err != nil {
log.Panicf("failed to parse $-symbol %s: %v", s.Name, err)
}
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Attr |= AttrLocal
switch s.Name[:5] {
case "$f32.":
// numberfile assigns a file number to the file if it hasn't been assigned already.
func numberfile(ctxt *Link, file *Symbol) {
- if file.Type != objabi.SFILEPATH {
+ if file.Type != SFILEPATH {
ctxt.Filesyms = append(ctxt.Filesyms, file)
file.Value = int64(len(ctxt.Filesyms))
- file.Type = objabi.SFILEPATH
+ file.Type = SFILEPATH
path := file.Name[len(src.FileSymPrefix):]
file.Name = expandGoroot(path)
}
}
// We want to generate func table entries only for the "lowest level" symbols,
// not containers of subsymbols.
- if s.Type&objabi.SCONTAINER != 0 {
+ if s.Type&SCONTAINER != 0 {
return 1
}
return 0
func (ctxt *Link) pclntab() {
funcdataBytes := int64(0)
ftab := ctxt.Syms.Lookup("runtime.pclntab", 0)
- ftab.Type = objabi.SPCLNTAB
+ ftab.Type = SPCLNTAB
ftab.Attr |= AttrReachable
// See golang.org/s/go12symtab for the format. Briefly:
// Find container symbols, mark them with SCONTAINER
for _, s := range ctxt.Textp {
if s.Outer != nil {
- s.Outer.Type |= objabi.SCONTAINER
+ s.Outer.Type |= SCONTAINER
}
}
if len(pcln.InlTree) > 0 {
inlTreeSym := ctxt.Syms.Lookup("inltree."+s.Name, 0)
- inlTreeSym.Type = objabi.SRODATA
+ inlTreeSym.Type = SRODATA
inlTreeSym.Attr |= AttrReachable | AttrDuplicateOK
for i, call := range pcln.InlTree {
// function for a pc. See src/runtime/symtab.go:findfunc for details.
func (ctxt *Link) findfunctab() {
t := ctxt.Syms.Lookup("runtime.findfunctab", 0)
- t.Type = objabi.SRODATA
+ t.Type = SRODATA
t.Attr |= AttrReachable
t.Attr |= AttrLocal
if Linkmode == LinkInternal {
// some mingw libs depend on this symbol, for example, FindPESectionByName
- ctxt.xdefine("__image_base__", objabi.SDATA, PEBASE)
- ctxt.xdefine("_image_base__", objabi.SDATA, PEBASE)
+ ctxt.xdefine("__image_base__", SDATA, PEBASE)
+ ctxt.xdefine("_image_base__", SDATA, PEBASE)
}
HEADR = PEFILEHEADR
dr = nil
var m *Imp
for _, s := range ctxt.Syms.Allsym {
- if !s.Attr.Reachable() || s.Type != objabi.SDYNIMPORT {
+ if !s.Attr.Reachable() || s.Type != SDYNIMPORT {
continue
}
for d = dr; d != nil; d = d.next {
// Add real symbol name
for d := dr; d != nil; d = d.next {
for m = d.ms; m != nil; m = m.next {
- m.s.Type = objabi.SDATA
+ m.s.Type = SDATA
Symgrow(m.s, int64(SysArch.PtrSize))
dynName := m.s.Extname
// only windows/386 requires stdcall decoration
}
dynSym := ctxt.Syms.Lookup(dynName, 0)
dynSym.Attr |= AttrReachable
- dynSym.Type = objabi.SHOSTOBJ
+ dynSym.Type = SHOSTOBJ
r := Addrel(m.s)
r.Sym = dynSym
r.Off = 0
} else {
dynamic := ctxt.Syms.Lookup(".windynamic", 0)
dynamic.Attr |= AttrReachable
- dynamic.Type = objabi.SWINDOWS
+ dynamic.Type = SWINDOWS
for d := dr; d != nil; d = d.next {
for m = d.ms; m != nil; m = m.next {
- m.s.Type = objabi.SWINDOWS | objabi.SSUB
+ m.s.Type = SWINDOWS | SSUB
m.s.Sub = dynamic.Sub
dynamic.Sub = m.s
m.s.Value = dynamic.Size
rel := ctxt.Syms.Lookup(".rel", 0)
rel.Attr |= AttrReachable
- rel.Type = objabi.SELFROSECT
+ rel.Type = SELFROSECT
initdynimport(ctxt)
initdynexport(ctxt)
// Only windows/386 requires underscore prefix on external symbols.
if SysArch.Family == sys.I386 &&
Linkmode == LinkExternal &&
- (s.Type == objabi.SHOSTOBJ || s.Attr.CgoExport()) {
+ (s.Type == SHOSTOBJ || s.Attr.CgoExport()) {
s.Name = "_" + s.Name
}
// it still belongs to the .data section, not the .bss section.
// Same for runtime.epclntab (type STEXT), it belongs to .text
// section, not the .data section.
- if uint64(s.Value) >= Segdata.Vaddr+Segdata.Filelen && s.Type != objabi.SDATA && Linkmode == LinkExternal {
+ if uint64(s.Value) >= Segdata.Vaddr+Segdata.Filelen && s.Type != SDATA && Linkmode == LinkExternal {
value = int64(uint64(s.Value) - Segdata.Vaddr - Segdata.Filelen)
sect = bsssect
- } else if uint64(s.Value) >= Segdata.Vaddr && s.Type != objabi.STEXT {
+ } else if uint64(s.Value) >= Segdata.Vaddr && s.Type != STEXT {
value = int64(uint64(s.Value) - Segdata.Vaddr)
sect = datasect
} else if uint64(s.Value) >= Segtext.Vaddr {
typ = 0x0308 // "array of structs"
}
class := IMAGE_SYM_CLASS_EXTERNAL
- if s.Version != 0 || (s.Type&objabi.SHIDDEN != 0) || s.Attr.Local() {
+ if s.Version != 0 || (s.Type&SHIDDEN != 0) || s.Attr.Local() {
class = IMAGE_SYM_CLASS_STATIC
}
writeOneSymbol(s, value, sect, typ, uint8(class))
--- /dev/null
+// Derived from Inferno utils/6l/l.h and related files.
+// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/l.h
+//
+// 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.
+
+package ld
+
+// A SymKind describes the kind of memory represented by a symbol.
+type SymKind int16
+
+// Defined SymKind values.
+//
+// TODO(rsc): Give idiomatic Go names.
+//go:generate stringer -type=SymKind
+const (
+ Sxxx SymKind = iota
+ STEXT
+ SELFRXSECT
+
+ // Read-only sections.
+ STYPE
+ SSTRING
+ SGOSTRING
+ SGOFUNC
+ SGCBITS
+ SRODATA
+ SFUNCTAB
+
+ SELFROSECT
+ SMACHOPLT
+
+ // Read-only sections with relocations.
+ //
+ // Types STYPE-SFUNCTAB above are written to the .rodata section by default.
+ // When linking a shared object, some conceptually "read only" types need to
+ // be written to by relocations and putting them in a section called
+ // ".rodata" interacts poorly with the system linkers. The GNU linkers
+ // support this situation by arranging for sections of the name
+ // ".data.rel.ro.XXX" to be mprotected read only by the dynamic linker after
+ // relocations have applied, so when the Go linker is creating a shared
+ // object it checks all objects of the above types and bumps any object that
+ // has a relocation to it to the corresponding type below, which are then
+ // written to sections with appropriate magic names.
+ STYPERELRO
+ SSTRINGRELRO
+ SGOSTRINGRELRO
+ SGOFUNCRELRO
+ SGCBITSRELRO
+ SRODATARELRO
+ SFUNCTABRELRO
+
+ // Part of .data.rel.ro if it exists, otherwise part of .rodata.
+ STYPELINK
+ SITABLINK
+ SSYMTAB
+ SPCLNTAB
+
+ // Writable sections.
+ SELFSECT
+ SMACHO
+ SMACHOGOT
+ SWINDOWS
+ SELFGOT
+ SNOPTRDATA
+ SINITARR
+ SDATA
+ SBSS
+ SNOPTRBSS
+ STLSBSS
+ SXREF
+ SMACHOSYMSTR
+ SMACHOSYMTAB
+ SMACHOINDIRECTPLT
+ SMACHOINDIRECTGOT
+ SFILE
+ SFILEPATH
+ SCONST
+ SDYNIMPORT
+ SHOSTOBJ
+ SDWARFSECT
+ SDWARFINFO
+ SSUB = SymKind(1 << 8)
+ SMASK = SymKind(SSUB - 1)
+ SHIDDEN = SymKind(1 << 9)
+ SCONTAINER = SymKind(1 << 10) // has a sub-symbol
+)
+
+// abiSymKindToSymKind maps values read from object files (which are
+// of type cmd/internal/objabi.SymKind) to values of type SymKind.
+var abiSymKindToSymKind = [...]SymKind{
+ Sxxx,
+ STEXT,
+ SRODATA,
+ SNOPTRDATA,
+ SDATA,
+ SBSS,
+ SNOPTRBSS,
+ STLSBSS,
+ SXREF,
+ SCONST,
+ SDWARFINFO,
+}
+
+// ReadOnly are the symbol kinds that form read-only sections. In some
+// cases, if they will require relocations, they are transformed into
+// rel-ro sections using RelROMap.
+var ReadOnly = []SymKind{
+ STYPE,
+ SSTRING,
+ SGOSTRING,
+ SGOFUNC,
+ SGCBITS,
+ SRODATA,
+ SFUNCTAB,
+}
+
+// RelROMap describes the transformation of read-only symbols to rel-ro
+// symbols.
+var RelROMap = map[SymKind]SymKind{
+ STYPE: STYPERELRO,
+ SSTRING: SSTRINGRELRO,
+ SGOSTRING: SGOSTRINGRELRO,
+ SGOFUNC: SGOFUNCRELRO,
+ SGCBITS: SGCBITSRELRO,
+ SRODATA: SRODATARELRO,
+ SFUNCTAB: SFUNCTABRELRO,
+}
--- /dev/null
+// Code generated by "stringer -type=SymKind"; DO NOT EDIT.
+
+package ld
+
+import "fmt"
+
+const _SymKind_name = "SxxxSTEXTSELFRXSECTSTYPESSTRINGSGOSTRINGSGOFUNCSGCBITSSRODATASFUNCTABSELFROSECTSMACHOPLTSTYPERELROSSTRINGRELROSGOSTRINGRELROSGOFUNCRELROSGCBITSRELROSRODATARELROSFUNCTABRELROSTYPELINKSITABLINKSSYMTABSPCLNTABSELFSECTSMACHOSMACHOGOTSWINDOWSSELFGOTSNOPTRDATASINITARRSDATASBSSSNOPTRBSSSTLSBSSSXREFSMACHOSYMSTRSMACHOSYMTABSMACHOINDIRECTPLTSMACHOINDIRECTGOTSFILESFILEPATHSCONSTSDYNIMPORTSHOSTOBJSDWARFSECTSDWARFINFO"
+
+var _SymKind_index = [...]uint16{0, 4, 9, 19, 24, 31, 40, 47, 54, 61, 69, 79, 88, 98, 110, 124, 136, 148, 160, 173, 182, 191, 198, 206, 214, 220, 229, 237, 244, 254, 262, 267, 271, 280, 287, 292, 304, 316, 333, 350, 355, 364, 370, 380, 388, 398, 408}
+
+func (i SymKind) String() string {
+ if i < 0 || i >= SymKind(len(_SymKind_index)-1) {
+ return fmt.Sprintf("SymKind(%d)", i)
+ }
+ return _SymKind_name[_SymKind_index[i]:_SymKind_index[i+1]]
+}
}
var elfshnum int
- if xo.Type == objabi.SDYNIMPORT || xo.Type == objabi.SHOSTOBJ {
+ if xo.Type == SDYNIMPORT || xo.Type == SHOSTOBJ {
elfshnum = SHN_UNDEF
} else {
if xo.Sect == nil {
// maybe one day STB_WEAK.
bind := STB_GLOBAL
- if x.Version != 0 || (x.Type&objabi.SHIDDEN != 0) || x.Attr.Local() {
+ if x.Version != 0 || (x.Type&SHIDDEN != 0) || x.Attr.Local() {
bind = STB_LOCAL
}
addr -= int64(xo.Sect.Vaddr)
}
other := STV_DEFAULT
- if x.Type&objabi.SHIDDEN != 0 {
+ if x.Type&SHIDDEN != 0 {
other = STV_HIDDEN
}
if (Buildmode == BuildmodeCArchive || Buildmode == BuildmodePIE || ctxt.DynlinkingGo()) && SysArch.Family == sys.PPC64 && typ == STT_FUNC && x.Name != "runtime.duffzero" && x.Name != "runtime.duffcopy" {
s = strings.Replace(s, "·", ".", -1)
}
- if ctxt.DynlinkingGo() && bind == STB_GLOBAL && elfbind == STB_LOCAL && x.Type == objabi.STEXT {
+ if ctxt.DynlinkingGo() && bind == STB_GLOBAL && elfbind == STB_LOCAL && x.Type == STEXT {
// When dynamically linking, we want references to functions defined
// in this module to always be to the function object, not to the
// PLT. We force this by writing an additional local symbol for every
func textsectionmap(ctxt *Link) uint32 {
t := ctxt.Syms.Lookup("runtime.textsectionmap", 0)
- t.Type = objabi.SRODATA
+ t.Type = SRODATA
t.Attr |= AttrReachable
nsections := int64(0)
// Define these so that they'll get put into the symbol table.
// data.c:/^address will provide the actual values.
- ctxt.xdefine("runtime.text", objabi.STEXT, 0)
-
- ctxt.xdefine("runtime.etext", objabi.STEXT, 0)
- ctxt.xdefine("runtime.itablink", objabi.SRODATA, 0)
- ctxt.xdefine("runtime.eitablink", objabi.SRODATA, 0)
- ctxt.xdefine("runtime.rodata", objabi.SRODATA, 0)
- ctxt.xdefine("runtime.erodata", objabi.SRODATA, 0)
- ctxt.xdefine("runtime.types", objabi.SRODATA, 0)
- ctxt.xdefine("runtime.etypes", objabi.SRODATA, 0)
- ctxt.xdefine("runtime.noptrdata", objabi.SNOPTRDATA, 0)
- ctxt.xdefine("runtime.enoptrdata", objabi.SNOPTRDATA, 0)
- ctxt.xdefine("runtime.data", objabi.SDATA, 0)
- ctxt.xdefine("runtime.edata", objabi.SDATA, 0)
- ctxt.xdefine("runtime.bss", objabi.SBSS, 0)
- ctxt.xdefine("runtime.ebss", objabi.SBSS, 0)
- ctxt.xdefine("runtime.noptrbss", objabi.SNOPTRBSS, 0)
- ctxt.xdefine("runtime.enoptrbss", objabi.SNOPTRBSS, 0)
- ctxt.xdefine("runtime.end", objabi.SBSS, 0)
- ctxt.xdefine("runtime.epclntab", objabi.SRODATA, 0)
- ctxt.xdefine("runtime.esymtab", objabi.SRODATA, 0)
+ ctxt.xdefine("runtime.text", STEXT, 0)
+
+ ctxt.xdefine("runtime.etext", STEXT, 0)
+ ctxt.xdefine("runtime.itablink", SRODATA, 0)
+ ctxt.xdefine("runtime.eitablink", SRODATA, 0)
+ ctxt.xdefine("runtime.rodata", SRODATA, 0)
+ ctxt.xdefine("runtime.erodata", SRODATA, 0)
+ ctxt.xdefine("runtime.types", SRODATA, 0)
+ ctxt.xdefine("runtime.etypes", SRODATA, 0)
+ ctxt.xdefine("runtime.noptrdata", SNOPTRDATA, 0)
+ ctxt.xdefine("runtime.enoptrdata", SNOPTRDATA, 0)
+ ctxt.xdefine("runtime.data", SDATA, 0)
+ ctxt.xdefine("runtime.edata", SDATA, 0)
+ ctxt.xdefine("runtime.bss", SBSS, 0)
+ ctxt.xdefine("runtime.ebss", SBSS, 0)
+ ctxt.xdefine("runtime.noptrbss", SNOPTRBSS, 0)
+ ctxt.xdefine("runtime.enoptrbss", SNOPTRBSS, 0)
+ ctxt.xdefine("runtime.end", SBSS, 0)
+ ctxt.xdefine("runtime.epclntab", SRODATA, 0)
+ ctxt.xdefine("runtime.esymtab", SRODATA, 0)
// garbage collection symbols
s := ctxt.Syms.Lookup("runtime.gcdata", 0)
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Size = 0
s.Attr |= AttrReachable
- ctxt.xdefine("runtime.egcdata", objabi.SRODATA, 0)
+ ctxt.xdefine("runtime.egcdata", SRODATA, 0)
s = ctxt.Syms.Lookup("runtime.gcbss", 0)
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Size = 0
s.Attr |= AttrReachable
- ctxt.xdefine("runtime.egcbss", objabi.SRODATA, 0)
+ ctxt.xdefine("runtime.egcbss", SRODATA, 0)
// pseudo-symbols to mark locations of type, string, and go string data.
var symtype *Symbol
if UseRelro() && (Buildmode == BuildmodeCArchive || Buildmode == BuildmodeCShared || Buildmode == BuildmodePIE) {
s = ctxt.Syms.Lookup("type.*", 0)
- s.Type = objabi.STYPE
+ s.Type = STYPE
s.Size = 0
s.Attr |= AttrReachable
symtype = s
s = ctxt.Syms.Lookup("typerel.*", 0)
- s.Type = objabi.STYPERELRO
+ s.Type = STYPERELRO
s.Size = 0
s.Attr |= AttrReachable
symtyperel = s
} else if !ctxt.DynlinkingGo() {
s = ctxt.Syms.Lookup("type.*", 0)
- s.Type = objabi.STYPE
+ s.Type = STYPE
s.Size = 0
s.Attr |= AttrReachable
symtype = s
symtyperel = s
}
- groupSym := func(name string, t objabi.SymKind) *Symbol {
+ groupSym := func(name string, t SymKind) *Symbol {
s := ctxt.Syms.Lookup(name, 0)
s.Type = t
s.Size = 0
return s
}
var (
- symgostring = groupSym("go.string.*", objabi.SGOSTRING)
- symgofunc = groupSym("go.func.*", objabi.SGOFUNC)
- symgcbits = groupSym("runtime.gcbits.*", objabi.SGCBITS)
+ symgostring = groupSym("go.string.*", SGOSTRING)
+ symgofunc = groupSym("go.func.*", SGOFUNC)
+ symgcbits = groupSym("runtime.gcbits.*", SGCBITS)
)
var symgofuncrel *Symbol
if !ctxt.DynlinkingGo() {
if UseRelro() {
- symgofuncrel = groupSym("go.funcrel.*", objabi.SGOFUNCRELRO)
+ symgofuncrel = groupSym("go.funcrel.*", SGOFUNCRELRO)
} else {
symgofuncrel = symgofunc
}
}
symitablink := ctxt.Syms.Lookup("runtime.itablink", 0)
- symitablink.Type = objabi.SITABLINK
+ symitablink.Type = SITABLINK
symt = ctxt.Syms.Lookup("runtime.symtab", 0)
symt.Attr |= AttrLocal
- symt.Type = objabi.SSYMTAB
+ symt.Type = SSYMTAB
symt.Size = 0
symt.Attr |= AttrReachable
// just defined above will be first.
// hide the specific symbols.
for _, s := range ctxt.Syms.Allsym {
- if !s.Attr.Reachable() || s.Attr.Special() || s.Type != objabi.SRODATA {
+ if !s.Attr.Reachable() || s.Attr.Special() || s.Type != SRODATA {
continue
}
s.Attr |= AttrHidden
}
if UseRelro() {
- s.Type = objabi.STYPERELRO
+ s.Type = STYPERELRO
s.Outer = symtyperel
} else {
- s.Type = objabi.STYPE
+ s.Type = STYPE
s.Outer = symtype
}
case strings.HasPrefix(s.Name, "go.importpath.") && UseRelro():
// Keep go.importpath symbols in the same section as types and
// names, as they can be referred to by a section offset.
- s.Type = objabi.STYPERELRO
+ s.Type = STYPERELRO
case strings.HasPrefix(s.Name, "go.itablink."):
nitablinks++
- s.Type = objabi.SITABLINK
+ s.Type = SITABLINK
s.Attr |= AttrHidden
s.Outer = symitablink
case strings.HasPrefix(s.Name, "go.string."):
- s.Type = objabi.SGOSTRING
+ s.Type = SGOSTRING
s.Attr |= AttrHidden
s.Outer = symgostring
case strings.HasPrefix(s.Name, "runtime.gcbits."):
- s.Type = objabi.SGCBITS
+ s.Type = SGCBITS
s.Attr |= AttrHidden
s.Outer = symgcbits
s.Attr |= AttrHidden
}
if UseRelro() {
- s.Type = objabi.SGOFUNCRELRO
+ s.Type = SGOFUNCRELRO
s.Outer = symgofuncrel
} else {
- s.Type = objabi.SGOFUNC
+ s.Type = SGOFUNC
s.Outer = symgofunc
}
strings.HasPrefix(s.Name, "gclocals."),
strings.HasPrefix(s.Name, "gclocals·"),
strings.HasPrefix(s.Name, "inltree."):
- s.Type = objabi.SGOFUNC
+ s.Type = SGOFUNC
s.Attr |= AttrHidden
s.Outer = symgofunc
s.Align = 4
if Buildmode == BuildmodeShared {
abihashgostr := ctxt.Syms.Lookup("go.link.abihash."+filepath.Base(*flagOutfile), 0)
abihashgostr.Attr |= AttrReachable
- abihashgostr.Type = objabi.SRODATA
+ abihashgostr.Type = SRODATA
hashsym := ctxt.Syms.Lookup("go.link.abihashbytes", 0)
Addaddr(ctxt, abihashgostr, hashsym)
adduint(ctxt, abihashgostr, uint64(hashsym.Size))
for _, l := range ctxt.Library {
s := ctxt.Syms.Lookup("go.link.pkghashbytes."+l.Pkg, 0)
s.Attr |= AttrReachable
- s.Type = objabi.SRODATA
+ s.Type = SRODATA
s.Size = int64(len(l.hash))
s.P = []byte(l.hash)
str := ctxt.Syms.Lookup("go.link.pkghash."+l.Pkg, 0)
str.Attr |= AttrReachable
- str.Type = objabi.SRODATA
+ str.Type = SRODATA
Addaddr(ctxt, str, s)
adduint(ctxt, str, uint64(len(l.hash)))
}
// The ptab slice
if ptab := ctxt.Syms.ROLookup("go.plugin.tabs", 0); ptab != nil && ptab.Attr.Reachable() {
ptab.Attr |= AttrLocal
- ptab.Type = objabi.SRODATA
+ ptab.Type = SRODATA
nentries := uint64(len(ptab.P) / 8) // sizeof(nameOff) + sizeof(typeOff)
Addaddr(ctxt, moduledata, ptab)
pkghashes := ctxt.Syms.Lookup("go.link.pkghashes", 0)
pkghashes.Attr |= AttrReachable
pkghashes.Attr |= AttrLocal
- pkghashes.Type = objabi.SRODATA
+ pkghashes.Type = SRODATA
for i, l := range ctxt.Library {
// pkghashes[i].name
modulehashes := ctxt.Syms.Lookup("go.link.abihashes", 0)
modulehashes.Attr |= AttrReachable
modulehashes.Attr |= AttrLocal
- modulehashes.Type = objabi.SRODATA
+ modulehashes.Type = SRODATA
for i, shlib := range ctxt.Shlibs {
// modulehashes[i].modulename
Symgrow(moduledata, moduledata.Size)
lastmoduledatap := ctxt.Syms.Lookup("runtime.lastmoduledatap", 0)
- if lastmoduledatap.Type != objabi.SDYNIMPORT {
- lastmoduledatap.Type = objabi.SNOPTRDATA
+ if lastmoduledatap.Type != SDYNIMPORT {
+ lastmoduledatap.Type = SNOPTRDATA
lastmoduledatap.Size = 0 // overwrite existing value
Addaddr(ctxt, lastmoduledatap, moduledata)
}
sort.Sort(typelinks)
tl := ctxt.Syms.Lookup("runtime.typelink", 0)
- tl.Type = objabi.STYPELINK
+ tl.Type = STYPELINK
tl.Attr |= AttrReachable | AttrLocal
tl.Size = int64(4 * len(typelinks))
tl.P = make([]byte, tl.Size)
rs = rs.Outer
}
- if rs.Type != objabi.SHOSTOBJ && rs.Type != objabi.SDYNIMPORT && rs.Sect == nil {
+ if rs.Type != ld.SHOSTOBJ && rs.Type != ld.SDYNIMPORT && rs.Sect == nil {
ld.Errorf(s, "missing section for %s", rs.Name)
}
r.Xsym = rs
rs = rs.Outer
}
- if rs.Type != objabi.SHOSTOBJ && rs.Type != objabi.SDYNIMPORT && rs.Sect == nil {
+ if rs.Type != ld.SHOSTOBJ && rs.Type != ld.SDYNIMPORT && rs.Sect == nil {
ld.Errorf(s, "missing section for %s", rs.Name)
}
r.Xsym = rs
for _, s := range ctxt.Textp {
for i := range s.R {
r := &s.R[i]
- if r.Type != 256+ld.R_PPC64_REL24 || r.Sym.Type != objabi.SDYNIMPORT {
+ if r.Type != 256+ld.R_PPC64_REL24 || r.Sym.Type != ld.SDYNIMPORT {
continue
}
func genaddmoduledata(ctxt *ld.Link) {
addmoduledata := ctxt.Syms.ROLookup("runtime.addmoduledata", 0)
- if addmoduledata.Type == objabi.STEXT {
+ if addmoduledata.Type == ld.STEXT {
return
}
addmoduledata.Attr |= ld.AttrReachable
initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0)
- initfunc.Type = objabi.STEXT
+ initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
o := func(op uint32) {
ctxt.Textp = append(ctxt.Textp, initfunc)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
- initarray_entry.Type = objabi.SINITARR
+ initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc)
}
plt := ctxt.Syms.Lookup(".plt", 0)
- stub.Type = objabi.STEXT
+ stub.Type = ld.STEXT
// Save TOC pointer in TOC save slot
ld.Adduint32(ctxt, stub, 0xf8410018) // std r2,24(r1)
// to use r12 to compute r2.)
r.Add += int64(r.Sym.Localentry) * 4
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
// Should have been handled in elfsetupplt
ld.Errorf(s, "unexpected R_PPC64_REL24 for dyn import")
}
r.Type = objabi.R_PCREL
r.Add += 4
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_PPC_REL32 for dyn import")
}
case 256 + ld.R_PPC64_ADDR64:
r.Type = objabi.R_ADDR
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
// These happen in .toc sections
ld.Adddynsym(ctxt, targ)
}
// Handle references to ELF symbols from our own object files.
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
return true
}
rs = rs.Outer
}
- if rs.Type != objabi.SHOSTOBJ && rs.Type != objabi.SDYNIMPORT && rs.Sect == nil {
+ if rs.Type != ld.SHOSTOBJ && rs.Type != ld.SDYNIMPORT && rs.Sect == nil {
ld.Errorf(s, "missing section for %s", rs.Name)
}
r.Xsym = rs
return
}
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0)
- if addmoduledata.Type == objabi.STEXT && ld.Buildmode != ld.BuildmodePlugin {
+ if addmoduledata.Type == ld.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 = objabi.STEXT
+ initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Attr |= ld.AttrReachable
- initarray_entry.Type = objabi.SINITARR
+ initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc)
}
256 + ld.R_390_16,
256 + ld.R_390_32,
256 + ld.R_390_64:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_390_nn relocation for dynamic symbol %s", targ.Name)
}
r.Type = objabi.R_ADDR
case 256 + ld.R_390_PC16,
256 + ld.R_390_PC32,
256 + ld.R_390_PC64:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_390_PCnn relocation for dynamic symbol %s", targ.Name)
}
- if targ.Type == 0 || targ.Type == objabi.SXREF {
+ if targ.Type == 0 || targ.Type == ld.SXREF {
ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
}
r.Type = objabi.R_PCREL
r.Type = objabi.R_PCREL
r.Variant = ld.RV_390_DBL
r.Add += int64(r.Siz)
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add += int64(targ.Plt)
256 + ld.R_390_PLT64:
r.Type = objabi.R_PCREL
r.Add += int64(r.Siz)
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add += int64(targ.Plt)
return false
case 256 + ld.R_390_GOTOFF:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_390_GOTOFF relocation for dynamic symbol %s", targ.Name)
}
r.Type = objabi.R_GOTOFF
r.Type = objabi.R_PCREL
r.Variant = ld.RV_390_DBL
r.Add += int64(r.Siz)
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_390_PCnnDBL relocation for dynamic symbol %s", targ.Name)
}
return true
return true
}
// Handle references to ELF symbols from our own object files.
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
return true
}
case objabi.R_PCRELDBL, objabi.R_CALL:
isdbl = true
}
- if r.Xsym.Type == objabi.SDYNIMPORT && (r.Xsym.ElfType == elf.STT_FUNC || r.Type == objabi.R_CALL) {
+ if r.Xsym.Type == ld.SDYNIMPORT && (r.Xsym.ElfType == elf.STT_FUNC || r.Type == objabi.R_CALL) {
if isdbl {
switch r.Siz {
case 2:
{"di", 7},
} {
thunkfunc := ctxt.Syms.Lookup("__x86.get_pc_thunk."+r.name, 0)
- thunkfunc.Type = objabi.STEXT
+ thunkfunc.Type = ld.STEXT
thunkfunc.Attr |= ld.AttrLocal
thunkfunc.Attr |= ld.AttrReachable //TODO: remove?
o := func(op ...uint8) {
ctxt.Textp = append(thunks, ctxt.Textp...) // keep Textp in dependency order
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0)
- if addmoduledata.Type == objabi.STEXT && ld.Buildmode != ld.BuildmodePlugin {
+ if addmoduledata.Type == ld.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 = objabi.STEXT
+ initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable
o := func(op ...uint8) {
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal
- initarray_entry.Type = objabi.SINITARR
+ initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc)
}
// Handle relocations found in ELF object files.
case 256 + ld.R_386_PC32:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_386_PC32 relocation for dynamic symbol %s", targ.Name)
}
- if targ.Type == 0 || targ.Type == objabi.SXREF {
+ if targ.Type == 0 || targ.Type == ld.SXREF {
ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
}
r.Type = objabi.R_PCREL
case 256 + ld.R_386_PLT32:
r.Type = objabi.R_PCREL
r.Add += 4
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add += int64(targ.Plt)
return true
case 256 + ld.R_386_GOT32, 256 + ld.R_386_GOT32X:
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
// have symbol
if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
// turn MOVL of GOT entry into LEAL of symbol address, relative to GOT.
return true
case 256 + ld.R_386_32:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_386_32 relocation for dynamic symbol %s", targ.Name)
}
r.Type = objabi.R_ADDR
case 512 + ld.MACHO_GENERIC_RELOC_VANILLA*2 + 0:
r.Type = objabi.R_ADDR
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected reloc for dynamic symbol %s", targ.Name)
}
return true
case 512 + ld.MACHO_GENERIC_RELOC_VANILLA*2 + 1:
- if targ.Type == objabi.SDYNIMPORT {
+ if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(targ.Plt)
return true
case 512 + ld.MACHO_FAKE_GOTPCREL:
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
// have symbol
// turn MOVL of GOT entry into LEAL of symbol itself
if r.Off < 2 || s.P[r.Off-2] != 0x8b {
}
// Handle references to ELF symbols from our own object files.
- if targ.Type != objabi.SDYNIMPORT {
+ if targ.Type != ld.SDYNIMPORT {
return true
}
switch r.Type {
return true
case objabi.R_ADDR:
- if s.Type != objabi.SDATA {
+ if s.Type != ld.SDATA {
break
}
if ld.Iself {
ld.Adddynsym(ctxt, targ)
got := ctxt.Syms.Lookup(".got", 0)
- s.Type = got.Type | objabi.SSUB
+ s.Type = got.Type | ld.SSUB
s.Outer = got
s.Sub = got.Sub
got.Sub = s
case objabi.R_CALL:
if r.Siz == 4 {
- if r.Xsym.Type == objabi.SDYNIMPORT {
+ if r.Xsym.Type == ld.SDYNIMPORT {
ld.Thearch.Lput(ld.R_386_PLT32 | uint32(elfsym)<<8)
} else {
ld.Thearch.Lput(ld.R_386_PC32 | uint32(elfsym)<<8)
rs := r.Xsym
- if rs.Type == objabi.SHOSTOBJ {
+ if rs.Type == ld.SHOSTOBJ {
if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1