return true
case objabi.R_ADDR:
- if s.Type == sym.STEXT && ld.Iself {
+ if s.Type == sym.STEXT && ctxt.IsELF {
if ld.Headtype == objabi.Hsolaris {
addpltsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".plt", 0)
}
}
- if ld.Iself {
+ if ctxt.IsELF {
// TODO: We generate a R_X86_64_64 relocation for every R_ADDR, even
// though it would be more efficient (for the dynamic linker) if we
// generated R_X86_RELATIVE instead.
ld.Adddynsym(ctxt, s)
- if ld.Iself {
+ if ctxt.IsELF {
plt := ctxt.Syms.Lookup(".plt", 0)
got := ctxt.Syms.Lookup(".got.plt", 0)
rela := ctxt.Syms.Lookup(".rela.plt", 0)
s.Got = int32(got.Size)
got.AddUint64(ctxt.Arch, 0)
- if ld.Iself {
+ if ctxt.IsELF {
rela := ctxt.Syms.Lookup(".rela", 0)
rela.AddAddrPlus(ctxt.Arch, got, int64(s.Got))
rela.AddUint64(ctxt.Arch, ld.ELF64_R_INFO(uint32(s.Dynid), uint32(elf.R_X86_64_GLOB_DAT)))
ctxt.Logf("%5.2f codeblk\n", ld.Cputime())
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Asmbelfsetup()
}
ctxt.Out.SeekSet(symo)
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
ctxt.Out.SeekSet(symo)
ld.Asmelfsym(ctxt)
ctxt.Out.Flush()
if s.Type != sym.SDATA {
break
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Adddynsym(ctxt, targ)
rel := ctxt.Syms.Lookup(".rel", 0)
rel.AddAddrPlus(ctxt.Arch, s, int64(r.Off))
ld.Adddynsym(ctxt, s)
- if ld.Iself {
+ if ctxt.IsELF {
plt := ctxt.Syms.Lookup(".plt", 0)
got := ctxt.Syms.Lookup(".got.plt", 0)
rel := ctxt.Syms.Lookup(".rel.plt", 0)
got.AddAddrPlus(ctxt.Arch, s, 0)
- if ld.Iself {
+ if ctxt.IsELF {
} else {
ld.Errorf(s, "addgotsyminternal: unsupported binary format")
}
s.Got = int32(got.Size)
got.AddUint32(ctxt.Arch, 0)
- if ld.Iself {
+ if ctxt.IsELF {
rel := ctxt.Syms.Lookup(".rel", 0)
rel.AddAddrPlus(ctxt.Arch, got, int64(s.Got))
rel.AddUint32(ctxt.Arch, ld.ELF32_R_INFO(uint32(s.Dynid), uint32(elf.R_ARM_GLOB_DAT)))
ctxt.Logf("%5.2f asmb\n", ld.Cputime())
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Asmbelfsetup()
}
}
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
ctxt.Out.SeekSet(int64(symo))
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f elfsym\n", ld.Cputime())
}
ctxt.Logf("%5.2f asmb\n", ld.Cputime())
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Asmbelfsetup()
}
}
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
ctxt.Out.SeekSet(int64(symo))
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f elfsym\n", ld.Cputime())
}
case objabi.R_TLS_LE:
isAndroidX86 := objabi.GOOS == "android" && (ctxt.Arch.InFamily(sys.AMD64, sys.I386))
- if ctxt.LinkMode == LinkExternal && Iself && !isAndroidX86 {
+ if ctxt.LinkMode == LinkExternal && ctxt.IsELF && !isAndroidX86 {
r.Done = false
if r.Sym == nil {
r.Sym = ctxt.Tlsg
break
}
- if Iself && ctxt.Arch.Family == sys.ARM {
+ if ctxt.IsELF && ctxt.Arch.Family == sys.ARM {
// On ELF ARM, the thread pointer is 8 bytes before
// the start of the thread-local data block, so add 8
// to the actual TLS offset (r->sym->value).
// related to the fact that our own TLS storage happens
// to take up 8 bytes.
o = 8 + r.Sym.Value
- } else if Iself || Headtype == objabi.Hplan9 || Headtype == objabi.Hdarwin || isAndroidX86 {
+ } else if ctxt.IsELF || Headtype == objabi.Hplan9 || Headtype == objabi.Hdarwin || isAndroidX86 {
o = int64(ctxt.Tlsoffset) + r.Add
} else if Headtype == objabi.Hwindows {
o = r.Add
case objabi.R_TLS_IE:
isAndroidX86 := objabi.GOOS == "android" && (ctxt.Arch.InFamily(sys.AMD64, sys.I386))
- if ctxt.LinkMode == LinkExternal && Iself && !isAndroidX86 {
+ if ctxt.LinkMode == LinkExternal && ctxt.IsELF && !isAndroidX86 {
r.Done = false
if r.Sym == nil {
r.Sym = ctxt.Tlsg
}
break
}
- if ctxt.BuildMode == BuildModePIE && Iself {
+ if ctxt.BuildMode == BuildModePIE && ctxt.IsELF {
// We are linking the final executable, so we
// can optimize any TLS IE relocation to LE.
if Thearch.TLSIEtoLE == nil {
r.Xsym = rs
o = r.Xadd
- if Iself {
+ if ctxt.IsELF {
if ctxt.Arch.Family == sys.AMD64 {
o = 0
}
r.Xadd = r.Add + Symaddr(r.Sym) - int64(r.Sym.Sect.Vaddr)
o = r.Xadd
- if Iself && ctxt.Arch.Family == sys.AMD64 {
+ if ctxt.IsELF && ctxt.Arch.Family == sys.AMD64 {
o = 0
}
break
r.Xsym = rs
o = r.Xadd
- if Iself {
+ if ctxt.IsELF {
if ctxt.Arch.Family == sys.AMD64 {
o = 0
}
dynrelocsym(ctxt, s)
}
}
- if Iself {
+ if ctxt.IsELF {
elfdynhash(ctxt)
}
}
if len(data[sym.STLSBSS]) > 0 {
var sect *sym.Section
- if Iself && (ctxt.LinkMode == LinkExternal || !*FlagD) {
+ if ctxt.IsELF && (ctxt.LinkMode == LinkExternal || !*FlagD) {
sect = addsection(ctxt.Arch, &Segdata, ".tbss", 06)
sect.Align = int32(ctxt.Arch.PtrSize)
sect.Vaddr = 0
* segtext.
*/
var segro *sym.Segment
- if Iself && ctxt.LinkMode == LinkInternal {
+ if ctxt.IsELF && ctxt.LinkMode == LinkInternal {
segro = &Segrodata
} else {
segro = &Segtext
syms[len(syms)-1] = tail
}
- if Iself && symn == sym.SELFROSECT {
+ if ctxt.IsELF && symn == sym.SELFROSECT {
// Make .rela and .rela.plt contiguous, the ELF ABI requires this
// and Solaris actually cares.
reli, plti := -1, -1
// at the very beginning of the text segment.
// This ``header'' is read by cmd/go.
func (ctxt *Link) textbuildid() {
- if Iself || ctxt.BuildMode == BuildModePlugin || *flagBuildid == "" {
+ if ctxt.IsELF || ctxt.BuildMode == BuildModePlugin || *flagBuildid == "" {
return
}
// Only break at outermost syms.
- if ctxt.Arch.InFamily(sys.PPC64) && s.Outer == nil && Iself && ctxt.LinkMode == LinkExternal && va-sect.Vaddr+funcsize+maxSizeTrampolinesPPC64(s, isTramp) > 0x1c00000 {
+ if ctxt.Arch.InFamily(sys.PPC64) && s.Outer == nil && ctxt.IsELF && ctxt.LinkMode == LinkExternal && va-sect.Vaddr+funcsize+maxSizeTrampolinesPPC64(s, isTramp) > 0x1c00000 {
// Set the length for the previous text section
sect.Length = va - sect.Vaddr
var bss *sym.Section
var noptrbss *sym.Section
for i, s := range Segdata.Sections {
- if Iself && s.Name == ".tbss" {
+ if ctxt.IsELF && s.Name == ".tbss" {
continue
}
vlen := int64(s.Length)
- if i+1 < len(Segdata.Sections) && !(Iself && Segdata.Sections[i+1].Name == ".tbss") {
+ if i+1 < len(Segdata.Sections) && !(ctxt.IsELF && Segdata.Sections[i+1].Name == ".tbss") {
vlen = int64(Segdata.Sections[i+1].Vaddr - s.Vaddr)
}
s.Vaddr = va
if ctxt.LinkMode == LinkExternal {
switch {
- case Iself:
+ case ctxt.IsELF:
case Headtype == objabi.Hdarwin:
case Headtype == objabi.Hwindows:
default:
)
var (
- Iself bool
-
Nelfsym = 1
elf64 bool
we write section and prog headers.
*/
func Elfinit(ctxt *Link) {
- Iself = true
+ ctxt.IsELF = true
if ctxt.Arch.InFamily(sys.AMD64, sys.ARM64, sys.MIPS64, sys.PPC64, sys.S390X) {
elfRelType = ".rela"
}
func elfdynhash(ctxt *Link) {
- if !Iself {
+ if !ctxt.IsELF {
return
}
}
func (ctxt *Link) doelf() {
- if !Iself {
+ if !ctxt.IsELF {
return
}
}
seenlib[lib] = true
- if Iself {
+ if ctxt.IsELF {
s := ctxt.Syms.Lookup(".dynstr", 0)
if s.Size == 0 {
Addstring(s, "")
return
}
- if Iself {
+ if ctxt.IsELF {
elfadddynsym(ctxt, s)
} else if Headtype == objabi.Hdarwin {
Errorf(s, "adddynsym: missed symbol (Extname=%s)", s.Extname)
func (ctxt *Link) UseRelro() bool {
switch ctxt.BuildMode {
case BuildModeCArchive, BuildModeCShared, BuildModeShared, BuildModePIE, BuildModePlugin:
- return Iself
+ return ctxt.IsELF
default:
return ctxt.linkShared
}
}
if ctxt.Arch == sys.Arch386 {
- if (ctxt.BuildMode == BuildModeCArchive && Iself) || (ctxt.BuildMode == BuildModeCShared && Headtype != objabi.Hwindows) || ctxt.BuildMode == BuildModePIE || ctxt.DynlinkingGo() {
+ if (ctxt.BuildMode == BuildModeCArchive && ctxt.IsELF) || (ctxt.BuildMode == BuildModeCShared && Headtype != objabi.Hwindows) || ctxt.BuildMode == BuildModePIE || ctxt.DynlinkingGo() {
got := ctxt.Syms.Lookup("_GLOBAL_OFFSET_TABLE_", 0)
got.Type = sym.SDYNIMPORT
got.Attr |= sym.AttrReachable
}
}
- if Iself && ctxt.DynlinkingGo() {
+ if ctxt.IsELF && ctxt.DynlinkingGo() {
// We force all symbol resolution to be done at program startup
// because lazy PLT resolution can use large amounts of stack at
// times we cannot allow it to do so.
}
}
- if Iself && len(buildinfo) > 0 {
+ if ctxt.IsELF && len(buildinfo) > 0 {
argv = append(argv, fmt.Sprintf("-Wl,--build-id=0x%x", buildinfo))
}
}
// Force global symbols to be exported for dlopen, etc.
- if Iself {
+ if ctxt.IsELF {
argv = append(argv, "-rdynamic")
}
// we added it. We do it in this order, rather than
// only adding -rdynamic later, so that -*extldflags
// can override -rdynamic without using -static.
- if Iself && p == "-static" {
+ if ctxt.IsELF && p == "-static" {
for i := range argv {
if argv[i] == "-rdynamic" {
argv[i] = "-static"
put(ctxt, s, s.Name, BSSSym, Symaddr(s), s.Gotype)
case sym.SHOSTOBJ:
- if Headtype == objabi.Hwindows || Iself {
+ if Headtype == objabi.Hwindows || ctxt.IsELF {
put(ctxt, s, s.Name, UndefinedSym, s.Value, nil)
}
Loaded bool // set after all inputs have been loaded as symbols
+ IsELF bool
+
linkShared bool // link against installed Go shared libraries
LinkMode LinkMode
BuildMode BuildMode
ctxt.computeTLSOffset()
Thearch.Archinit(ctxt)
- if ctxt.linkShared && !Iself {
+ if ctxt.linkShared && !ctxt.IsELF {
Exitf("-linkshared can only be used on elf systems")
}
ctxt.Logf("%5.2f asmb\n", ld.Cputime())
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Asmbelfsetup()
}
ld.Lcsize = 0
symo := uint32(0)
if !*ld.FlagS {
- if !ld.Iself {
+ if !ctxt.IsELF {
ld.Errorf(nil, "unsupported executable format")
}
if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f asmb\n", ld.Cputime())
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Asmbelfsetup()
}
}
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
ctxt.Out.SeekSet(int64(symo))
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f elfsym\n", ld.Cputime())
}
ld.Adddynsym(ctxt, s)
- if ld.Iself {
+ if ctxt.IsELF {
plt := ctxt.Syms.Lookup(".plt", 0)
rela := ctxt.Syms.Lookup(".rela.plt", 0)
if plt.Size == 0 {
ctxt.Logf("%5.2f asmb\n", ld.Cputime())
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Asmbelfsetup()
}
}
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
ctxt.Out.SeekSet(int64(symo))
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f elfsym\n", ld.Cputime())
}
ld.Adddynsym(ctxt, s)
- if ld.Iself {
+ if ctxt.IsELF {
plt := ctxt.Syms.Lookup(".plt", 0)
got := ctxt.Syms.Lookup(".got", 0)
rela := ctxt.Syms.Lookup(".rela.plt", 0)
s.Got = int32(got.Size)
got.AddUint64(ctxt.Arch, 0)
- if ld.Iself {
+ if ctxt.IsELF {
rela := ctxt.Syms.Lookup(".rela", 0)
rela.AddAddrPlus(ctxt.Arch, got, int64(s.Got))
rela.AddUint64(ctxt.Arch, ld.ELF64_R_INFO(uint32(s.Dynid), uint32(elf.R_390_GLOB_DAT)))
ctxt.Logf("%5.2f asmb\n", ld.Cputime())
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Asmbelfsetup()
}
ld.Lcsize = 0
symo := uint32(0)
if !*ld.FlagS {
- if !ld.Iself {
+ if !ctxt.IsELF {
ld.Errorf(nil, "unsupported executable format")
}
if ctxt.Debugvlog != 0 {
} else {
switch ctxt.BuildMode {
case ld.BuildModeCArchive:
- if !ld.Iself {
+ if !ctxt.IsELF {
return
}
case ld.BuildModePIE, ld.BuildModeCShared, ld.BuildModePlugin:
if s.Type != sym.SDATA {
break
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Adddynsym(ctxt, targ)
rel := ctxt.Syms.Lookup(".rel", 0)
rel.AddAddrPlus(ctxt.Arch, s, int64(r.Off))
ld.Adddynsym(ctxt, s)
- if ld.Iself {
+ if ctxt.IsELF {
plt := ctxt.Syms.Lookup(".plt", 0)
got := ctxt.Syms.Lookup(".got.plt", 0)
rel := ctxt.Syms.Lookup(".rel.plt", 0)
s.Got = int32(got.Size)
got.AddUint32(ctxt.Arch, 0)
- if ld.Iself {
+ if ctxt.IsELF {
rel := ctxt.Syms.Lookup(".rel", 0)
rel.AddAddrPlus(ctxt.Arch, got, int64(s.Got))
rel.AddUint32(ctxt.Arch, ld.ELF32_R_INFO(uint32(s.Dynid), uint32(elf.R_386_GLOB_DAT)))
ctxt.Logf("%5.2f asmb\n", ld.Cputime())
}
- if ld.Iself {
+ if ctxt.IsELF {
ld.Asmbelfsetup()
}
}
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
ctxt.Out.SeekSet(int64(symo))
switch ld.Headtype {
default:
- if ld.Iself {
+ if ctxt.IsELF {
if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f elfsym\n", ld.Cputime())
}