Commit be2ee2a4 authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle

cmd/internal/objabi, cmd/link: move linker-only symkind values into linker

Many (most!) of the values of objapi.SymKind are used only in the linker, so
this creates a separate cmd/link/internal/ld.SymKind type, removes most values
from SymKind and maps one to the other when reading object files in the linker.

Two of the remaining objapi.SymKind values are only checked for, never set and
so will never be actually found but I wanted to keep this to the most
mechanical change possible.

Change-Id: I4bbc5aed6713cab3e8de732e6e288eb77be0474c
Reviewed-on: https://go-review.googlesource.com/40985
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent b1868cf1
...@@ -36,102 +36,28 @@ type SymKind int16 ...@@ -36,102 +36,28 @@ type SymKind int16
// Defined SymKind values. // Defined SymKind values.
// //
// TODO(rsc): Give idiomatic Go names. // TODO(rsc): Give idiomatic Go names.
// TODO(rsc): Reduce the number of symbol types in the object files.
//go:generate stringer -type=SymKind //go:generate stringer -type=SymKind
const ( const (
// An otherwise invalid zero value for the type
Sxxx SymKind = iota Sxxx SymKind = iota
// Executable instructions
STEXT STEXT
SELFRXSECT // Read only static data
// Read-only sections.
STYPE
SSTRING
SGOSTRING
SGOFUNC
SGCBITS
SRODATA SRODATA
SFUNCTAB // Static data that does not contain any pointers
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 SNOPTRDATA
SINITARR // Static data
SDATA SDATA
// Statically data that is initially all 0s
SBSS SBSS
// Statically data that is initially all 0s and does not contain pointers
SNOPTRBSS SNOPTRBSS
// Thread-local data that is initally all 0s
STLSBSS STLSBSS
// TODO(mwhudson): outside of the linker, these values are
// only checked for, not set, so they should be removed.
SXREF SXREF
SMACHOSYMSTR
SMACHOSYMTAB
SMACHOINDIRECTPLT
SMACHOINDIRECTGOT
SFILE
SFILEPATH
SCONST SCONST
SDYNIMPORT // Debugging data
SHOSTOBJ
SDWARFSECT
SDWARFINFO 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,
}
...@@ -4,9 +4,9 @@ package objabi ...@@ -4,9 +4,9 @@ package objabi
import "fmt" 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 { func (i SymKind) String() string {
if i < 0 || i >= SymKind(len(_SymKind_index)-1) { if i < 0 || i >= SymKind(len(_SymKind_index)-1) {
......
...@@ -45,15 +45,15 @@ func (f *goobjFile) symbols() ([]Sym, error) { ...@@ -45,15 +45,15 @@ func (f *goobjFile) symbols() ([]Sym, error) {
seen[s.SymID] = true seen[s.SymID] = true
sym := Sym{Addr: uint64(s.Data.Offset), Name: goobjName(s.SymID), Size: int64(s.Size), Type: s.Type.Name, Code: '?'} sym := Sym{Addr: uint64(s.Data.Offset), Name: goobjName(s.SymID), Size: int64(s.Size), Type: s.Type.Name, Code: '?'}
switch s.Kind { switch s.Kind {
case objabi.STEXT, objabi.SELFRXSECT: case objabi.STEXT:
sym.Code = 'T' 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' 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' sym.Code = 'D'
case objabi.SBSS, objabi.SNOPTRBSS, objabi.STLSBSS: case objabi.SBSS, objabi.SNOPTRBSS, objabi.STLSBSS:
sym.Code = 'B' 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 sym.Code = 'X' // should not see
} }
if s.Version != 0 { if s.Version != 0 {
......
...@@ -59,14 +59,14 @@ func gentext(ctxt *ld.Link) { ...@@ -59,14 +59,14 @@ func gentext(ctxt *ld.Link) {
return return
} }
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0) 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 // we're linking a module containing the runtime -> no need for
// an init function // an init function
return return
} }
addmoduledata.Attr |= ld.AttrReachable addmoduledata.Attr |= ld.AttrReachable
initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0) initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0)
initfunc.Type = objabi.STEXT initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable initfunc.Attr |= ld.AttrReachable
o := func(op ...uint8) { o := func(op ...uint8) {
...@@ -92,7 +92,7 @@ func gentext(ctxt *ld.Link) { ...@@ -92,7 +92,7 @@ func gentext(ctxt *ld.Link) {
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0) initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Type = objabi.SINITARR initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc) ld.Addaddr(ctxt, initarray_entry, initfunc)
} }
...@@ -108,10 +108,10 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -108,10 +108,10 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
// Handle relocations found in ELF object files. // Handle relocations found in ELF object files.
case 256 + ld.R_X86_64_PC32: 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) 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) ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
} }
r.Type = objabi.R_PCREL r.Type = objabi.R_PCREL
...@@ -121,7 +121,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -121,7 +121,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_X86_64_PLT32: case 256 + ld.R_X86_64_PLT32:
r.Type = objabi.R_PCREL r.Type = objabi.R_PCREL
r.Add += 4 r.Add += 4
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add += int64(targ.Plt) r.Add += int64(targ.Plt)
...@@ -130,7 +130,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -130,7 +130,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case 256 + ld.R_X86_64_GOTPCREL, 256 + ld.R_X86_64_GOTPCRELX, 256 + ld.R_X86_64_REX_GOTPCRELX: 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 // have symbol
if r.Off >= 2 && s.P[r.Off-2] == 0x8b { if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
// turn MOVQ of GOT entry into LEAQ of symbol itself // turn MOVQ of GOT entry into LEAQ of symbol itself
...@@ -153,7 +153,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -153,7 +153,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case 256 + ld.R_X86_64_64: 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) ld.Errorf(s, "unexpected R_X86_64_64 relocation for dynamic symbol %s", targ.Name)
} }
r.Type = objabi.R_ADDR r.Type = objabi.R_ADDR
...@@ -166,13 +166,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -166,13 +166,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
// TODO: What is the difference between all these? // TODO: What is the difference between all these?
r.Type = objabi.R_ADDR 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) ld.Errorf(s, "unexpected reloc for dynamic symbol %s", targ.Name)
} }
return true return true
case 512 + ld.MACHO_X86_64_RELOC_BRANCH*2 + 1: case 512 + ld.MACHO_X86_64_RELOC_BRANCH*2 + 1:
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(targ.Plt) r.Add = int64(targ.Plt)
...@@ -189,13 +189,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -189,13 +189,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
512 + ld.MACHO_X86_64_RELOC_SIGNED_4*2 + 1: 512 + ld.MACHO_X86_64_RELOC_SIGNED_4*2 + 1:
r.Type = objabi.R_PCREL 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) ld.Errorf(s, "unexpected pc-relative reloc for dynamic symbol %s", targ.Name)
} }
return true return true
case 512 + ld.MACHO_X86_64_RELOC_GOT_LOAD*2 + 1: case 512 + ld.MACHO_X86_64_RELOC_GOT_LOAD*2 + 1:
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
// have symbol // have symbol
// turn MOVQ of GOT entry into LEAQ of symbol itself // turn MOVQ of GOT entry into LEAQ of symbol itself
if r.Off < 2 || s.P[r.Off-2] != 0x8b { if r.Off < 2 || s.P[r.Off-2] != 0x8b {
...@@ -211,7 +211,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -211,7 +211,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
// fall through // fall through
case 512 + ld.MACHO_X86_64_RELOC_GOT*2 + 1: 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) ld.Errorf(s, "unexpected GOT reloc for non-dynamic symbol %s", targ.Name)
} }
addgotsym(ctxt, targ) addgotsym(ctxt, targ)
...@@ -224,7 +224,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -224,7 +224,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
switch r.Type { switch r.Type {
case objabi.R_CALL, case objabi.R_CALL,
objabi.R_PCREL: objabi.R_PCREL:
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
// nothing to do, the relocation will be laid out in reloc // nothing to do, the relocation will be laid out in reloc
return true return true
} }
...@@ -240,7 +240,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -240,7 +240,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
} }
case objabi.R_ADDR: case objabi.R_ADDR:
if s.Type == objabi.STEXT && ld.Iself { if s.Type == ld.STEXT && ld.Iself {
if ld.Headtype == objabi.Hsolaris { if ld.Headtype == objabi.Hsolaris {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
...@@ -294,7 +294,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -294,7 +294,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
// linking, in which case the relocation will be // linking, in which case the relocation will be
// prepared in the 'reloc' phase and passed to the // prepared in the 'reloc' phase and passed to the
// external linker in the 'asmb' phase. // 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 break
} }
} }
...@@ -331,7 +331,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -331,7 +331,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
ld.Adddynsym(ctxt, targ) ld.Adddynsym(ctxt, targ)
got := ctxt.Syms.Lookup(".got", 0) got := ctxt.Syms.Lookup(".got", 0)
s.Type = got.Type | objabi.SSUB s.Type = got.Type | ld.SSUB
s.Outer = got s.Outer = got
s.Sub = got.Sub s.Sub = got.Sub
got.Sub = s got.Sub = s
...@@ -384,7 +384,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -384,7 +384,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
case objabi.R_CALL: case objabi.R_CALL:
if r.Siz == 4 { if r.Siz == 4 {
if r.Xsym.Type == objabi.SDYNIMPORT { if r.Xsym.Type == ld.SDYNIMPORT {
if ctxt.DynlinkingGo() { if ctxt.DynlinkingGo() {
ld.Thearch.Vput(ld.R_X86_64_PLT32 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_X86_64_PLT32 | uint64(elfsym)<<32)
} else { } else {
...@@ -399,7 +399,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -399,7 +399,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
case objabi.R_PCREL: case objabi.R_PCREL:
if r.Siz == 4 { 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) ld.Thearch.Vput(ld.R_X86_64_PLT32 | uint64(elfsym)<<32)
} else { } else {
ld.Thearch.Vput(ld.R_X86_64_PC32 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_X86_64_PC32 | uint64(elfsym)<<32)
...@@ -425,7 +425,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -425,7 +425,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
rs := r.Xsym 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 { if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
......
...@@ -63,14 +63,14 @@ func gentext(ctxt *ld.Link) { ...@@ -63,14 +63,14 @@ func gentext(ctxt *ld.Link) {
return return
} }
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0) 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 // we're linking a module containing the runtime -> no need for
// an init function // an init function
return return
} }
addmoduledata.Attr |= ld.AttrReachable addmoduledata.Attr |= ld.AttrReachable
initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0) initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0)
initfunc.Type = objabi.STEXT initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable initfunc.Attr |= ld.AttrReachable
o := func(op uint32) { o := func(op uint32) {
...@@ -102,7 +102,7 @@ func gentext(ctxt *ld.Link) { ...@@ -102,7 +102,7 @@ func gentext(ctxt *ld.Link) {
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0) initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Type = objabi.SINITARR initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc) ld.Addaddr(ctxt, initarray_entry, initfunc)
} }
...@@ -126,7 +126,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -126,7 +126,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_ARM_PLT32: case 256 + ld.R_ARM_PLT32:
r.Type = objabi.R_CALLARM r.Type = objabi.R_CALLARM
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(braddoff(int32(r.Add), targ.Plt/4)) r.Add = int64(braddoff(int32(r.Add), targ.Plt/4))
...@@ -139,7 +139,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -139,7 +139,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
case 256 + ld.R_ARM_GOT32: // R_ARM_GOT_BREL case 256 + ld.R_ARM_GOT32: // R_ARM_GOT_BREL
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
addgotsyminternal(ctxt, targ) addgotsyminternal(ctxt, targ)
} else { } else {
addgotsym(ctxt, targ) addgotsym(ctxt, targ)
...@@ -151,7 +151,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -151,7 +151,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case 256 + ld.R_ARM_GOT_PREL: // GOT(nil) + A - nil case 256 + ld.R_ARM_GOT_PREL: // GOT(nil) + A - nil
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
addgotsyminternal(ctxt, targ) addgotsyminternal(ctxt, targ)
} else { } else {
addgotsym(ctxt, targ) addgotsym(ctxt, targ)
...@@ -176,7 +176,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -176,7 +176,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_ARM_CALL: case 256 + ld.R_ARM_CALL:
r.Type = objabi.R_CALLARM r.Type = objabi.R_CALLARM
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(braddoff(int32(r.Add), targ.Plt/4)) r.Add = int64(braddoff(int32(r.Add), targ.Plt/4))
...@@ -191,7 +191,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -191,7 +191,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case 256 + ld.R_ARM_ABS32: 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) ld.Errorf(s, "unexpected R_ARM_ABS32 relocation for dynamic symbol %s", targ.Name)
} }
r.Type = objabi.R_ADDR r.Type = objabi.R_ADDR
...@@ -210,7 +210,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -210,7 +210,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_ARM_PC24, case 256 + ld.R_ARM_PC24,
256 + ld.R_ARM_JUMP24: 256 + ld.R_ARM_JUMP24:
r.Type = objabi.R_CALLARM r.Type = objabi.R_CALLARM
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(braddoff(int32(r.Add), targ.Plt/4)) r.Add = int64(braddoff(int32(r.Add), targ.Plt/4))
...@@ -220,7 +220,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -220,7 +220,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
} }
// Handle references to ELF symbols from our own object files. // Handle references to ELF symbols from our own object files.
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
return true return true
} }
...@@ -232,7 +232,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -232,7 +232,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case objabi.R_ADDR: case objabi.R_ADDR:
if s.Type != objabi.SDATA { if s.Type != ld.SDATA {
break break
} }
if ld.Iself { if ld.Iself {
...@@ -332,7 +332,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -332,7 +332,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
rs := r.Xsym rs := r.Xsym
if r.Type == objabi.R_PCREL { 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") ld.Errorf(s, "pc-relative relocation of external symbol is not supported")
return -1 return -1
} }
...@@ -361,7 +361,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -361,7 +361,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
return 0 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 { if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
...@@ -443,7 +443,7 @@ func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) { ...@@ -443,7 +443,7 @@ func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) {
for i := 0; ; i++ { for i := 0; ; i++ {
name := r.Sym.Name + fmt.Sprintf("%+d-tramp%d", offset, i) name := r.Sym.Name + fmt.Sprintf("%+d-tramp%d", offset, i)
tramp = ctxt.Syms.Lookup(name, int(r.Sym.Version)) 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 // don't reuse trampoline defined in other module
continue continue
} }
...@@ -584,7 +584,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -584,7 +584,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
rs = rs.Outer 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) ld.Errorf(s, "missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
......
...@@ -43,14 +43,14 @@ func gentext(ctxt *ld.Link) { ...@@ -43,14 +43,14 @@ func gentext(ctxt *ld.Link) {
return return
} }
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0) 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 // we're linking a module containing the runtime -> no need for
// an init function // an init function
return return
} }
addmoduledata.Attr |= ld.AttrReachable addmoduledata.Attr |= ld.AttrReachable
initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0) initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0)
initfunc.Type = objabi.STEXT initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable initfunc.Attr |= ld.AttrReachable
o := func(op uint32) { o := func(op uint32) {
...@@ -82,7 +82,7 @@ func gentext(ctxt *ld.Link) { ...@@ -82,7 +82,7 @@ func gentext(ctxt *ld.Link) {
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0) initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Type = objabi.SINITARR initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc) ld.Addaddr(ctxt, initarray_entry, initfunc)
} }
...@@ -156,7 +156,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -156,7 +156,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
// ld64 has a bug handling MACHO_ARM64_RELOC_UNSIGNED with !extern relocation. // 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 // see cmd/internal/ld/data.go for details. The workaround is that don't use !extern
// UNSIGNED relocation at all. // 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 { if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
...@@ -250,7 +250,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -250,7 +250,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
// (https://sourceware.org/bugzilla/show_bug.cgi?id=18270). So // (https://sourceware.org/bugzilla/show_bug.cgi?id=18270). So
// we convert the adrp; ld64 + R_ARM64_GOTPCREL into adrp; // we convert the adrp; ld64 + R_ARM64_GOTPCREL into adrp;
// add + R_ADDRARM64. // 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 { if o2&0xffc00000 != 0xf9400000 {
ld.Errorf(s, "R_ARM64_GOTPCREL against unexpected instruction %x", o2) ld.Errorf(s, "R_ARM64_GOTPCREL against unexpected instruction %x", o2)
} }
...@@ -275,7 +275,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -275,7 +275,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
rs = rs.Outer 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) ld.Errorf(s, "missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
......
...@@ -101,7 +101,7 @@ func hostArchive(ctxt *Link, name string) { ...@@ -101,7 +101,7 @@ func hostArchive(ctxt *Link, name string) {
var load []uint64 var load []uint64
for _, s := range ctxt.Syms.Allsym { for _, s := range ctxt.Syms.Allsym {
for _, r := range s.R { 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] { if off := armap[r.Sym.Name]; off != 0 && !loaded[off] {
load = append(load, off) load = append(load, off)
loaded[off] = true loaded[off] = true
......
This diff is collapsed.
...@@ -208,7 +208,7 @@ func (d *deadcodepass) init() { ...@@ -208,7 +208,7 @@ func (d *deadcodepass) init() {
// Mark all symbols defined in this library as reachable when // Mark all symbols defined in this library as reachable when
// building a shared library. // building a shared library.
for _, s := range d.ctxt.Syms.Allsym { 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) d.mark(s, nil)
} }
} }
...@@ -246,7 +246,7 @@ func (d *deadcodepass) flood() { ...@@ -246,7 +246,7 @@ func (d *deadcodepass) flood() {
for len(d.markQueue) > 0 { for len(d.markQueue) > 0 {
s := d.markQueue[0] s := d.markQueue[0]
d.markQueue = d.markQueue[1:] d.markQueue = d.markQueue[1:]
if s.Type == objabi.STEXT { if s.Type == STEXT {
if d.ctxt.Debugvlog > 1 { if d.ctxt.Debugvlog > 1 {
d.ctxt.Logf("marktext %s\n", s.Name) d.ctxt.Logf("marktext %s\n", s.Name)
} }
......
...@@ -104,7 +104,7 @@ func findShlibSection(ctxt *Link, path string, addr uint64) *elf.Section { ...@@ -104,7 +104,7 @@ func findShlibSection(ctxt *Link, path string, addr uint64) *elf.Section {
// Type.commonType.gc // Type.commonType.gc
func decodetypeGcprog(ctxt *Link, s *Symbol) []byte { func decodetypeGcprog(ctxt *Link, s *Symbol) []byte {
if s.Type == objabi.SDYNIMPORT { if s.Type == SDYNIMPORT {
addr := decodetypeGcprogShlib(ctxt, s) addr := decodetypeGcprogShlib(ctxt, s)
sect := findShlibSection(ctxt, s.File, addr) sect := findShlibSection(ctxt, s.File, addr)
if sect != nil { if sect != nil {
...@@ -135,7 +135,7 @@ func decodetypeGcprogShlib(ctxt *Link, s *Symbol) uint64 { ...@@ -135,7 +135,7 @@ func decodetypeGcprogShlib(ctxt *Link, s *Symbol) uint64 {
} }
func decodetypeGcmask(ctxt *Link, s *Symbol) []byte { func decodetypeGcmask(ctxt *Link, s *Symbol) []byte {
if s.Type == objabi.SDYNIMPORT { if s.Type == SDYNIMPORT {
addr := decodetypeGcprogShlib(ctxt, s) addr := decodetypeGcprogShlib(ctxt, s)
ptrdata := decodetypePtrdata(ctxt.Arch, s) ptrdata := decodetypePtrdata(ctxt.Arch, s)
sect := findShlibSection(ctxt, s.File, addr) sect := findShlibSection(ctxt, s.File, addr)
......
...@@ -83,7 +83,7 @@ var dwarfp []*Symbol ...@@ -83,7 +83,7 @@ var dwarfp []*Symbol
func writeabbrev(ctxt *Link, syms []*Symbol) []*Symbol { func writeabbrev(ctxt *Link, syms []*Symbol) []*Symbol {
s := ctxt.Syms.Lookup(".debug_abbrev", 0) s := ctxt.Syms.Lookup(".debug_abbrev", 0)
s.Type = objabi.SDWARFSECT s.Type = SDWARFSECT
abbrevsym = s abbrevsym = s
Addbytes(s, dwarf.GetAbbrev()) Addbytes(s, dwarf.GetAbbrev())
return append(syms, s) return append(syms, s)
...@@ -148,7 +148,7 @@ func newdie(ctxt *Link, parent *dwarf.DWDie, abbrev int, name string, version in ...@@ -148,7 +148,7 @@ func newdie(ctxt *Link, parent *dwarf.DWDie, abbrev int, name string, version in
if abbrev != dwarf.DW_ABRV_VARIABLE || version == 0 { if abbrev != dwarf.DW_ABRV_VARIABLE || version == 0 {
sym := ctxt.Syms.Lookup(dwarf.InfoPrefix+name, version) sym := ctxt.Syms.Lookup(dwarf.InfoPrefix+name, version)
sym.Attr |= AttrHidden sym.Attr |= AttrHidden
sym.Type = objabi.SDWARFINFO sym.Type = SDWARFINFO
die.Sym = sym die.Sym = sym
} }
} }
...@@ -202,7 +202,7 @@ func find(ctxt *Link, name string) *Symbol { ...@@ -202,7 +202,7 @@ func find(ctxt *Link, name string) *Symbol {
// The string allocation below is optimized away because it is only used in a map lookup. // The string allocation below is optimized away because it is only used in a map lookup.
s := ctxt.Syms.ROLookup(string(n), 0) s := ctxt.Syms.ROLookup(string(n), 0)
prefixBuf = n[:len(dwarf.InfoPrefix)] prefixBuf = n[:len(dwarf.InfoPrefix)]
if s != nil && s.Type == objabi.SDWARFINFO { if s != nil && s.Type == SDWARFINFO {
return s return s
} }
return nil return nil
...@@ -340,7 +340,7 @@ func dotypedef(ctxt *Link, parent *dwarf.DWDie, name string, def *dwarf.DWDie) { ...@@ -340,7 +340,7 @@ func dotypedef(ctxt *Link, parent *dwarf.DWDie, name string, def *dwarf.DWDie) {
sym := ctxt.Syms.Lookup(dtolsym(def.Sym).Name+"..def", 0) sym := ctxt.Syms.Lookup(dtolsym(def.Sym).Name+"..def", 0)
sym.Attr |= AttrHidden sym.Attr |= AttrHidden
sym.Type = objabi.SDWARFINFO sym.Type = SDWARFINFO
def.Sym = sym def.Sym = sym
// The typedef entry must be created after the def, // The typedef entry must be created after the def,
...@@ -660,7 +660,7 @@ func mkinternaltype(ctxt *Link, abbrev int, typename, keyname, valname string, f ...@@ -660,7 +660,7 @@ func mkinternaltype(ctxt *Link, abbrev int, typename, keyname, valname string, f
name := mkinternaltypename(typename, keyname, valname) name := mkinternaltypename(typename, keyname, valname)
symname := dwarf.InfoPrefix + name symname := dwarf.InfoPrefix + name
s := ctxt.Syms.ROLookup(symname, 0) s := ctxt.Syms.ROLookup(symname, 0)
if s != nil && s.Type == objabi.SDWARFINFO { if s != nil && s.Type == SDWARFINFO {
return s return s
} }
die := newdie(ctxt, &dwtypes, abbrev, name, 0) die := newdie(ctxt, &dwtypes, abbrev, name, 0)
...@@ -996,7 +996,7 @@ func writelines(ctxt *Link, syms []*Symbol) ([]*Symbol, []*Symbol) { ...@@ -996,7 +996,7 @@ func writelines(ctxt *Link, syms []*Symbol) ([]*Symbol, []*Symbol) {
if linesec == nil { if linesec == nil {
linesec = ctxt.Syms.Lookup(".debug_line", 0) linesec = ctxt.Syms.Lookup(".debug_line", 0)
} }
linesec.Type = objabi.SDWARFSECT linesec.Type = SDWARFSECT
linesec.R = linesec.R[:0] linesec.R = linesec.R[:0]
ls := linesec ls := linesec
...@@ -1082,7 +1082,7 @@ func writelines(ctxt *Link, syms []*Symbol) ([]*Symbol, []*Symbol) { ...@@ -1082,7 +1082,7 @@ func writelines(ctxt *Link, syms []*Symbol) ([]*Symbol, []*Symbol) {
dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version)) dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version))
dsym.Attr |= AttrHidden | AttrReachable dsym.Attr |= AttrHidden | AttrReachable
dsym.Type = objabi.SDWARFINFO dsym.Type = SDWARFINFO
for _, r := range dsym.R { for _, r := range dsym.R {
if r.Type == objabi.R_DWARFREF && r.Sym.Size == 0 { if r.Type == objabi.R_DWARFREF && r.Sym.Size == 0 {
if Buildmode == BuildmodeShared { if Buildmode == BuildmodeShared {
...@@ -1179,7 +1179,7 @@ func writeframes(ctxt *Link, syms []*Symbol) []*Symbol { ...@@ -1179,7 +1179,7 @@ func writeframes(ctxt *Link, syms []*Symbol) []*Symbol {
if framesec == nil { if framesec == nil {
framesec = ctxt.Syms.Lookup(".debug_frame", 0) framesec = ctxt.Syms.Lookup(".debug_frame", 0)
} }
framesec.Type = objabi.SDWARFSECT framesec.Type = SDWARFSECT
framesec.R = framesec.R[:0] framesec.R = framesec.R[:0]
fs := framesec fs := framesec
syms = append(syms, fs) syms = append(syms, fs)
...@@ -1301,7 +1301,7 @@ func writeinfo(ctxt *Link, syms []*Symbol, funcs []*Symbol) []*Symbol { ...@@ -1301,7 +1301,7 @@ func writeinfo(ctxt *Link, syms []*Symbol, funcs []*Symbol) []*Symbol {
infosec = ctxt.Syms.Lookup(".debug_info", 0) infosec = ctxt.Syms.Lookup(".debug_info", 0)
} }
infosec.R = infosec.R[:0] infosec.R = infosec.R[:0]
infosec.Type = objabi.SDWARFINFO infosec.Type = SDWARFINFO
infosec.Attr |= AttrReachable infosec.Attr |= AttrReachable
syms = append(syms, infosec) syms = append(syms, infosec)
...@@ -1367,7 +1367,7 @@ func ispubtype(die *dwarf.DWDie) bool { ...@@ -1367,7 +1367,7 @@ func ispubtype(die *dwarf.DWDie) bool {
func writepub(ctxt *Link, sname string, ispub func(*dwarf.DWDie) bool, syms []*Symbol) []*Symbol { func writepub(ctxt *Link, sname string, ispub func(*dwarf.DWDie) bool, syms []*Symbol) []*Symbol {
s := ctxt.Syms.Lookup(sname, 0) s := ctxt.Syms.Lookup(sname, 0)
s.Type = objabi.SDWARFSECT s.Type = SDWARFSECT
syms = append(syms, s) syms = append(syms, s)
for compunit := dwroot.Child; compunit != nil; compunit = compunit.Link { for compunit := dwroot.Child; compunit != nil; compunit = compunit.Link {
...@@ -1407,7 +1407,7 @@ func writepub(ctxt *Link, sname string, ispub func(*dwarf.DWDie) bool, syms []*S ...@@ -1407,7 +1407,7 @@ func writepub(ctxt *Link, sname string, ispub func(*dwarf.DWDie) bool, syms []*S
*/ */
func writearanges(ctxt *Link, syms []*Symbol) []*Symbol { func writearanges(ctxt *Link, syms []*Symbol) []*Symbol {
s := ctxt.Syms.Lookup(".debug_aranges", 0) 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 // The first tuple is aligned to a multiple of the size of a single tuple
// (twice the size of an address) // (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 headersize := int(Rnd(4+2+4+1+1, int64(SysArch.PtrSize*2))) // don't count unit_length field itself
...@@ -1451,7 +1451,7 @@ func writegdbscript(ctxt *Link, syms []*Symbol) []*Symbol { ...@@ -1451,7 +1451,7 @@ func writegdbscript(ctxt *Link, syms []*Symbol) []*Symbol {
if gdbscript != "" { if gdbscript != "" {
s := ctxt.Syms.Lookup(".debug_gdb_scripts", 0) s := ctxt.Syms.Lookup(".debug_gdb_scripts", 0)
s.Type = objabi.SDWARFSECT s.Type = SDWARFSECT
syms = append(syms, s) syms = append(syms, s)
Adduint8(ctxt, s, 1) // magic 1 byte? Adduint8(ctxt, s, 1) // magic 1 byte?
Addstring(s, gdbscript) Addstring(s, gdbscript)
......
...@@ -1451,7 +1451,7 @@ func elfdynhash(ctxt *Link) { ...@@ -1451,7 +1451,7 @@ func elfdynhash(ctxt *Link) {
nsym := Nelfsym nsym := Nelfsym
s := ctxt.Syms.Lookup(".hash", 0) s := ctxt.Syms.Lookup(".hash", 0)
s.Type = objabi.SELFROSECT s.Type = SELFROSECT
s.Attr |= AttrReachable s.Attr |= AttrReachable
i := nsym i := nsym
...@@ -1856,7 +1856,7 @@ func Elfemitreloc(ctxt *Link) { ...@@ -1856,7 +1856,7 @@ func Elfemitreloc(ctxt *Link) {
func addgonote(ctxt *Link, sectionName string, tag uint32, desc []byte) { func addgonote(ctxt *Link, sectionName string, tag uint32, desc []byte) {
s := ctxt.Syms.Lookup(sectionName, 0) s := ctxt.Syms.Lookup(sectionName, 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFROSECT s.Type = SELFROSECT
// namesz // namesz
Adduint32(ctxt, s, uint32(len(ELF_NOTE_GO_NAME))) Adduint32(ctxt, s, uint32(len(ELF_NOTE_GO_NAME)))
// descsz // descsz
...@@ -1884,7 +1884,7 @@ func (ctxt *Link) doelf() { ...@@ -1884,7 +1884,7 @@ func (ctxt *Link) doelf() {
/* predefine strings we need for section headers */ /* predefine strings we need for section headers */
shstrtab := ctxt.Syms.Lookup(".shstrtab", 0) shstrtab := ctxt.Syms.Lookup(".shstrtab", 0)
shstrtab.Type = objabi.SELFROSECT shstrtab.Type = SELFROSECT
shstrtab.Attr |= AttrReachable shstrtab.Attr |= AttrReachable
Addstring(shstrtab, "") Addstring(shstrtab, "")
...@@ -1992,7 +1992,7 @@ func (ctxt *Link) doelf() { ...@@ -1992,7 +1992,7 @@ func (ctxt *Link) doelf() {
/* dynamic symbol table - first entry all zeros */ /* dynamic symbol table - first entry all zeros */
s := ctxt.Syms.Lookup(".dynsym", 0) s := ctxt.Syms.Lookup(".dynsym", 0)
s.Type = objabi.SELFROSECT s.Type = SELFROSECT
s.Attr |= AttrReachable s.Attr |= AttrReachable
if elf64 { if elf64 {
s.Size += ELF64SYMSIZE s.Size += ELF64SYMSIZE
...@@ -2003,7 +2003,7 @@ func (ctxt *Link) doelf() { ...@@ -2003,7 +2003,7 @@ func (ctxt *Link) doelf() {
/* dynamic string table */ /* dynamic string table */
s = ctxt.Syms.Lookup(".dynstr", 0) s = ctxt.Syms.Lookup(".dynstr", 0)
s.Type = objabi.SELFROSECT s.Type = SELFROSECT
s.Attr |= AttrReachable s.Attr |= AttrReachable
if s.Size == 0 { if s.Size == 0 {
Addstring(s, "") Addstring(s, "")
...@@ -2013,30 +2013,30 @@ func (ctxt *Link) doelf() { ...@@ -2013,30 +2013,30 @@ func (ctxt *Link) doelf() {
/* relocation table */ /* relocation table */
s = ctxt.Syms.Lookup(elfRelType, 0) s = ctxt.Syms.Lookup(elfRelType, 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFROSECT s.Type = SELFROSECT
/* global offset table */ /* global offset table */
s = ctxt.Syms.Lookup(".got", 0) s = ctxt.Syms.Lookup(".got", 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFGOT // writable s.Type = SELFGOT // writable
/* ppc64 glink resolver */ /* ppc64 glink resolver */
if SysArch.Family == sys.PPC64 { if SysArch.Family == sys.PPC64 {
s := ctxt.Syms.Lookup(".glink", 0) s := ctxt.Syms.Lookup(".glink", 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFRXSECT s.Type = SELFRXSECT
} }
/* hash */ /* hash */
s = ctxt.Syms.Lookup(".hash", 0) s = ctxt.Syms.Lookup(".hash", 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFROSECT s.Type = SELFROSECT
s = ctxt.Syms.Lookup(".got.plt", 0) s = ctxt.Syms.Lookup(".got.plt", 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFSECT // writable s.Type = SELFSECT // writable
s = ctxt.Syms.Lookup(".plt", 0) s = ctxt.Syms.Lookup(".plt", 0)
...@@ -2044,30 +2044,30 @@ func (ctxt *Link) doelf() { ...@@ -2044,30 +2044,30 @@ func (ctxt *Link) doelf() {
if SysArch.Family == sys.PPC64 { if SysArch.Family == sys.PPC64 {
// In the ppc64 ABI, .plt is a data section // In the ppc64 ABI, .plt is a data section
// written by the dynamic linker. // written by the dynamic linker.
s.Type = objabi.SELFSECT s.Type = SELFSECT
} else { } else {
s.Type = objabi.SELFRXSECT s.Type = SELFRXSECT
} }
Thearch.Elfsetupplt(ctxt) Thearch.Elfsetupplt(ctxt)
s = ctxt.Syms.Lookup(elfRelType+".plt", 0) s = ctxt.Syms.Lookup(elfRelType+".plt", 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFROSECT s.Type = SELFROSECT
s = ctxt.Syms.Lookup(".gnu.version", 0) s = ctxt.Syms.Lookup(".gnu.version", 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFROSECT s.Type = SELFROSECT
s = ctxt.Syms.Lookup(".gnu.version_r", 0) s = ctxt.Syms.Lookup(".gnu.version_r", 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFROSECT s.Type = SELFROSECT
/* define dynamic elf table */ /* define dynamic elf table */
s = ctxt.Syms.Lookup(".dynamic", 0) s = ctxt.Syms.Lookup(".dynamic", 0)
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Type = objabi.SELFSECT // writable s.Type = SELFSECT // writable
/* /*
* .dynamic table * .dynamic table
...@@ -2120,7 +2120,7 @@ func (ctxt *Link) doelf() { ...@@ -2120,7 +2120,7 @@ func (ctxt *Link) doelf() {
// part of the .note.go.abihash section in data.go:func address(). // part of the .note.go.abihash section in data.go:func address().
s := ctxt.Syms.Lookup("go.link.abihashbytes", 0) s := ctxt.Syms.Lookup("go.link.abihashbytes", 0)
s.Attr |= AttrLocal s.Attr |= AttrLocal
s.Type = objabi.SRODATA s.Type = SRODATA
s.Attr |= AttrSpecial s.Attr |= AttrSpecial
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Size = int64(sha1.Size) s.Size = int64(sha1.Size)
...@@ -2596,10 +2596,10 @@ elfobj: ...@@ -2596,10 +2596,10 @@ elfobj:
elfshreloc(sect) elfshreloc(sect)
} }
for _, s := range dwarfp { for _, s := range dwarfp {
if len(s.R) > 0 || s.Type == objabi.SDWARFINFO { if len(s.R) > 0 || s.Type == SDWARFINFO {
elfshreloc(s.Sect) elfshreloc(s.Sect)
} }
if s.Type == objabi.SDWARFINFO { if s.Type == SDWARFINFO {
break break
} }
} }
...@@ -2715,7 +2715,7 @@ func Elfadddynsym(ctxt *Link, s *Symbol) { ...@@ -2715,7 +2715,7 @@ func Elfadddynsym(ctxt *Link, s *Symbol) {
/* type */ /* type */
t := STB_GLOBAL << 4 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 t |= STT_FUNC
} else { } else {
t |= STT_OBJECT t |= STT_OBJECT
...@@ -2726,14 +2726,14 @@ func Elfadddynsym(ctxt *Link, s *Symbol) { ...@@ -2726,14 +2726,14 @@ func Elfadddynsym(ctxt *Link, s *Symbol) {
Adduint8(ctxt, d, 0) Adduint8(ctxt, d, 0)
/* section where symbol is defined */ /* section where symbol is defined */
if s.Type == objabi.SDYNIMPORT { if s.Type == SDYNIMPORT {
Adduint16(ctxt, d, SHN_UNDEF) Adduint16(ctxt, d, SHN_UNDEF)
} else { } else {
Adduint16(ctxt, d, 1) Adduint16(ctxt, d, 1)
} }
/* value */ /* value */
if s.Type == objabi.SDYNIMPORT { if s.Type == SDYNIMPORT {
Adduint64(ctxt, d, 0) Adduint64(ctxt, d, 0)
} else { } else {
Addaddr(ctxt, d, s) Addaddr(ctxt, d, s)
...@@ -2757,7 +2757,7 @@ func Elfadddynsym(ctxt *Link, s *Symbol) { ...@@ -2757,7 +2757,7 @@ func Elfadddynsym(ctxt *Link, s *Symbol) {
Adduint32(ctxt, d, uint32(Addstring(ctxt.Syms.Lookup(".dynstr", 0), name))) Adduint32(ctxt, d, uint32(Addstring(ctxt.Syms.Lookup(".dynstr", 0), name)))
/* value */ /* value */
if s.Type == objabi.SDYNIMPORT { if s.Type == SDYNIMPORT {
Adduint32(ctxt, d, 0) Adduint32(ctxt, d, 0)
} else { } else {
Addaddr(ctxt, d, s) Addaddr(ctxt, d, s)
...@@ -2770,9 +2770,9 @@ func Elfadddynsym(ctxt *Link, s *Symbol) { ...@@ -2770,9 +2770,9 @@ func Elfadddynsym(ctxt *Link, s *Symbol) {
t := STB_GLOBAL << 4 t := STB_GLOBAL << 4
// TODO(mwhudson): presumably the behavior should actually be the same on both arm and 386. // 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 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 t |= STT_FUNC
} else { } else {
t |= STT_OBJECT t |= STT_OBJECT
...@@ -2781,7 +2781,7 @@ func Elfadddynsym(ctxt *Link, s *Symbol) { ...@@ -2781,7 +2781,7 @@ func Elfadddynsym(ctxt *Link, s *Symbol) {
Adduint8(ctxt, d, 0) Adduint8(ctxt, d, 0)
/* shndx */ /* shndx */
if s.Type == objabi.SDYNIMPORT { if s.Type == SDYNIMPORT {
Adduint16(ctxt, d, SHN_UNDEF) Adduint16(ctxt, d, SHN_UNDEF)
} else { } else {
Adduint16(ctxt, d, 1) Adduint16(ctxt, d, 1)
......
...@@ -190,12 +190,12 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) { ...@@ -190,12 +190,12 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
s = ctxt.Syms.Lookup(local, 0) s = ctxt.Syms.Lookup(local, 0)
if local != f[1] { 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.Dynimplib = lib
s.Extname = remote s.Extname = remote
s.Dynimpvers = q s.Dynimpvers = q
if s.Type != objabi.SHOSTOBJ { if s.Type != SHOSTOBJ {
s.Type = objabi.SDYNIMPORT s.Type = SDYNIMPORT
} }
havedynamic = 1 havedynamic = 1
} }
...@@ -209,7 +209,7 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) { ...@@ -209,7 +209,7 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
} }
local = f[1] local = f[1]
s = ctxt.Syms.Lookup(local, 0) s = ctxt.Syms.Lookup(local, 0)
s.Type = objabi.SHOSTOBJ s.Type = SHOSTOBJ
s.Size = 0 s.Size = 0
continue continue
} }
...@@ -347,7 +347,7 @@ func fieldtrack(ctxt *Link) { ...@@ -347,7 +347,7 @@ func fieldtrack(ctxt *Link) {
buf.WriteString("\n") buf.WriteString("\n")
} }
s.Type = objabi.SCONST s.Type = SCONST
s.Value = 0 s.Value = 0
} }
} }
......
...@@ -729,21 +729,21 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -729,21 +729,21 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
return return
case ElfSectFlagAlloc: case ElfSectFlagAlloc:
s.Type = objabi.SRODATA s.Type = SRODATA
case ElfSectFlagAlloc + ElfSectFlagWrite: case ElfSectFlagAlloc + ElfSectFlagWrite:
if sect.type_ == ElfSectNobits { if sect.type_ == ElfSectNobits {
s.Type = objabi.SNOPTRBSS s.Type = SNOPTRBSS
} else { } else {
s.Type = objabi.SNOPTRDATA s.Type = SNOPTRDATA
} }
case ElfSectFlagAlloc + ElfSectFlagExec: case ElfSectFlagAlloc + ElfSectFlagExec:
s.Type = objabi.STEXT s.Type = STEXT
} }
if sect.name == ".got" || sect.name == ".toc" { if sect.name == ".got" || sect.name == ".toc" {
s.Type = objabi.SELFGOT s.Type = SELFGOT
} }
if sect.type_ == ElfSectProgbits { if sect.type_ == ElfSectProgbits {
s.P = sect.base s.P = sect.base
...@@ -773,8 +773,8 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -773,8 +773,8 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
if uint64(s.Size) < sym.size { if uint64(s.Size) < sym.size {
s.Size = int64(sym.size) s.Size = int64(sym.size)
} }
if s.Type == 0 || s.Type == objabi.SXREF { if s.Type == 0 || s.Type == SXREF {
s.Type = objabi.SNOPTRBSS s.Type = SNOPTRBSS
} }
continue continue
} }
...@@ -816,14 +816,14 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -816,14 +816,14 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
s.Sub = sect.sym.Sub s.Sub = sect.sym.Sub
sect.sym.Sub = s 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() { if !s.Attr.CgoExportDynamic() {
s.Dynimplib = "" // satisfy dynimport s.Dynimplib = "" // satisfy dynimport
} }
s.Value = int64(sym.value) s.Value = int64(sym.value)
s.Size = int64(sym.size) s.Size = int64(sym.size)
s.Outer = sect.sym s.Outer = sect.sym
if sect.sym.Type == objabi.STEXT { if sect.sym.Type == STEXT {
if s.Attr.External() && !s.Attr.DuplicateOK() { if s.Attr.External() && !s.Attr.DuplicateOK() {
Errorf(s, "%s: duplicate symbol definition", pn) Errorf(s, "%s: duplicate symbol definition", pn)
} }
...@@ -850,7 +850,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -850,7 +850,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
if s.Sub != nil { if s.Sub != nil {
s.Sub = listsort(s.Sub) s.Sub = listsort(s.Sub)
} }
if s.Type == objabi.STEXT { if s.Type == STEXT {
if s.Attr.OnList() { if s.Attr.OnList() {
log.Fatalf("symbol %s listed multiple times", s.Name) log.Fatalf("symbol %s listed multiple times", s.Name)
} }
...@@ -1060,7 +1060,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc ...@@ -1060,7 +1060,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc
// set dupok generally. See http://codereview.appspot.com/5823055/ // set dupok generally. See http://codereview.appspot.com/5823055/
// comment #5 for details. // comment #5 for details.
if s != nil && sym.other == 2 { if s != nil && sym.other == 2 {
s.Type |= objabi.SHIDDEN s.Type |= SHIDDEN
s.Attr |= AttrDuplicateOK s.Attr |= AttrDuplicateOK
} }
} }
...@@ -1077,7 +1077,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc ...@@ -1077,7 +1077,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc
// so put it in the hash table. // so put it in the hash table.
if needSym != 0 { if needSym != 0 {
s = ctxt.Syms.Lookup(sym.name, localSymVersion) s = ctxt.Syms.Lookup(sym.name, localSymVersion)
s.Type |= objabi.SHIDDEN s.Type |= SHIDDEN
} }
break break
...@@ -1089,14 +1089,14 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc ...@@ -1089,14 +1089,14 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc
// don't bother to add them into the hash table // don't bother to add them into the hash table
s = ctxt.Syms.newsym(sym.name, localSymVersion) s = ctxt.Syms.newsym(sym.name, localSymVersion)
s.Type |= objabi.SHIDDEN s.Type |= SHIDDEN
} }
case ElfSymBindWeak: case ElfSymBindWeak:
if needSym != 0 { if needSym != 0 {
s = ctxt.Syms.Lookup(sym.name, 0) s = ctxt.Syms.Lookup(sym.name, 0)
if sym.other == 2 { if sym.other == 2 {
s.Type |= objabi.SHIDDEN s.Type |= SHIDDEN
} }
} }
...@@ -1107,7 +1107,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc ...@@ -1107,7 +1107,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc
} }
if s != nil && s.Type == 0 && sym.type_ != ElfSymTypeSection { if s != nil && s.Type == 0 && sym.type_ != ElfSymTypeSection {
s.Type = objabi.SXREF s.Type = SXREF
} }
sym.sym = s sym.sym = s
......
...@@ -602,16 +602,16 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -602,16 +602,16 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
if sect.segname == "__TEXT" { if sect.segname == "__TEXT" {
if sect.name == "__text" { if sect.name == "__text" {
s.Type = objabi.STEXT s.Type = STEXT
} else { } else {
s.Type = objabi.SRODATA s.Type = SRODATA
} }
} else { } else {
if sect.name == "__bss" { if sect.name == "__bss" {
s.Type = objabi.SNOPTRBSS s.Type = SNOPTRBSS
s.P = s.P[:0] s.P = s.P[:0]
} else { } else {
s.Type = objabi.SNOPTRDATA s.Type = SNOPTRDATA
} }
} }
...@@ -663,7 +663,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -663,7 +663,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
Exitf("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name) 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 s.Sub = outer.Sub
outer.Sub = s outer.Sub = s
s.Outer = outer s.Outer = outer
...@@ -671,7 +671,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -671,7 +671,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
if !s.Attr.CgoExportDynamic() { if !s.Attr.CgoExportDynamic() {
s.Dynimplib = "" // satisfy dynimport s.Dynimplib = "" // satisfy dynimport
} }
if outer.Type == objabi.STEXT { if outer.Type == STEXT {
if s.Attr.External() && !s.Attr.DuplicateOK() { if s.Attr.External() && !s.Attr.DuplicateOK() {
Errorf(s, "%s: duplicate symbol definition", pn) Errorf(s, "%s: duplicate symbol definition", pn)
} }
...@@ -702,7 +702,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -702,7 +702,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
} }
} }
if s.Type == objabi.STEXT { if s.Type == STEXT {
if s.Attr.OnList() { if s.Attr.OnList() {
log.Fatalf("symbol %s listed multiple times", s.Name) log.Fatalf("symbol %s listed multiple times", s.Name)
} }
......
...@@ -173,16 +173,16 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin ...@@ -173,16 +173,16 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin
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) { 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 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 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 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 case IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ: //.text
s.Type = objabi.STEXT s.Type = STEXT
default: default:
return fmt.Errorf("unexpected flags %#06x for PE section %s", sect.Characteristics, sect.Name) return fmt.Errorf("unexpected flags %#06x for PE section %s", sect.Characteristics, sect.Name)
...@@ -313,11 +313,11 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin ...@@ -313,11 +313,11 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin
} }
if pesym.SectionNumber == 0 { // extern if pesym.SectionNumber == 0 { // extern
if s.Type == objabi.SDYNIMPORT { if s.Type == SDYNIMPORT {
s.Plt = -2 // flag for dynimport in PE object files. s.Plt = -2 // flag for dynimport in PE object files.
} }
if s.Type == objabi.SXREF && pesym.Value > 0 { // global data if s.Type == SXREF && pesym.Value > 0 { // global data
s.Type = objabi.SNOPTRDATA s.Type = SNOPTRDATA
s.Size = int64(pesym.Value) s.Size = int64(pesym.Value)
} }
...@@ -345,11 +345,11 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin ...@@ -345,11 +345,11 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin
sectsym := sectsyms[sect] sectsym := sectsyms[sect]
s.Sub = sectsym.Sub s.Sub = sectsym.Sub
sectsym.Sub = s sectsym.Sub = s
s.Type = sectsym.Type | objabi.SSUB s.Type = sectsym.Type | SSUB
s.Value = int64(pesym.Value) s.Value = int64(pesym.Value)
s.Size = 4 s.Size = 4
s.Outer = sectsym s.Outer = sectsym
if sectsym.Type == objabi.STEXT { if sectsym.Type == STEXT {
if s.Attr.External() && !s.Attr.DuplicateOK() { if s.Attr.External() && !s.Attr.DuplicateOK() {
Errorf(s, "%s: duplicate symbol definition", pn) Errorf(s, "%s: duplicate symbol definition", pn)
} }
...@@ -367,7 +367,7 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin ...@@ -367,7 +367,7 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin
if s.Sub != nil { if s.Sub != nil {
s.Sub = listsort(s.Sub) s.Sub = listsort(s.Sub)
} }
if s.Type == objabi.STEXT { if s.Type == STEXT {
if s.Attr.OnList() { if s.Attr.OnList() {
log.Fatalf("symbol %s listed multiple times", s.Name) log.Fatalf("symbol %s listed multiple times", s.Name)
} }
...@@ -433,7 +433,7 @@ func readpesym(ctxt *Link, f *pe.File, sym *pe.COFFSymbol, sectsyms map[*pe.Sect ...@@ -433,7 +433,7 @@ func readpesym(ctxt *Link, f *pe.File, sym *pe.COFFSymbol, sectsyms map[*pe.Sect
} }
if s != nil && s.Type == 0 && (sym.StorageClass != IMAGE_SYM_CLASS_STATIC || sym.Value != 0) { 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_") { if strings.HasPrefix(symname, "__imp_") {
s.Got = -2 // flag for __imp_ s.Got = -2 // flag for __imp_
......
...@@ -440,7 +440,7 @@ func (ctxt *Link) loadlib() { ...@@ -440,7 +440,7 @@ func (ctxt *Link) loadlib() {
if Linkmode == LinkExternal && SysArch.Family == sys.PPC64 { if Linkmode == LinkExternal && SysArch.Family == sys.PPC64 {
toc := ctxt.Syms.Lookup(".TOC.", 0) toc := ctxt.Syms.Lookup(".TOC.", 0)
toc.Type = objabi.SDYNIMPORT toc.Type = SDYNIMPORT
} }
if Linkmode == LinkExternal && !iscgo { if Linkmode == LinkExternal && !iscgo {
...@@ -466,13 +466,13 @@ func (ctxt *Link) loadlib() { ...@@ -466,13 +466,13 @@ func (ctxt *Link) loadlib() {
// Drop all the cgo_import_static declarations. // Drop all the cgo_import_static declarations.
// Turns out we won't be needing them. // Turns out we won't be needing them.
for _, s := range ctxt.Syms.Allsym { for _, s := range ctxt.Syms.Allsym {
if s.Type == objabi.SHOSTOBJ { if s.Type == SHOSTOBJ {
// If a symbol was marked both // If a symbol was marked both
// cgo_import_static and cgo_import_dynamic, // cgo_import_static and cgo_import_dynamic,
// then we want to make it cgo_import_dynamic // then we want to make it cgo_import_dynamic
// now. // now.
if s.Extname != "" && s.Dynimplib != "" && !s.Attr.CgoExport() { if s.Extname != "" && s.Dynimplib != "" && !s.Attr.CgoExport() {
s.Type = objabi.SDYNIMPORT s.Type = SDYNIMPORT
} else { } else {
s.Type = 0 s.Type = 0
} }
...@@ -485,9 +485,9 @@ func (ctxt *Link) loadlib() { ...@@ -485,9 +485,9 @@ func (ctxt *Link) loadlib() {
// runtime.tlsg is used for external linking on platforms that do not define // runtime.tlsg is used for external linking on platforms that do not define
// a variable to hold g in assembly (currently only intel). // a variable to hold g in assembly (currently only intel).
if tlsg.Type == 0 { if tlsg.Type == 0 {
tlsg.Type = objabi.STLSBSS tlsg.Type = STLSBSS
tlsg.Size = int64(SysArch.PtrSize) 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) Errorf(nil, "runtime declared tlsg variable %v", tlsg.Type)
} }
tlsg.Attr |= AttrReachable tlsg.Attr |= AttrReachable
...@@ -500,7 +500,7 @@ func (ctxt *Link) loadlib() { ...@@ -500,7 +500,7 @@ func (ctxt *Link) loadlib() {
} else { } else {
moduledata = ctxt.Syms.Lookup("runtime.firstmoduledata", 0) 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 // If the module (toolchain-speak for "executable or shared
// library") we are linking contains the runtime package, it // library") we are linking contains the runtime package, it
// will define the runtime.firstmoduledata symbol and we // will define the runtime.firstmoduledata symbol and we
...@@ -512,14 +512,14 @@ func (ctxt *Link) loadlib() { ...@@ -512,14 +512,14 @@ func (ctxt *Link) loadlib() {
// recording the value of GOARM. // recording the value of GOARM.
if SysArch.Family == sys.ARM { if SysArch.Family == sys.ARM {
s := ctxt.Syms.Lookup("runtime.goarm", 0) s := ctxt.Syms.Lookup("runtime.goarm", 0)
s.Type = objabi.SRODATA s.Type = SRODATA
s.Size = 0 s.Size = 0
Adduint8(ctxt, s, uint8(objabi.GOARM)) Adduint8(ctxt, s, uint8(objabi.GOARM))
} }
if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) { if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) {
s := ctxt.Syms.Lookup("runtime.framepointer_enabled", 0) s := ctxt.Syms.Lookup("runtime.framepointer_enabled", 0)
s.Type = objabi.SRODATA s.Type = SRODATA
s.Size = 0 s.Size = 0
Adduint8(ctxt, s, 1) Adduint8(ctxt, s, 1)
} }
...@@ -531,7 +531,7 @@ func (ctxt *Link) loadlib() { ...@@ -531,7 +531,7 @@ func (ctxt *Link) loadlib() {
} }
// In all cases way we mark the moduledata as noptrdata to hide it from // In all cases way we mark the moduledata as noptrdata to hide it from
// the GC. // the GC.
moduledata.Type = objabi.SNOPTRDATA moduledata.Type = SNOPTRDATA
moduledata.Attr |= AttrReachable moduledata.Attr |= AttrReachable
ctxt.Moduledata = moduledata ctxt.Moduledata = moduledata
...@@ -559,7 +559,7 @@ func (ctxt *Link) loadlib() { ...@@ -559,7 +559,7 @@ func (ctxt *Link) loadlib() {
any := false any := false
for _, s := range ctxt.Syms.Allsym { for _, s := range ctxt.Syms.Allsym {
for _, r := range s.R { 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 any = true
break break
} }
...@@ -625,7 +625,7 @@ func (ctxt *Link) loadlib() { ...@@ -625,7 +625,7 @@ func (ctxt *Link) loadlib() {
if SysArch == sys.Arch386 { if SysArch == sys.Arch386 {
if (Buildmode == BuildmodeCArchive && Iself) || Buildmode == BuildmodeCShared || Buildmode == BuildmodePIE || ctxt.DynlinkingGo() { if (Buildmode == BuildmodeCArchive && Iself) || Buildmode == BuildmodeCShared || Buildmode == BuildmodePIE || ctxt.DynlinkingGo() {
got := ctxt.Syms.Lookup("_GLOBAL_OFFSET_TABLE_", 0) got := ctxt.Syms.Lookup("_GLOBAL_OFFSET_TABLE_", 0)
got.Type = objabi.SDYNIMPORT got.Type = SDYNIMPORT
got.Attr |= AttrReachable got.Attr |= AttrReachable
} }
} }
...@@ -663,7 +663,7 @@ func (ctxt *Link) loadlib() { ...@@ -663,7 +663,7 @@ func (ctxt *Link) loadlib() {
// pcln table entries for these any more so remove them from Textp. // pcln table entries for these any more so remove them from Textp.
textp := make([]*Symbol, 0, len(ctxt.Textp)) textp := make([]*Symbol, 0, len(ctxt.Textp))
for _, s := range ctxt.Textp { for _, s := range ctxt.Textp {
if s.Type != objabi.SDYNIMPORT { if s.Type != SDYNIMPORT {
textp = append(textp, s) textp = append(textp, s)
} }
} }
...@@ -1526,10 +1526,10 @@ func ldshlibsyms(ctxt *Link, shlib string) { ...@@ -1526,10 +1526,10 @@ func ldshlibsyms(ctxt *Link, shlib string) {
// libraries, any non-dynimport symbols we find that duplicate symbols // libraries, any non-dynimport symbols we find that duplicate symbols
// already loaded should be ignored (the symbols from the .a files // already loaded should be ignored (the symbols from the .a files
// "win"). // "win").
if lsym.Type != 0 && lsym.Type != objabi.SDYNIMPORT { if lsym.Type != 0 && lsym.Type != SDYNIMPORT {
continue continue
} }
lsym.Type = objabi.SDYNIMPORT lsym.Type = SDYNIMPORT
lsym.ElfType = elf.ST_TYPE(elfsym.Info) lsym.ElfType = elf.ST_TYPE(elfsym.Info)
lsym.Size = int64(elfsym.Size) lsym.Size = int64(elfsym.Size)
if elfsym.Section != elf.SHN_UNDEF { if elfsym.Section != elf.SHN_UNDEF {
...@@ -1689,7 +1689,7 @@ func stkcheck(ctxt *Link, up *chain, depth int) int { ...@@ -1689,7 +1689,7 @@ func stkcheck(ctxt *Link, up *chain, depth int) int {
// should never be called directly. // should never be called directly.
// onlyctxt.Diagnose the direct caller. // onlyctxt.Diagnose the direct caller.
// TODO(mwhudson): actually think about this. // 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 { Buildmode != BuildmodeCArchive && Buildmode != BuildmodePIE && Buildmode != BuildmodeCShared && Buildmode != BuildmodePlugin {
Errorf(s, "call to external function") Errorf(s, "call to external function")
...@@ -1872,7 +1872,7 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, * ...@@ -1872,7 +1872,7 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, *
// These symbols won't show up in the first loop below because we // These symbols won't show up in the first loop below because we
// skip STEXT symbols. Normal STEXT symbols are emitted by walking textp. // skip STEXT symbols. Normal STEXT symbols are emitted by walking textp.
s := ctxt.Syms.Lookup("runtime.text", 0) 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) put(ctxt, s, s.Name, TextSym, s.Value, nil)
} }
...@@ -1891,14 +1891,14 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, * ...@@ -1891,14 +1891,14 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, *
if s == nil { if s == nil {
break break
} }
if s.Type == objabi.STEXT { if s.Type == STEXT {
put(ctxt, s, s.Name, TextSym, s.Value, nil) put(ctxt, s, s.Name, TextSym, s.Value, nil)
} }
n++ n++
} }
s = ctxt.Syms.Lookup("runtime.etext", 0) 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) put(ctxt, s, s.Name, TextSym, s.Value, nil)
} }
...@@ -1909,36 +1909,36 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, * ...@@ -1909,36 +1909,36 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, *
if (s.Name == "" || s.Name[0] == '.') && s.Version == 0 && s.Name != ".rathole" && s.Name != ".TOC." { if (s.Name == "" || s.Name[0] == '.') && s.Version == 0 && s.Name != ".rathole" && s.Name != ".TOC." {
continue continue
} }
switch s.Type & objabi.SMASK { switch s.Type & SMASK {
case objabi.SCONST, case SCONST,
objabi.SRODATA, SRODATA,
objabi.SSYMTAB, SSYMTAB,
objabi.SPCLNTAB, SPCLNTAB,
objabi.SINITARR, SINITARR,
objabi.SDATA, SDATA,
objabi.SNOPTRDATA, SNOPTRDATA,
objabi.SELFROSECT, SELFROSECT,
objabi.SMACHOGOT, SMACHOGOT,
objabi.STYPE, STYPE,
objabi.SSTRING, SSTRING,
objabi.SGOSTRING, SGOSTRING,
objabi.SGOFUNC, SGOFUNC,
objabi.SGCBITS, SGCBITS,
objabi.STYPERELRO, STYPERELRO,
objabi.SSTRINGRELRO, SSTRINGRELRO,
objabi.SGOSTRINGRELRO, SGOSTRINGRELRO,
objabi.SGOFUNCRELRO, SGOFUNCRELRO,
objabi.SGCBITSRELRO, SGCBITSRELRO,
objabi.SRODATARELRO, SRODATARELRO,
objabi.STYPELINK, STYPELINK,
objabi.SITABLINK, SITABLINK,
objabi.SWINDOWS: SWINDOWS:
if !s.Attr.Reachable() { if !s.Attr.Reachable() {
continue continue
} }
put(ctxt, s, s.Name, DataSym, Symaddr(s), s.Gotype) put(ctxt, s, s.Name, DataSym, Symaddr(s), s.Gotype)
case objabi.SBSS, objabi.SNOPTRBSS: case SBSS, SNOPTRBSS:
if !s.Attr.Reachable() { if !s.Attr.Reachable() {
continue continue
} }
...@@ -1947,21 +1947,21 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, * ...@@ -1947,21 +1947,21 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, *
} }
put(ctxt, s, s.Name, BSSSym, Symaddr(s), s.Gotype) put(ctxt, s, s.Name, BSSSym, Symaddr(s), s.Gotype)
case objabi.SFILE: case SFILE:
put(ctxt, nil, s.Name, FileSym, s.Value, nil) put(ctxt, nil, s.Name, FileSym, s.Value, nil)
case objabi.SHOSTOBJ: case SHOSTOBJ:
if Headtype == objabi.Hwindows || Iself { if Headtype == objabi.Hwindows || Iself {
put(ctxt, s, s.Name, UndefinedSym, s.Value, nil) put(ctxt, s, s.Name, UndefinedSym, s.Value, nil)
} }
case objabi.SDYNIMPORT: case SDYNIMPORT:
if !s.Attr.Reachable() { if !s.Attr.Reachable() {
continue continue
} }
put(ctxt, s, s.Extname, UndefinedSym, 0, nil) put(ctxt, s, s.Extname, UndefinedSym, 0, nil)
case objabi.STLSBSS: case STLSBSS:
if Linkmode == LinkExternal { if Linkmode == LinkExternal {
put(ctxt, s, s.Name, TLSSym, Symaddr(s), s.Gotype) put(ctxt, s, s.Name, TLSSym, Symaddr(s), s.Gotype)
} }
...@@ -2024,7 +2024,7 @@ func Symaddr(s *Symbol) int64 { ...@@ -2024,7 +2024,7 @@ func Symaddr(s *Symbol) int64 {
return s.Value 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 := ctxt.Syms.Lookup(p, 0)
s.Type = t s.Type = t
s.Value = v s.Value = v
...@@ -2053,7 +2053,7 @@ func Entryvalue(ctxt *Link) int64 { ...@@ -2053,7 +2053,7 @@ func Entryvalue(ctxt *Link) int64 {
if s.Type == 0 { if s.Type == 0 {
return *FlagTextAddr return *FlagTextAddr
} }
if s.Type != objabi.STEXT { if s.Type != STEXT {
Errorf(s, "entry not text") Errorf(s, "entry not text")
} }
return s.Value return s.Value
...@@ -2067,7 +2067,7 @@ func undefsym(ctxt *Link, s *Symbol) { ...@@ -2067,7 +2067,7 @@ func undefsym(ctxt *Link, s *Symbol) {
if r.Sym == nil { // happens for some external ARM relocs if r.Sym == nil { // happens for some external ARM relocs
continue 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) Errorf(s, "undefined: %q", r.Sym.Name)
} }
if !r.Sym.Attr.Reachable() && r.Type != objabi.R_WEAKADDROFF { if !r.Sym.Attr.Reachable() && r.Type != objabi.R_WEAKADDROFF {
...@@ -2101,7 +2101,7 @@ func (ctxt *Link) callgraph() { ...@@ -2101,7 +2101,7 @@ func (ctxt *Link) callgraph() {
if r.Sym == nil { if r.Sym == nil {
continue 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) ctxt.Logf("%s calls %s\n", s.Name, r.Sym.Name)
} }
} }
......
...@@ -42,7 +42,7 @@ import ( ...@@ -42,7 +42,7 @@ import (
type Symbol struct { type Symbol struct {
Name string Name string
Extname string Extname string
Type objabi.SymKind Type SymKind
Version int16 Version int16
Attr Attribute Attr Attribute
Localentry uint8 Localentry uint8
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package ld package ld
import ( import (
"cmd/internal/objabi"
"cmd/internal/sys" "cmd/internal/sys"
"sort" "sort"
"strings" "strings"
...@@ -302,31 +301,31 @@ func (ctxt *Link) domacho() { ...@@ -302,31 +301,31 @@ func (ctxt *Link) domacho() {
// empirically, string table must begin with " \x00". // empirically, string table must begin with " \x00".
s := ctxt.Syms.Lookup(".machosymstr", 0) s := ctxt.Syms.Lookup(".machosymstr", 0)
s.Type = objabi.SMACHOSYMSTR s.Type = SMACHOSYMSTR
s.Attr |= AttrReachable s.Attr |= AttrReachable
Adduint8(ctxt, s, ' ') Adduint8(ctxt, s, ' ')
Adduint8(ctxt, s, '\x00') Adduint8(ctxt, s, '\x00')
s = ctxt.Syms.Lookup(".machosymtab", 0) s = ctxt.Syms.Lookup(".machosymtab", 0)
s.Type = objabi.SMACHOSYMTAB s.Type = SMACHOSYMTAB
s.Attr |= AttrReachable s.Attr |= AttrReachable
if Linkmode != LinkExternal { if Linkmode != LinkExternal {
s := ctxt.Syms.Lookup(".plt", 0) // will be __symbol_stub s := ctxt.Syms.Lookup(".plt", 0) // will be __symbol_stub
s.Type = objabi.SMACHOPLT s.Type = SMACHOPLT
s.Attr |= AttrReachable s.Attr |= AttrReachable
s = ctxt.Syms.Lookup(".got", 0) // will be __nl_symbol_ptr s = ctxt.Syms.Lookup(".got", 0) // will be __nl_symbol_ptr
s.Type = objabi.SMACHOGOT s.Type = SMACHOGOT
s.Attr |= AttrReachable s.Attr |= AttrReachable
s.Align = 4 s.Align = 4
s = ctxt.Syms.Lookup(".linkedit.plt", 0) // indirect table for .plt s = ctxt.Syms.Lookup(".linkedit.plt", 0) // indirect table for .plt
s.Type = objabi.SMACHOINDIRECTPLT s.Type = SMACHOINDIRECTPLT
s.Attr |= AttrReachable s.Attr |= AttrReachable
s = ctxt.Syms.Lookup(".linkedit.got", 0) // indirect table for .got s = ctxt.Syms.Lookup(".linkedit.got", 0) // indirect table for .got
s.Type = objabi.SMACHOINDIRECTGOT s.Type = SMACHOINDIRECTGOT
s.Attr |= AttrReachable s.Attr |= AttrReachable
} }
} }
...@@ -603,7 +602,7 @@ func Asmbmacho(ctxt *Link) { ...@@ -603,7 +602,7 @@ func Asmbmacho(ctxt *Link) {
} }
func symkind(s *Symbol) int { func symkind(s *Symbol) int {
if s.Type == objabi.SDYNIMPORT { if s.Type == SDYNIMPORT {
return SymKindUndef return SymKindUndef
} }
if s.Attr.CgoExport() { if s.Attr.CgoExport() {
...@@ -659,7 +658,7 @@ func (x machoscmp) Less(i, j int) bool { ...@@ -659,7 +658,7 @@ func (x machoscmp) Less(i, j int) bool {
func machogenasmsym(ctxt *Link) { func machogenasmsym(ctxt *Link) {
genasmsym(ctxt, addsym) genasmsym(ctxt, addsym)
for _, s := range ctxt.Syms.Allsym { 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() { if s.Attr.Reachable() {
addsym(ctxt, s, "", DataSym, 0, nil) addsym(ctxt, s, "", DataSym, 0, nil)
} }
...@@ -704,7 +703,7 @@ func machoShouldExport(ctxt *Link, s *Symbol) bool { ...@@ -704,7 +703,7 @@ func machoShouldExport(ctxt *Link, s *Symbol) bool {
if strings.HasPrefix(s.Name, "go.link.pkghash") { if strings.HasPrefix(s.Name, "go.link.pkghash") {
return true return true
} }
return s.Type >= objabi.SELFSECT // only writable sections return s.Type >= SELFSECT // only writable sections
} }
func machosymtab(ctxt *Link) { func machosymtab(ctxt *Link) {
...@@ -732,7 +731,7 @@ func machosymtab(ctxt *Link) { ...@@ -732,7 +731,7 @@ func machosymtab(ctxt *Link) {
// replace "·" as ".", because DTrace cannot handle it. // replace "·" as ".", because DTrace cannot handle it.
Addstring(symstr, strings.Replace(s.Extname, "·", ".", -1)) 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, 0x01) // type N_EXT, external symbol
Adduint8(ctxt, symtab, 0) // no section Adduint8(ctxt, symtab, 0) // no section
Adduint16(ctxt, symtab, 0) // desc Adduint16(ctxt, symtab, 0) // desc
......
...@@ -158,7 +158,7 @@ func (r *objReader) readSym() { ...@@ -158,7 +158,7 @@ func (r *objReader) readSym() {
if c, err := r.rd.ReadByte(); c != symPrefix || err != nil { if c, err := r.rd.ReadByte(); c != symPrefix || err != nil {
log.Fatalln("readSym out of sync") log.Fatalln("readSym out of sync")
} }
t := objabi.SymKind(r.readInt()) t := abiSymKindToSymKind[r.readInt()]
s := r.readSymIndex() s := r.readSymIndex()
flags := r.readInt() flags := r.readInt()
dupok := flags&1 != 0 dupok := flags&1 != 0
...@@ -172,8 +172,8 @@ func (r *objReader) readSym() { ...@@ -172,8 +172,8 @@ func (r *objReader) readSym() {
isdup := false isdup := false
var dup *Symbol var dup *Symbol
if s.Type != 0 && s.Type != objabi.SXREF { if s.Type != 0 && s.Type != SXREF {
if (t == objabi.SDATA || t == objabi.SBSS || t == objabi.SNOPTRBSS) && len(data) == 0 && nreloc == 0 { if (t == SDATA || t == SBSS || t == SNOPTRBSS) && len(data) == 0 && nreloc == 0 {
if s.Size < int64(size) { if s.Size < int64(size) {
s.Size = int64(size) s.Size = int64(size)
} }
...@@ -183,10 +183,10 @@ func (r *objReader) readSym() { ...@@ -183,10 +183,10 @@ func (r *objReader) readSym() {
return 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 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) 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 len(s.P) > 0 {
...@@ -201,13 +201,13 @@ overwrite: ...@@ -201,13 +201,13 @@ overwrite:
if dupok { if dupok {
s.Attr |= AttrDuplicateOK s.Attr |= AttrDuplicateOK
} }
if t == objabi.SXREF { if t == SXREF {
log.Fatalf("bad sxref") log.Fatalf("bad sxref")
} }
if t == 0 { if t == 0 {
log.Fatalf("missing type for %s in %s", s.Name, r.pn) 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 t = s.Type
} }
s.Type = t s.Type = t
...@@ -240,7 +240,7 @@ overwrite: ...@@ -240,7 +240,7 @@ overwrite:
} }
} }
if s.Type == objabi.STEXT { if s.Type == STEXT {
s.FuncInfo = new(FuncInfo) s.FuncInfo = new(FuncInfo)
pc := s.FuncInfo pc := s.FuncInfo
...@@ -326,7 +326,7 @@ overwrite: ...@@ -326,7 +326,7 @@ overwrite:
} }
} }
} }
if s.Type == objabi.SDWARFINFO { if s.Type == SDWARFINFO {
r.patchDWARFName(s) r.patchDWARFName(s)
} }
} }
...@@ -389,7 +389,7 @@ func (r *objReader) readRef() { ...@@ -389,7 +389,7 @@ func (r *objReader) readRef() {
if err != nil { if err != nil {
log.Panicf("failed to parse $-symbol %s: %v", s.Name, err) log.Panicf("failed to parse $-symbol %s: %v", s.Name, err)
} }
s.Type = objabi.SRODATA s.Type = SRODATA
s.Attr |= AttrLocal s.Attr |= AttrLocal
switch s.Name[:5] { switch s.Name[:5] {
case "$f32.": case "$f32.":
......
...@@ -111,10 +111,10 @@ func ftabaddstring(ctxt *Link, ftab *Symbol, s string) int32 { ...@@ -111,10 +111,10 @@ func ftabaddstring(ctxt *Link, ftab *Symbol, s string) int32 {
// numberfile assigns a file number to the file if it hasn't been assigned already. // numberfile assigns a file number to the file if it hasn't been assigned already.
func numberfile(ctxt *Link, file *Symbol) { func numberfile(ctxt *Link, file *Symbol) {
if file.Type != objabi.SFILEPATH { if file.Type != SFILEPATH {
ctxt.Filesyms = append(ctxt.Filesyms, file) ctxt.Filesyms = append(ctxt.Filesyms, file)
file.Value = int64(len(ctxt.Filesyms)) file.Value = int64(len(ctxt.Filesyms))
file.Type = objabi.SFILEPATH file.Type = SFILEPATH
path := file.Name[len(src.FileSymPrefix):] path := file.Name[len(src.FileSymPrefix):]
file.Name = expandGoroot(path) file.Name = expandGoroot(path)
} }
...@@ -180,7 +180,7 @@ func container(s *Symbol) int { ...@@ -180,7 +180,7 @@ func container(s *Symbol) int {
} }
// We want to generate func table entries only for the "lowest level" symbols, // We want to generate func table entries only for the "lowest level" symbols,
// not containers of subsymbols. // not containers of subsymbols.
if s.Type&objabi.SCONTAINER != 0 { if s.Type&SCONTAINER != 0 {
return 1 return 1
} }
return 0 return 0
...@@ -201,7 +201,7 @@ var pclntabLastFunc *Symbol ...@@ -201,7 +201,7 @@ var pclntabLastFunc *Symbol
func (ctxt *Link) pclntab() { func (ctxt *Link) pclntab() {
funcdataBytes := int64(0) funcdataBytes := int64(0)
ftab := ctxt.Syms.Lookup("runtime.pclntab", 0) ftab := ctxt.Syms.Lookup("runtime.pclntab", 0)
ftab.Type = objabi.SPCLNTAB ftab.Type = SPCLNTAB
ftab.Attr |= AttrReachable ftab.Attr |= AttrReachable
// See golang.org/s/go12symtab for the format. Briefly: // See golang.org/s/go12symtab for the format. Briefly:
...@@ -215,7 +215,7 @@ func (ctxt *Link) pclntab() { ...@@ -215,7 +215,7 @@ func (ctxt *Link) pclntab() {
// Find container symbols, mark them with SCONTAINER // Find container symbols, mark them with SCONTAINER
for _, s := range ctxt.Textp { for _, s := range ctxt.Textp {
if s.Outer != nil { if s.Outer != nil {
s.Outer.Type |= objabi.SCONTAINER s.Outer.Type |= SCONTAINER
} }
} }
...@@ -334,7 +334,7 @@ func (ctxt *Link) pclntab() { ...@@ -334,7 +334,7 @@ func (ctxt *Link) pclntab() {
if len(pcln.InlTree) > 0 { if len(pcln.InlTree) > 0 {
inlTreeSym := ctxt.Syms.Lookup("inltree."+s.Name, 0) inlTreeSym := ctxt.Syms.Lookup("inltree."+s.Name, 0)
inlTreeSym.Type = objabi.SRODATA inlTreeSym.Type = SRODATA
inlTreeSym.Attr |= AttrReachable | AttrDuplicateOK inlTreeSym.Attr |= AttrReachable | AttrDuplicateOK
for i, call := range pcln.InlTree { for i, call := range pcln.InlTree {
...@@ -443,7 +443,7 @@ const ( ...@@ -443,7 +443,7 @@ const (
// function for a pc. See src/runtime/symtab.go:findfunc for details. // function for a pc. See src/runtime/symtab.go:findfunc for details.
func (ctxt *Link) findfunctab() { func (ctxt *Link) findfunctab() {
t := ctxt.Syms.Lookup("runtime.findfunctab", 0) t := ctxt.Syms.Lookup("runtime.findfunctab", 0)
t.Type = objabi.SRODATA t.Type = SRODATA
t.Attr |= AttrReachable t.Attr |= AttrReachable
t.Attr |= AttrLocal t.Attr |= AttrLocal
......
...@@ -460,8 +460,8 @@ func Peinit(ctxt *Link) { ...@@ -460,8 +460,8 @@ func Peinit(ctxt *Link) {
if Linkmode == LinkInternal { if Linkmode == LinkInternal {
// some mingw libs depend on this symbol, for example, FindPESectionByName // some mingw libs depend on this symbol, for example, FindPESectionByName
ctxt.xdefine("__image_base__", objabi.SDATA, PEBASE) ctxt.xdefine("__image_base__", SDATA, PEBASE)
ctxt.xdefine("_image_base__", objabi.SDATA, PEBASE) ctxt.xdefine("_image_base__", SDATA, PEBASE)
} }
HEADR = PEFILEHEADR HEADR = PEFILEHEADR
...@@ -516,7 +516,7 @@ func initdynimport(ctxt *Link) *Dll { ...@@ -516,7 +516,7 @@ func initdynimport(ctxt *Link) *Dll {
dr = nil dr = nil
var m *Imp var m *Imp
for _, s := range ctxt.Syms.Allsym { for _, s := range ctxt.Syms.Allsym {
if !s.Attr.Reachable() || s.Type != objabi.SDYNIMPORT { if !s.Attr.Reachable() || s.Type != SDYNIMPORT {
continue continue
} }
for d = dr; d != nil; d = d.next { for d = dr; d != nil; d = d.next {
...@@ -558,7 +558,7 @@ func initdynimport(ctxt *Link) *Dll { ...@@ -558,7 +558,7 @@ func initdynimport(ctxt *Link) *Dll {
// Add real symbol name // Add real symbol name
for d := dr; d != nil; d = d.next { for d := dr; d != nil; d = d.next {
for m = d.ms; m != nil; m = m.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)) Symgrow(m.s, int64(SysArch.PtrSize))
dynName := m.s.Extname dynName := m.s.Extname
// only windows/386 requires stdcall decoration // only windows/386 requires stdcall decoration
...@@ -567,7 +567,7 @@ func initdynimport(ctxt *Link) *Dll { ...@@ -567,7 +567,7 @@ func initdynimport(ctxt *Link) *Dll {
} }
dynSym := ctxt.Syms.Lookup(dynName, 0) dynSym := ctxt.Syms.Lookup(dynName, 0)
dynSym.Attr |= AttrReachable dynSym.Attr |= AttrReachable
dynSym.Type = objabi.SHOSTOBJ dynSym.Type = SHOSTOBJ
r := Addrel(m.s) r := Addrel(m.s)
r.Sym = dynSym r.Sym = dynSym
r.Off = 0 r.Off = 0
...@@ -578,10 +578,10 @@ func initdynimport(ctxt *Link) *Dll { ...@@ -578,10 +578,10 @@ func initdynimport(ctxt *Link) *Dll {
} else { } else {
dynamic := ctxt.Syms.Lookup(".windynamic", 0) dynamic := ctxt.Syms.Lookup(".windynamic", 0)
dynamic.Attr |= AttrReachable dynamic.Attr |= AttrReachable
dynamic.Type = objabi.SWINDOWS dynamic.Type = SWINDOWS
for d := dr; d != nil; d = d.next { for d := dr; d != nil; d = d.next {
for m = d.ms; m != nil; m = m.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 m.s.Sub = dynamic.Sub
dynamic.Sub = m.s dynamic.Sub = m.s
m.s.Value = dynamic.Size m.s.Value = dynamic.Size
...@@ -936,7 +936,7 @@ func (ctxt *Link) dope() { ...@@ -936,7 +936,7 @@ func (ctxt *Link) dope() {
rel := ctxt.Syms.Lookup(".rel", 0) rel := ctxt.Syms.Lookup(".rel", 0)
rel.Attr |= AttrReachable rel.Attr |= AttrReachable
rel.Type = objabi.SELFROSECT rel.Type = SELFROSECT
initdynimport(ctxt) initdynimport(ctxt)
initdynexport(ctxt) initdynexport(ctxt)
...@@ -1009,7 +1009,7 @@ func writePESymTableRecords(ctxt *Link) int { ...@@ -1009,7 +1009,7 @@ func writePESymTableRecords(ctxt *Link) int {
// Only windows/386 requires underscore prefix on external symbols. // Only windows/386 requires underscore prefix on external symbols.
if SysArch.Family == sys.I386 && if SysArch.Family == sys.I386 &&
Linkmode == LinkExternal && Linkmode == LinkExternal &&
(s.Type == objabi.SHOSTOBJ || s.Attr.CgoExport()) { (s.Type == SHOSTOBJ || s.Attr.CgoExport()) {
s.Name = "_" + s.Name s.Name = "_" + s.Name
} }
...@@ -1020,10 +1020,10 @@ func writePESymTableRecords(ctxt *Link) int { ...@@ -1020,10 +1020,10 @@ func writePESymTableRecords(ctxt *Link) int {
// it still belongs to the .data section, not the .bss section. // it still belongs to the .data section, not the .bss section.
// Same for runtime.epclntab (type STEXT), it belongs to .text // Same for runtime.epclntab (type STEXT), it belongs to .text
// section, not the .data section. // 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) value = int64(uint64(s.Value) - Segdata.Vaddr - Segdata.Filelen)
sect = bsssect 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) value = int64(uint64(s.Value) - Segdata.Vaddr)
sect = datasect sect = datasect
} else if uint64(s.Value) >= Segtext.Vaddr { } else if uint64(s.Value) >= Segtext.Vaddr {
...@@ -1041,7 +1041,7 @@ func writePESymTableRecords(ctxt *Link) int { ...@@ -1041,7 +1041,7 @@ func writePESymTableRecords(ctxt *Link) int {
typ = 0x0308 // "array of structs" typ = 0x0308 // "array of structs"
} }
class := IMAGE_SYM_CLASS_EXTERNAL 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 class = IMAGE_SYM_CLASS_STATIC
} }
writeOneSymbol(s, value, sect, typ, uint8(class)) writeOneSymbol(s, value, sect, typ, uint8(class))
......
// 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,
}
// 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]]
}
This diff is collapsed.
...@@ -33,7 +33,7 @@ func (ctxt *Link) typelink() { ...@@ -33,7 +33,7 @@ func (ctxt *Link) typelink() {
sort.Sort(typelinks) sort.Sort(typelinks)
tl := ctxt.Syms.Lookup("runtime.typelink", 0) tl := ctxt.Syms.Lookup("runtime.typelink", 0)
tl.Type = objabi.STYPELINK tl.Type = STYPELINK
tl.Attr |= AttrReachable | AttrLocal tl.Attr |= AttrReachable | AttrLocal
tl.Size = int64(4 * len(typelinks)) tl.Size = int64(4 * len(typelinks))
tl.P = make([]byte, tl.Size) tl.P = make([]byte, tl.Size)
......
...@@ -114,7 +114,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -114,7 +114,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
rs = rs.Outer 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) ld.Errorf(s, "missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
......
...@@ -120,7 +120,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -120,7 +120,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
rs = rs.Outer 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) ld.Errorf(s, "missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
......
...@@ -91,7 +91,7 @@ func genplt(ctxt *ld.Link) { ...@@ -91,7 +91,7 @@ func genplt(ctxt *ld.Link) {
for _, s := range ctxt.Textp { for _, s := range ctxt.Textp {
for i := range s.R { for i := range s.R {
r := &s.R[i] 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 continue
} }
...@@ -131,12 +131,12 @@ func genplt(ctxt *ld.Link) { ...@@ -131,12 +131,12 @@ func genplt(ctxt *ld.Link) {
func genaddmoduledata(ctxt *ld.Link) { func genaddmoduledata(ctxt *ld.Link) {
addmoduledata := ctxt.Syms.ROLookup("runtime.addmoduledata", 0) addmoduledata := ctxt.Syms.ROLookup("runtime.addmoduledata", 0)
if addmoduledata.Type == objabi.STEXT { if addmoduledata.Type == ld.STEXT {
return return
} }
addmoduledata.Attr |= ld.AttrReachable addmoduledata.Attr |= ld.AttrReachable
initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0) initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0)
initfunc.Type = objabi.STEXT initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable initfunc.Attr |= ld.AttrReachable
o := func(op uint32) { o := func(op uint32) {
...@@ -186,7 +186,7 @@ func genaddmoduledata(ctxt *ld.Link) { ...@@ -186,7 +186,7 @@ func genaddmoduledata(ctxt *ld.Link) {
ctxt.Textp = append(ctxt.Textp, initfunc) ctxt.Textp = append(ctxt.Textp, initfunc)
initarray_entry.Attr |= ld.AttrReachable initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Type = objabi.SINITARR initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc) ld.Addaddr(ctxt, initarray_entry, initfunc)
} }
...@@ -211,7 +211,7 @@ func gencallstub(ctxt *ld.Link, abicase int, stub *ld.Symbol, targ *ld.Symbol) { ...@@ -211,7 +211,7 @@ func gencallstub(ctxt *ld.Link, abicase int, stub *ld.Symbol, targ *ld.Symbol) {
plt := ctxt.Syms.Lookup(".plt", 0) plt := ctxt.Syms.Lookup(".plt", 0)
stub.Type = objabi.STEXT stub.Type = ld.STEXT
// Save TOC pointer in TOC save slot // Save TOC pointer in TOC save slot
ld.Adduint32(ctxt, stub, 0xf8410018) // std r2,24(r1) ld.Adduint32(ctxt, stub, 0xf8410018) // std r2,24(r1)
...@@ -267,7 +267,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -267,7 +267,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
// to use r12 to compute r2.) // to use r12 to compute r2.)
r.Add += int64(r.Sym.Localentry) * 4 r.Add += int64(r.Sym.Localentry) * 4
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
// Should have been handled in elfsetupplt // Should have been handled in elfsetupplt
ld.Errorf(s, "unexpected R_PPC64_REL24 for dyn import") ld.Errorf(s, "unexpected R_PPC64_REL24 for dyn import")
} }
...@@ -278,7 +278,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -278,7 +278,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
r.Type = objabi.R_PCREL r.Type = objabi.R_PCREL
r.Add += 4 r.Add += 4
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
ld.Errorf(s, "unexpected R_PPC_REL32 for dyn import") ld.Errorf(s, "unexpected R_PPC_REL32 for dyn import")
} }
...@@ -286,7 +286,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -286,7 +286,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_PPC64_ADDR64: case 256 + ld.R_PPC64_ADDR64:
r.Type = objabi.R_ADDR r.Type = objabi.R_ADDR
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
// These happen in .toc sections // These happen in .toc sections
ld.Adddynsym(ctxt, targ) ld.Adddynsym(ctxt, targ)
...@@ -349,7 +349,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -349,7 +349,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
} }
// Handle references to ELF symbols from our own object files. // Handle references to ELF symbols from our own object files.
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
return true return true
} }
...@@ -611,7 +611,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { ...@@ -611,7 +611,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
rs = rs.Outer 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) ld.Errorf(s, "missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
......
...@@ -52,14 +52,14 @@ func gentext(ctxt *ld.Link) { ...@@ -52,14 +52,14 @@ func gentext(ctxt *ld.Link) {
return return
} }
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0) 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 // we're linking a module containing the runtime -> no need for
// an init function // an init function
return return
} }
addmoduledata.Attr |= ld.AttrReachable addmoduledata.Attr |= ld.AttrReachable
initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0) initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0)
initfunc.Type = objabi.STEXT initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable initfunc.Attr |= ld.AttrReachable
...@@ -96,7 +96,7 @@ func gentext(ctxt *ld.Link) { ...@@ -96,7 +96,7 @@ func gentext(ctxt *ld.Link) {
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0) initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrLocal initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Attr |= ld.AttrReachable initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Type = objabi.SINITARR initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc) ld.Addaddr(ctxt, initarray_entry, initfunc)
} }
...@@ -120,7 +120,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -120,7 +120,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
256 + ld.R_390_16, 256 + ld.R_390_16,
256 + ld.R_390_32, 256 + ld.R_390_32,
256 + ld.R_390_64: 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) ld.Errorf(s, "unexpected R_390_nn relocation for dynamic symbol %s", targ.Name)
} }
r.Type = objabi.R_ADDR r.Type = objabi.R_ADDR
...@@ -129,10 +129,10 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -129,10 +129,10 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_390_PC16, case 256 + ld.R_390_PC16,
256 + ld.R_390_PC32, 256 + ld.R_390_PC32,
256 + ld.R_390_PC64: 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) 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) ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
} }
r.Type = objabi.R_PCREL r.Type = objabi.R_PCREL
...@@ -150,7 +150,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -150,7 +150,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
r.Type = objabi.R_PCREL r.Type = objabi.R_PCREL
r.Variant = ld.RV_390_DBL r.Variant = ld.RV_390_DBL
r.Add += int64(r.Siz) r.Add += int64(r.Siz)
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add += int64(targ.Plt) r.Add += int64(targ.Plt)
...@@ -161,7 +161,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -161,7 +161,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
256 + ld.R_390_PLT64: 256 + ld.R_390_PLT64:
r.Type = objabi.R_PCREL r.Type = objabi.R_PCREL
r.Add += int64(r.Siz) r.Add += int64(r.Siz)
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add += int64(targ.Plt) r.Add += int64(targ.Plt)
...@@ -185,7 +185,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -185,7 +185,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return false return false
case 256 + ld.R_390_GOTOFF: 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) ld.Errorf(s, "unexpected R_390_GOTOFF relocation for dynamic symbol %s", targ.Name)
} }
r.Type = objabi.R_GOTOFF r.Type = objabi.R_GOTOFF
...@@ -202,7 +202,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -202,7 +202,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
r.Type = objabi.R_PCREL r.Type = objabi.R_PCREL
r.Variant = ld.RV_390_DBL r.Variant = ld.RV_390_DBL
r.Add += int64(r.Siz) 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) ld.Errorf(s, "unexpected R_390_PCnnDBL relocation for dynamic symbol %s", targ.Name)
} }
return true return true
...@@ -225,7 +225,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -225,7 +225,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
} }
// Handle references to ELF symbols from our own object files. // Handle references to ELF symbols from our own object files.
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
return true return true
} }
...@@ -286,7 +286,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -286,7 +286,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
case objabi.R_PCRELDBL, objabi.R_CALL: case objabi.R_PCRELDBL, objabi.R_CALL:
isdbl = true 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 { if isdbl {
switch r.Siz { switch r.Siz {
case 2: case 2:
......
...@@ -81,7 +81,7 @@ func gentext(ctxt *ld.Link) { ...@@ -81,7 +81,7 @@ func gentext(ctxt *ld.Link) {
{"di", 7}, {"di", 7},
} { } {
thunkfunc := ctxt.Syms.Lookup("__x86.get_pc_thunk."+r.name, 0) 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.AttrLocal
thunkfunc.Attr |= ld.AttrReachable //TODO: remove? thunkfunc.Attr |= ld.AttrReachable //TODO: remove?
o := func(op ...uint8) { o := func(op ...uint8) {
...@@ -100,7 +100,7 @@ func gentext(ctxt *ld.Link) { ...@@ -100,7 +100,7 @@ func gentext(ctxt *ld.Link) {
ctxt.Textp = append(thunks, ctxt.Textp...) // keep Textp in dependency order ctxt.Textp = append(thunks, ctxt.Textp...) // keep Textp in dependency order
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0) 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 // we're linking a module containing the runtime -> no need for
// an init function // an init function
return return
...@@ -109,7 +109,7 @@ func gentext(ctxt *ld.Link) { ...@@ -109,7 +109,7 @@ func gentext(ctxt *ld.Link) {
addmoduledata.Attr |= ld.AttrReachable addmoduledata.Attr |= ld.AttrReachable
initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0) initfunc := ctxt.Syms.Lookup("go.link.addmoduledata", 0)
initfunc.Type = objabi.STEXT initfunc.Type = ld.STEXT
initfunc.Attr |= ld.AttrLocal initfunc.Attr |= ld.AttrLocal
initfunc.Attr |= ld.AttrReachable initfunc.Attr |= ld.AttrReachable
o := func(op ...uint8) { o := func(op ...uint8) {
...@@ -160,7 +160,7 @@ func gentext(ctxt *ld.Link) { ...@@ -160,7 +160,7 @@ func gentext(ctxt *ld.Link) {
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0) initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= ld.AttrReachable initarray_entry.Attr |= ld.AttrReachable
initarray_entry.Attr |= ld.AttrLocal initarray_entry.Attr |= ld.AttrLocal
initarray_entry.Type = objabi.SINITARR initarray_entry.Type = ld.SINITARR
ld.Addaddr(ctxt, initarray_entry, initfunc) ld.Addaddr(ctxt, initarray_entry, initfunc)
} }
...@@ -176,10 +176,10 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -176,10 +176,10 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
// Handle relocations found in ELF object files. // Handle relocations found in ELF object files.
case 256 + ld.R_386_PC32: 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) 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) ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
} }
r.Type = objabi.R_PCREL r.Type = objabi.R_PCREL
...@@ -189,7 +189,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -189,7 +189,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 256 + ld.R_386_PLT32: case 256 + ld.R_386_PLT32:
r.Type = objabi.R_PCREL r.Type = objabi.R_PCREL
r.Add += 4 r.Add += 4
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add += int64(targ.Plt) r.Add += int64(targ.Plt)
...@@ -198,7 +198,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -198,7 +198,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case 256 + ld.R_386_GOT32, 256 + ld.R_386_GOT32X: case 256 + ld.R_386_GOT32, 256 + ld.R_386_GOT32X:
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
// have symbol // have symbol
if r.Off >= 2 && s.P[r.Off-2] == 0x8b { if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
// turn MOVL of GOT entry into LEAL of symbol address, relative to GOT. // turn MOVL of GOT entry into LEAL of symbol address, relative to GOT.
...@@ -239,7 +239,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -239,7 +239,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case 256 + ld.R_386_32: 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) ld.Errorf(s, "unexpected R_386_32 relocation for dynamic symbol %s", targ.Name)
} }
r.Type = objabi.R_ADDR r.Type = objabi.R_ADDR
...@@ -247,13 +247,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -247,13 +247,13 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
case 512 + ld.MACHO_GENERIC_RELOC_VANILLA*2 + 0: case 512 + ld.MACHO_GENERIC_RELOC_VANILLA*2 + 0:
r.Type = objabi.R_ADDR 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) ld.Errorf(s, "unexpected reloc for dynamic symbol %s", targ.Name)
} }
return true return true
case 512 + ld.MACHO_GENERIC_RELOC_VANILLA*2 + 1: case 512 + ld.MACHO_GENERIC_RELOC_VANILLA*2 + 1:
if targ.Type == objabi.SDYNIMPORT { if targ.Type == ld.SDYNIMPORT {
addpltsym(ctxt, targ) addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0) r.Sym = ctxt.Syms.Lookup(".plt", 0)
r.Add = int64(targ.Plt) r.Add = int64(targ.Plt)
...@@ -265,7 +265,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -265,7 +265,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case 512 + ld.MACHO_FAKE_GOTPCREL: case 512 + ld.MACHO_FAKE_GOTPCREL:
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
// have symbol // have symbol
// turn MOVL of GOT entry into LEAL of symbol itself // turn MOVL of GOT entry into LEAL of symbol itself
if r.Off < 2 || s.P[r.Off-2] != 0x8b { if r.Off < 2 || s.P[r.Off-2] != 0x8b {
...@@ -286,7 +286,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -286,7 +286,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
} }
// Handle references to ELF symbols from our own object files. // Handle references to ELF symbols from our own object files.
if targ.Type != objabi.SDYNIMPORT { if targ.Type != ld.SDYNIMPORT {
return true return true
} }
switch r.Type { switch r.Type {
...@@ -298,7 +298,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -298,7 +298,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
return true return true
case objabi.R_ADDR: case objabi.R_ADDR:
if s.Type != objabi.SDATA { if s.Type != ld.SDATA {
break break
} }
if ld.Iself { if ld.Iself {
...@@ -325,7 +325,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { ...@@ -325,7 +325,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
ld.Adddynsym(ctxt, targ) ld.Adddynsym(ctxt, targ)
got := ctxt.Syms.Lookup(".got", 0) got := ctxt.Syms.Lookup(".got", 0)
s.Type = got.Type | objabi.SSUB s.Type = got.Type | ld.SSUB
s.Outer = got s.Outer = got
s.Sub = got.Sub s.Sub = got.Sub
got.Sub = s got.Sub = s
...@@ -373,7 +373,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { ...@@ -373,7 +373,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
case objabi.R_CALL: case objabi.R_CALL:
if r.Siz == 4 { 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) ld.Thearch.Lput(ld.R_386_PLT32 | uint32(elfsym)<<8)
} else { } else {
ld.Thearch.Lput(ld.R_386_PC32 | uint32(elfsym)<<8) ld.Thearch.Lput(ld.R_386_PC32 | uint32(elfsym)<<8)
...@@ -414,7 +414,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { ...@@ -414,7 +414,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
rs := r.Xsym rs := r.Xsym
if rs.Type == objabi.SHOSTOBJ { if rs.Type == ld.SHOSTOBJ {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Errorf(s, "reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment