Commit fa8a28d5 authored by Michael Matloob's avatar Michael Matloob

cmd/link: turn some globals into flag pointer variables

This moves many of the flag globals into main and assigns them
to their flag.String/Int64/... directly.

Updates #16818

Change-Id: Ibbff44a273bbc5cb7228e43f147900ee8848517f
Reviewed-on: https://go-review.googlesource.com/27473Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent 23690138
......@@ -657,7 +657,7 @@ func asmb(ctxt *ld.Link) {
break
case obj.Hdarwin:
ld.Debug['8'] = true /* 64-bit addresses */
ld.Flag8 = true /* 64-bit addresses */
case obj.Hlinux,
obj.Hfreebsd,
......@@ -665,7 +665,7 @@ func asmb(ctxt *ld.Link) {
obj.Hopenbsd,
obj.Hdragonfly,
obj.Hsolaris:
ld.Debug['8'] = true /* 64-bit addresses */
ld.Flag8 = true /* 64-bit addresses */
case obj.Hnacl,
obj.Hwindows:
......@@ -676,7 +676,7 @@ func asmb(ctxt *ld.Link) {
ld.Spsize = 0
ld.Lcsize = 0
symo := int64(0)
if !ld.Debug['s'] {
if !*ld.FlagS {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
}
......@@ -684,11 +684,11 @@ func asmb(ctxt *ld.Link) {
switch ld.HEADTYPE {
default:
case obj.Hplan9:
ld.Debug['s'] = true
*ld.FlagS = true
symo = int64(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case obj.Hdarwin:
symo = int64(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(ld.INITRND))) + uint64(machlink))
symo = int64(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(*ld.FlagRound))) + uint64(machlink))
case obj.Hlinux,
obj.Hfreebsd,
......@@ -698,7 +698,7 @@ func asmb(ctxt *ld.Link) {
obj.Hsolaris,
obj.Hnacl:
symo = int64(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = ld.Rnd(symo, int64(ld.INITRND))
symo = ld.Rnd(symo, int64(*ld.FlagRound))
case obj.Hwindows:
symo = int64(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
......
......@@ -42,7 +42,7 @@ import (
func Main() {
linkarchinit()
ld.Ldmain()
ld.Main()
}
func linkarchinit() {
......@@ -121,28 +121,28 @@ func archinit(ctxt *ld.Link) {
case obj.Hplan9: /* plan 9 */
ld.HEADR = 32 + 8
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x200000 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x200000 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x200000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x200000
}
case obj.Hdarwin: /* apple MACH */
ld.Machoinit()
ld.HEADR = ld.INITIAL_MACHO_HEADR
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
if ld.INITTEXT == -1 {
ld.INITTEXT = 4096 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
case obj.Hlinux, /* elf64 executable */
......@@ -154,47 +154,47 @@ func archinit(ctxt *ld.Link) {
ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = (1 << 22) + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = (1 << 22) + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
case obj.Hnacl:
ld.Elfinit(ctxt)
ld.Debug['w'] = true // disable dwarf, which gets confused and is useless anyway
*ld.FlagW = true // disable dwarf, which gets confused and is useless anyway
ld.HEADR = 0x10000
ld.Funcalign = 32
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x20000
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x20000
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
case obj.Hwindows: /* PE executable */
ld.Peinit(ctxt)
ld.HEADR = ld.PEFILEHEADR
if ld.INITTEXT == -1 {
ld.INITTEXT = ld.PEBASE + int64(ld.PESECTHEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = ld.PEBASE + int64(ld.PESECTHEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = ld.PESECTALIGN
if *ld.FlagRound == -1 {
*ld.FlagRound = ld.PESECTALIGN
}
}
if ld.INITDAT != 0 && ld.INITRND != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(ld.INITDAT), uint32(ld.INITRND))
if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(*ld.FlagDataAddr), uint32(*ld.FlagRound))
}
}
......@@ -630,7 +630,7 @@ func asmb(ctxt *ld.Link) {
ld.Lcsize = 0
symo := uint32(0)
if !ld.Debug['s'] {
if !*ld.FlagS {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
......@@ -640,14 +640,14 @@ func asmb(ctxt *ld.Link) {
default:
if ld.Iself {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND)))
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
case obj.Hplan9:
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case obj.Hdarwin:
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(ld.INITRND))) + uint64(machlink))
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(*ld.FlagRound))) + uint64(machlink))
}
ld.Cseek(int64(symo))
......@@ -717,7 +717,7 @@ func asmb(ctxt *ld.Link) {
}
ld.Cflush()
if ld.Debug['c'] {
if *ld.FlagC {
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)
......
......@@ -42,7 +42,7 @@ import (
func Main() {
linkarchinit()
ld.Ldmain()
ld.Main()
}
func linkarchinit() {
......@@ -112,64 +112,64 @@ func archinit(ctxt *ld.Link) {
case obj.Hplan9: /* plan 9 */
ld.HEADR = 32
if ld.INITTEXT == -1 {
ld.INITTEXT = 4128
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4128
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
case obj.Hlinux, /* arm elf */
obj.Hfreebsd,
obj.Hnetbsd,
obj.Hopenbsd:
ld.Debug['d'] = false
*ld.FlagD = false
// with dynamic linking
ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x10000 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
case obj.Hnacl:
ld.Elfinit(ctxt)
ld.HEADR = 0x10000
ld.Funcalign = 16
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x20000
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x20000
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
case obj.Hdarwin: /* apple MACH */
ld.Debug['w'] = true // disable DWARF generation
*ld.FlagW = true // disable DWARF generation
ld.Machoinit()
ld.HEADR = ld.INITIAL_MACHO_HEADR
if ld.INITTEXT == -1 {
ld.INITTEXT = 4096 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
}
if ld.INITDAT != 0 && ld.INITRND != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(ld.INITDAT), uint32(ld.INITRND))
if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(*ld.FlagDataAddr), uint32(*ld.FlagRound))
}
}
......@@ -439,7 +439,7 @@ func asmb(ctxt *ld.Link) {
ld.Lcsize = 0
symo := uint32(0)
if !ld.Debug['s'] {
if !*ld.FlagS {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
......@@ -449,14 +449,14 @@ func asmb(ctxt *ld.Link) {
default:
if ld.Iself {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND)))
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
case obj.Hplan9:
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case obj.Hdarwin:
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(ld.INITRND))) + uint64(machlink))
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(*ld.FlagRound))) + uint64(machlink))
}
ld.Cseek(int64(symo))
......@@ -526,7 +526,7 @@ func asmb(ctxt *ld.Link) {
}
ld.Cflush()
if ld.Debug['c'] {
if *ld.FlagC {
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)
......
......@@ -42,7 +42,7 @@ import (
func Main() {
linkarchinit()
ld.Ldmain()
ld.Main()
}
func linkarchinit() {
......@@ -114,59 +114,59 @@ func archinit(ctxt *ld.Link) {
case obj.Hplan9: /* plan 9 */
ld.HEADR = 32
if ld.INITTEXT == -1 {
ld.INITTEXT = 4128
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4128
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
case obj.Hlinux: /* arm64 elf */
ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x10000 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
case obj.Hdarwin: /* apple MACH */
ld.Debug['w'] = true // disable DWARF generation
*ld.FlagW = true // disable DWARF generation
ld.Machoinit()
ld.HEADR = ld.INITIAL_MACHO_HEADR
if ld.INITTEXT == -1 {
ld.INITTEXT = 4096 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
case obj.Hnacl:
ld.Elfinit(ctxt)
ld.HEADR = 0x10000
ld.Funcalign = 16
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x20000
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x20000
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
}
if ld.INITDAT != 0 && ld.INITRND != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(ld.INITDAT), uint32(ld.INITRND))
if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(*ld.FlagDataAddr), uint32(*ld.FlagRound))
}
}
......@@ -720,7 +720,7 @@ func dynrelocsym(ctxt *Link, s *Symbol) {
func dynreloc(ctxt *Link, data *[obj.SXREF][]*Symbol) {
// -d suppresses dynamic loader format, so we may as well not
// compute these sections or mark their symbols as reachable.
if Debug['d'] && HEADTYPE != obj.Hwindows {
if *FlagD && HEADTYPE != obj.Hwindows {
return
}
if ctxt.Debugvlog != 0 {
......@@ -745,14 +745,14 @@ func Codeblk(ctxt *Link, addr int64, size int64) {
CodeblkPad(ctxt, addr, size, zeros[:])
}
func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) {
if Debug['a'] {
if *flagA {
fmt.Fprintf(ctxt.Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
}
blk(ctxt, ctxt.Textp, addr, size, pad)
/* again for printing */
if !Debug['a'] {
if !*flagA {
return
}
......@@ -857,14 +857,14 @@ func blk(ctxt *Link, syms []*Symbol, addr, size int64, pad []byte) {
}
func Datblk(ctxt *Link, addr int64, size int64) {
if Debug['a'] {
if *flagA {
fmt.Fprintf(ctxt.Bso, "datblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
}
blk(ctxt, datap, addr, size, zeros[:])
/* again for printing */
if !Debug['a'] {
if !*flagA {
return
}
......@@ -928,7 +928,7 @@ func Datblk(ctxt *Link, addr int64, size int64) {
}
func Dwarfblk(ctxt *Link, addr int64, size int64) {
if Debug['a'] {
if *flagA {
fmt.Fprintf(ctxt.Bso, "dwarfblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
}
......@@ -1060,7 +1060,7 @@ func dosymtype(ctxt *Link) {
// library initializer function.
switch Buildmode {
case BuildmodeCArchive, BuildmodeCShared:
if s.Name == INITENTRY {
if s.Name == *flagEntrySymbol {
addinitarrdata(ctxt, s)
}
}
......@@ -1351,7 +1351,7 @@ func (ctxt *Link) dodata() {
checkdatsize(ctxt, datsize, obj.SNOPTRDATA)
sect.Length = uint64(datsize) - sect.Vaddr
hasinitarr := Linkshared
hasinitarr := *FlagLinkshared
/* shared library initializer */
switch Buildmode {
......@@ -1434,7 +1434,7 @@ func (ctxt *Link) dodata() {
if len(data[obj.STLSBSS]) > 0 {
var sect *Section
if Iself && (Linkmode == LinkExternal || !Debug['d']) && HEADTYPE != obj.Hopenbsd {
if Iself && (Linkmode == LinkExternal || !*FlagD) && HEADTYPE != obj.Hopenbsd {
sect = addsection(&Segdata, ".tbss", 06)
sect.Align = int32(SysArch.PtrSize)
sect.Vaddr = 0
......@@ -1843,7 +1843,7 @@ func dodataSect(ctxt *Link, symn int, syms []*Symbol) (result []*Symbol, maxAlig
// at the very beginning of the text segment.
// This ``header'' is read by cmd/go.
func (ctxt *Link) textbuildid() {
if Iself || buildid == "" {
if Iself || *flagBuildid == "" {
return
}
......@@ -1851,7 +1851,7 @@ func (ctxt *Link) textbuildid() {
sym.Attr |= AttrReachable
// The \xff is invalid UTF-8, meant to make it less likely
// to find one of these accidentally.
data := "\xff Go build ID: " + strconv.Quote(buildid) + "\n \xff"
data := "\xff Go build ID: " + strconv.Quote(*flagBuildid) + "\n \xff"
sym.Type = obj.STEXT
sym.P = []byte(data)
sym.Size = int64(len(sym.P))
......@@ -1876,7 +1876,7 @@ func (ctxt *Link) textaddress() {
if HEADTYPE == obj.Hwindows {
Linklookup(ctxt, ".text", 0).Sect = sect
}
va := uint64(INITTEXT)
va := uint64(*FlagTextAddr)
sect.Vaddr = va
for _, sym := range ctxt.Textp {
sym.Sect = sect
......@@ -1907,7 +1907,7 @@ func (ctxt *Link) textaddress() {
// assign addresses
func (ctxt *Link) address() {
va := uint64(INITTEXT)
va := uint64(*FlagTextAddr)
Segtext.Rwx = 05
Segtext.Vaddr = va
Segtext.Fileoff = uint64(HEADR)
......@@ -1917,7 +1917,7 @@ func (ctxt *Link) address() {
va += s.Length
}
Segtext.Length = va - uint64(INITTEXT)
Segtext.Length = va - uint64(*FlagTextAddr)
Segtext.Filelen = Segtext.Length
if HEADTYPE == obj.Hnacl {
va += 32 // room for the "halt sled"
......@@ -1926,7 +1926,7 @@ func (ctxt *Link) address() {
if Segrodata.Sect != nil {
// align to page boundary so as not to mix
// rodata and executable text.
va = uint64(Rnd(int64(va), int64(INITRND)))
va = uint64(Rnd(int64(va), int64(*FlagRound)))
Segrodata.Rwx = 04
Segrodata.Vaddr = va
......@@ -1942,7 +1942,7 @@ func (ctxt *Link) address() {
Segrodata.Filelen = Segrodata.Length
}
va = uint64(Rnd(int64(va), int64(INITRND)))
va = uint64(Rnd(int64(va), int64(*FlagRound)))
Segdata.Rwx = 06
Segdata.Vaddr = va
Segdata.Fileoff = va - Segtext.Vaddr + Segtext.Fileoff
......@@ -1985,10 +1985,10 @@ func (ctxt *Link) address() {
Segdata.Filelen = bss.Vaddr - Segdata.Vaddr
va = uint64(Rnd(int64(va), int64(INITRND)))
va = uint64(Rnd(int64(va), int64(*FlagRound)))
Segdwarf.Rwx = 06
Segdwarf.Vaddr = va
Segdwarf.Fileoff = Segdata.Fileoff + uint64(Rnd(int64(Segdata.Filelen), int64(INITRND)))
Segdwarf.Fileoff = Segdata.Fileoff + uint64(Rnd(int64(Segdata.Filelen), int64(*FlagRound)))
Segdwarf.Filelen = 0
if HEADTYPE == obj.Hwindows {
Segdwarf.Fileoff = Segdata.Fileoff + uint64(Rnd(int64(Segdata.Filelen), int64(PEFILEALIGN)))
......
......@@ -15,7 +15,7 @@ import (
// deadcode marks all reachable symbols.
//
// The basis of the dead code elimination is a flood fill of symbols,
// following their relocations, beginning at INITENTRY.
// following their relocations, beginning at *flagEntrySymbol.
//
// This flood fill is wrapped in logic for pruning unused methods.
// All methods are mentioned by relocations on their receiver's *rtype.
......@@ -55,7 +55,7 @@ func deadcode(ctxt *Link) {
}
// First, flood fill any symbols directly reachable in the call
// graph from INITENTRY. Ignore all methods not directly called.
// graph from *flagEntrySymbol. Ignore all methods not directly called.
d.init()
d.flood()
......@@ -196,7 +196,7 @@ func (d *deadcodepass) mark(s, parent *Symbol) {
if s.Attr.ReflectMethod() {
d.reflectMethod = true
}
if flag_dumpdep {
if *flagDumpDep {
p := "_"
if parent != nil {
p = parent.Name
......@@ -217,7 +217,7 @@ func (d *deadcodepass) markMethod(m methodref) {
}
// init marks all initial symbols as reachable.
// In a typical binary, this is INITENTRY.
// In a typical binary, this is *flagEntrySymbol.
func (d *deadcodepass) init() {
var names []string
......@@ -240,8 +240,8 @@ func (d *deadcodepass) init() {
} else {
// In a normal binary, start at main.main and the init
// functions and mark what is reachable from there.
names = append(names, INITENTRY)
if Linkshared && Buildmode == BuildmodeExe {
names = append(names, *flagEntrySymbol)
if *FlagLinkshared && Buildmode == BuildmodeExe {
names = append(names, "main.main", "main.init")
}
for _, name := range markextra {
......
......@@ -1398,10 +1398,10 @@ var prototypedies map[string]*dwarf.DWDie
*
*/
func dwarfgeneratedebugsyms(ctxt *Link) {
if Debug['w'] { // disable dwarf
if *FlagW { // disable dwarf
return
}
if Debug['s'] && HEADTYPE != obj.Hdarwin {
if *FlagS && HEADTYPE != obj.Hdarwin {
return
}
if HEADTYPE == obj.Hplan9 {
......@@ -1483,7 +1483,7 @@ func dwarfgeneratedebugsyms(ctxt *Link) {
* Elf.
*/
func dwarfaddshstrings(ctxt *Link, shstrtab *Symbol) {
if Debug['w'] { // disable dwarf
if *FlagW { // disable dwarf
return
}
......@@ -1508,7 +1508,7 @@ func dwarfaddshstrings(ctxt *Link, shstrtab *Symbol) {
// Add section symbols for DWARF debug info. This is called before
// dwarfaddelfheaders.
func dwarfaddelfsectionsyms(ctxt *Link) {
if Debug['w'] { // disable dwarf
if *FlagW { // disable dwarf
return
}
if Linkmode != LinkExternal {
......@@ -1528,7 +1528,7 @@ func dwarfaddelfsectionsyms(ctxt *Link) {
* Windows PE
*/
func dwarfaddpeheaders(ctxt *Link) {
if Debug['w'] { // disable dwarf
if *FlagW { // disable dwarf
return
}
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next {
......
......@@ -1355,7 +1355,7 @@ func elfbuildinfo(sh *ElfShdr, startva uint64, resoff uint64) int {
}
func elfgobuildid(sh *ElfShdr, startva uint64, resoff uint64) int {
n := len(ELF_NOTE_GO_NAME) + int(Rnd(int64(len(buildid)), 4))
n := len(ELF_NOTE_GO_NAME) + int(Rnd(int64(len(*flagBuildid)), 4))
return elfnote(sh, startva, resoff, n, true)
}
......@@ -1374,15 +1374,15 @@ func elfwritebuildinfo(ctxt *Link) int {
}
func elfwritegobuildid(ctxt *Link) int {
sh := elfwritenotehdr(ctxt, ".note.go.buildid", uint32(len(ELF_NOTE_GO_NAME)), uint32(len(buildid)), ELF_NOTE_GOBUILDID_TAG)
sh := elfwritenotehdr(ctxt, ".note.go.buildid", uint32(len(ELF_NOTE_GO_NAME)), uint32(len(*flagBuildid)), ELF_NOTE_GOBUILDID_TAG)
if sh == nil {
return 0
}
Cwrite(ELF_NOTE_GO_NAME)
Cwrite([]byte(buildid))
Cwrite([]byte(*flagBuildid))
var zero = make([]byte, 4)
Cwrite(zero[:int(Rnd(int64(len(buildid)), 4)-int64(len(buildid)))])
Cwrite(zero[:int(Rnd(int64(len(*flagBuildid)), 4)-int64(len(*flagBuildid)))])
return int(sh.size)
}
......@@ -1594,7 +1594,7 @@ func elfphload(ctxt *Link, seg *Segment) *ElfPhdr {
ph.memsz = seg.Length
ph.off = seg.Fileoff
ph.filesz = seg.Filelen
ph.align = uint64(INITRND)
ph.align = uint64(*FlagRound)
return ph
}
......@@ -1837,7 +1837,7 @@ func (ctxt *Link) doelf() {
// binutils could correctly calculate PT_TLS size.
// see https://golang.org/issue/5200.
if HEADTYPE != obj.Hopenbsd {
if !Debug['d'] || Linkmode == LinkExternal {
if !*FlagD || Linkmode == LinkExternal {
Addstring(ctxt, shstrtab, ".tbss")
}
}
......@@ -1850,7 +1850,7 @@ func (ctxt *Link) doelf() {
if len(buildinfo) > 0 {
Addstring(ctxt, shstrtab, ".note.gnu.build-id")
}
if buildid != "" {
if *flagBuildid != "" {
Addstring(ctxt, shstrtab, ".note.go.buildid")
}
Addstring(ctxt, shstrtab, ".elfdata")
......@@ -1867,7 +1867,7 @@ func (ctxt *Link) doelf() {
Addstring(ctxt, shstrtab, relro_prefix+".gopclntab")
if Linkmode == LinkExternal {
Debug['d'] = true
*FlagD = true
Addstring(ctxt, shstrtab, elfRelType+".text")
Addstring(ctxt, shstrtab, elfRelType+".rodata")
......@@ -1891,7 +1891,7 @@ func (ctxt *Link) doelf() {
}
}
hasinitarr := Linkshared
hasinitarr := *FlagLinkshared
/* shared library initializer */
switch Buildmode {
......@@ -1904,7 +1904,7 @@ func (ctxt *Link) doelf() {
Addstring(ctxt, shstrtab, elfRelType+".init_array")
}
if !Debug['s'] {
if !*FlagS {
Addstring(ctxt, shstrtab, ".symtab")
Addstring(ctxt, shstrtab, ".strtab")
dwarfaddshstrings(ctxt, shstrtab)
......@@ -1912,7 +1912,7 @@ func (ctxt *Link) doelf() {
Addstring(ctxt, shstrtab, ".shstrtab")
if !Debug['d'] { /* -d suppresses dynamic loader format */
if !*FlagD { /* -d suppresses dynamic loader format */
Addstring(ctxt, shstrtab, ".interp")
Addstring(ctxt, shstrtab, ".hash")
Addstring(ctxt, shstrtab, ".got")
......@@ -2080,8 +2080,8 @@ func (ctxt *Link) doelf() {
addgonote(ctxt, ".note.go.deps", ELF_NOTE_GODEPS_TAG, []byte(strings.Join(deplist, "\n")))
}
if Linkmode == LinkExternal && buildid != "" {
addgonote(ctxt, ".note.go.buildid", ELF_NOTE_GOBUILDID_TAG, []byte(buildid))
if Linkmode == LinkExternal && *flagBuildid != "" {
addgonote(ctxt, ".note.go.buildid", ELF_NOTE_GOBUILDID_TAG, []byte(*flagBuildid))
}
}
......@@ -2144,7 +2144,7 @@ func Asmbelf(ctxt *Link, symo int64) {
}
elfreserve := int64(ELFRESERVE)
startva := INITTEXT - int64(HEADR)
startva := *FlagTextAddr - int64(HEADR)
resoff := elfreserve
var pph *ElfPhdr
......@@ -2165,7 +2165,7 @@ func Asmbelf(ctxt *Link, symo int64) {
sh.type_ = SHT_NOTE
}
if buildid != "" {
if *flagBuildid != "" {
sh := elfshname(ctxt, ".note.go.buildid")
sh.type_ = SHT_NOTE
sh.flags = SHF_ALLOC
......@@ -2180,9 +2180,9 @@ func Asmbelf(ctxt *Link, symo int64) {
pph.type_ = PT_PHDR
pph.flags = PF_R
pph.off = uint64(eh.ehsize)
pph.vaddr = uint64(INITTEXT) - uint64(HEADR) + pph.off
pph.paddr = uint64(INITTEXT) - uint64(HEADR) + pph.off
pph.align = uint64(INITRND)
pph.vaddr = uint64(*FlagTextAddr) - uint64(HEADR) + pph.off
pph.paddr = uint64(*FlagTextAddr) - uint64(HEADR) + pph.off
pph.align = uint64(*FlagRound)
/*
* PHDR must be in a loaded segment. Adjust the text
......@@ -2198,36 +2198,36 @@ func Asmbelf(ctxt *Link, symo int64) {
Segtext.Filelen += uint64(o)
}
if !Debug['d'] { /* -d suppresses dynamic loader format */
if !*FlagD { /* -d suppresses dynamic loader format */
/* interpreter */
sh := elfshname(ctxt, ".interp")
sh.type_ = SHT_PROGBITS
sh.flags = SHF_ALLOC
sh.addralign = 1
if interpreter == "" {
if *flagInterpreter == "" {
switch HEADTYPE {
case obj.Hlinux:
interpreter = Thearch.Linuxdynld
*flagInterpreter = Thearch.Linuxdynld
case obj.Hfreebsd:
interpreter = Thearch.Freebsddynld
*flagInterpreter = Thearch.Freebsddynld
case obj.Hnetbsd:
interpreter = Thearch.Netbsddynld
*flagInterpreter = Thearch.Netbsddynld
case obj.Hopenbsd:
interpreter = Thearch.Openbsddynld
*flagInterpreter = Thearch.Openbsddynld
case obj.Hdragonfly:
interpreter = Thearch.Dragonflydynld
*flagInterpreter = Thearch.Dragonflydynld
case obj.Hsolaris:
interpreter = Thearch.Solarisdynld
*flagInterpreter = Thearch.Solarisdynld
}
}
resoff -= int64(elfinterp(sh, uint64(startva), uint64(resoff), interpreter))
resoff -= int64(elfinterp(sh, uint64(startva), uint64(resoff), *flagInterpreter))
ph := newElfPhdr(ctxt)
ph.type_ = PT_INTERP
......@@ -2267,7 +2267,7 @@ func Asmbelf(ctxt *Link, symo int64) {
phsh(pnote, sh)
}
if buildid != "" {
if *flagBuildid != "" {
sh := elfshname(ctxt, ".note.go.buildid")
resoff -= int64(elfgobuildid(sh, uint64(startva), uint64(resoff)))
......@@ -2286,7 +2286,7 @@ func Asmbelf(ctxt *Link, symo int64) {
elfphload(ctxt, &Segdata)
/* Dynamic linking sections */
if !Debug['d'] {
if !*FlagD {
sh := elfshname(ctxt, ".dynsym")
sh.type_ = SHT_DYNSYM
sh.flags = SHF_ALLOC
......@@ -2471,7 +2471,7 @@ elfobj:
eh.shstrndx = uint16(sh.shnum)
// put these sections early in the list
if !Debug['s'] {
if !*FlagS {
elfshname(ctxt, ".symtab")
elfshname(ctxt, ".strtab")
}
......@@ -2515,7 +2515,7 @@ elfobj:
sh.flags = 0
}
if !Debug['s'] {
if !*FlagS {
sh := elfshname(ctxt, ".symtab")
sh.type_ = SHT_SYMTAB
sh.off = uint64(symo)
......@@ -2581,7 +2581,7 @@ elfobj:
a += int64(elfwritehdr())
a += int64(elfwritephdrs())
a += int64(elfwriteshdrs())
if !Debug['d'] {
if !*FlagD {
a += int64(elfwriteinterp(ctxt))
}
if Linkmode != LinkExternal {
......@@ -2594,7 +2594,7 @@ elfobj:
if len(buildinfo) > 0 {
a += int64(elfwritebuildinfo(ctxt))
}
if buildid != "" {
if *flagBuildid != "" {
a += int64(elfwritegobuildid(ctxt))
}
}
......
......@@ -31,13 +31,13 @@ func expandpkg(t0 string, pkg string) string {
func ldpkg(ctxt *Link, f *bio.Reader, pkg string, length int64, filename string, whence int) {
var p0, p1 int
if Debug['g'] {
if *flagG {
return
}
if int64(int(length)) != length {
fmt.Fprintf(os.Stderr, "%s: too much pkg data in %s\n", os.Args[0], filename)
if Debug['u'] {
if *flagU {
errorexit()
}
return
......@@ -52,7 +52,7 @@ func ldpkg(ctxt *Link, f *bio.Reader, pkg string, length int64, filename string,
bdata := make([]byte, length)
if _, err := io.ReadFull(f, bdata); err != nil {
fmt.Fprintf(os.Stderr, "%s: short pkg read %s\n", os.Args[0], filename)
if Debug['u'] {
if *flagU {
errorexit()
}
return
......@@ -84,7 +84,7 @@ func ldpkg(ctxt *Link, f *bio.Reader, pkg string, length int64, filename string,
if pkg == "main" && !isMain {
Exitf("%s: not package main", filename)
}
if Debug['u'] && whence != ArchiveObj && !isSafe {
if *flagU && whence != ArchiveObj && !isSafe {
Exitf("load of unsafe package %s", filename)
}
}
......@@ -101,7 +101,7 @@ func ldpkg(ctxt *Link, f *bio.Reader, pkg string, length int64, filename string,
i := strings.IndexByte(data[p0+1:], '\n')
if i < 0 {
fmt.Fprintf(os.Stderr, "%s: found $$ // cgo but no newline in %s\n", os.Args[0], filename)
if Debug['u'] {
if *flagU {
errorexit()
}
return
......@@ -114,7 +114,7 @@ func ldpkg(ctxt *Link, f *bio.Reader, pkg string, length int64, filename string,
}
if p1 < 0 {
fmt.Fprintf(os.Stderr, "%s: cannot find end of // cgo section in %s\n", os.Args[0], filename)
if Debug['u'] {
if *flagU {
errorexit()
}
return
......@@ -163,7 +163,7 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
lib = f[3]
}
if Debug['d'] {
if *FlagD {
fmt.Fprintf(os.Stderr, "%s: %s: cannot use dynamic imports with -d flag\n", os.Args[0], file)
nerrors++
return
......@@ -267,14 +267,14 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
goto err
}
if !Debug['I'] {
if interpreter != "" && interpreter != f[1] {
fmt.Fprintf(os.Stderr, "%s: conflict dynlinker: %s and %s\n", os.Args[0], interpreter, f[1])
if *flagInterpreter != "" {
if *flagInterpreter != f[1] {
fmt.Fprintf(os.Stderr, "%s: conflict dynlinker: %s and %s\n", os.Args[0], *flagInterpreter, f[1])
nerrors++
return
}
interpreter = f[1]
*flagInterpreter = f[1]
}
continue
......@@ -352,14 +352,14 @@ func fieldtrack(ctxt *Link) {
}
}
if tracksym == "" {
if *flagFieldTrack == "" {
return
}
s := Linklookup(ctxt, tracksym, 0)
s := Linklookup(ctxt, *flagFieldTrack, 0)
if !s.Attr.Reachable() {
return
}
addstrdata(ctxt, tracksym, buf.String())
addstrdata(ctxt, *flagFieldTrack, buf.String())
}
func (ctxt *Link) addexport() {
......
......@@ -64,7 +64,7 @@ func addlib(ctxt *Link, src string, obj string, pathname string) {
} else {
// try dot, -L "libdir", and then goroot.
for _, dir := range ctxt.Libdir {
if Linkshared {
if *FlagLinkshared {
pname = dir + "/" + pkg + ".shlibname"
if _, err := os.Stat(pname); err == nil {
isshlib = true
......
This diff is collapsed.
......@@ -295,7 +295,7 @@ func machowrite() int {
}
func (ctxt *Link) domacho() {
if Debug['d'] {
if *FlagD {
return
}
......@@ -340,7 +340,7 @@ func Machoadddynlib(lib string) {
if load_budget < 0 {
HEADR += 4096
INITTEXT += 4096
*FlagTextAddr += 4096
load_budget += 4096
}
......@@ -415,7 +415,7 @@ func machoshbits(ctxt *Link, mseg *MachoSeg, sect *Section, segname string) {
func Asmbmacho(ctxt *Link) {
/* apple MACH */
va := INITTEXT - int64(HEADR)
va := *FlagTextAddr - int64(HEADR)
mh := getMachoHdr()
switch SysArch.Family {
......@@ -460,7 +460,7 @@ func Asmbmacho(ctxt *Link) {
}
/* text */
v := Rnd(int64(uint64(HEADR)+Segtext.Length), int64(INITRND))
v := Rnd(int64(uint64(HEADR)+Segtext.Length), int64(*FlagRound))
if Linkmode != LinkExternal {
ms = newMachoSeg("__TEXT", 20)
......@@ -493,7 +493,7 @@ func Asmbmacho(ctxt *Link) {
}
/* dwarf */
if !Debug['w'] {
if !*FlagW {
if Linkmode != LinkExternal {
ms = newMachoSeg("__DWARF", 20)
ms.vaddr = Segdwarf.Vaddr
......@@ -539,7 +539,7 @@ func Asmbmacho(ctxt *Link) {
}
}
if !Debug['d'] {
if !*FlagD {
// must match domacholink below
s1 := Linklookup(ctxt, ".machosymtab", 0)
s2 := Linklookup(ctxt, ".linkedit.plt", 0)
......@@ -548,7 +548,7 @@ func Asmbmacho(ctxt *Link) {
if Linkmode != LinkExternal {
ms := newMachoSeg("__LINKEDIT", 0)
ms.vaddr = uint64(va) + uint64(v) + uint64(Rnd(int64(Segdata.Length), int64(INITRND)))
ms.vaddr = uint64(va) + uint64(v) + uint64(Rnd(int64(Segdata.Length), int64(*FlagRound)))
ms.vsize = uint64(s1.Size) + uint64(s2.Size) + uint64(s3.Size) + uint64(s4.Size)
ms.fileoffset = uint64(linkoff)
ms.filesize = ms.vsize
......@@ -797,7 +797,7 @@ func Domacholink(ctxt *Link) int64 {
size := int(s1.Size + s2.Size + s3.Size + s4.Size)
if size > 0 {
linkoff = Rnd(int64(uint64(HEADR)+Segtext.Length), int64(INITRND)) + Rnd(int64(Segdata.Filelen), int64(INITRND)) + Rnd(int64(Segdwarf.Filelen), int64(INITRND))
linkoff = Rnd(int64(uint64(HEADR)+Segtext.Length), int64(*FlagRound)) + Rnd(int64(Segdata.Filelen), int64(*FlagRound)) + Rnd(int64(Segdwarf.Filelen), int64(*FlagRound))
Cseek(linkoff)
Cwrite(s1.P[:s1.Size])
......@@ -806,7 +806,7 @@ func Domacholink(ctxt *Link) int64 {
Cwrite(s4.P[:s4.Size])
}
return Rnd(int64(size), int64(INITRND))
return Rnd(int64(size), int64(*FlagRound))
}
func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
......
This diff is collapsed.
......@@ -701,7 +701,7 @@ func initdynexport(ctxt *Link) {
func addexports(ctxt *Link) {
var e IMAGE_EXPORT_DIRECTORY
size := binary.Size(&e) + 10*nexport + len(outfile) + 1
size := binary.Size(&e) + 10*nexport + len(*flagOutfile) + 1
for i := 0; i < nexport; i++ {
size += len(dexport[i].Extname) + 1
}
......@@ -741,7 +741,7 @@ func addexports(ctxt *Link) {
}
// put EXPORT Name Pointer Table
v := int(e.Name + uint32(len(outfile)) + 1)
v := int(e.Name + uint32(len(*flagOutfile)) + 1)
for i := 0; i < nexport; i++ {
Lputl(uint32(v))
......@@ -754,7 +754,7 @@ func addexports(ctxt *Link) {
}
// put Names
strnput(outfile, len(outfile)+1)
strnput(*flagOutfile, len(*flagOutfile)+1)
for i := 0; i < nexport; i++ {
strnput(dexport[i].Extname, len(dexport[i].Extname)+1)
......@@ -1021,7 +1021,7 @@ func addpesymtable(ctxt *Link) {
// write COFF symbol table
var symcnt int
if !Debug['s'] || Linkmode == LinkExternal {
if !*FlagS || Linkmode == LinkExternal {
symcnt = writePESymTableRecords(ctxt)
}
......@@ -1114,7 +1114,7 @@ func addinitarray(ctxt *Link) (c *IMAGE_SECTION_HEADER) {
Cseek(int64(c.PointerToRawData))
chksectoff(ctxt, c, Cpos())
init_entry := Linklookup(ctxt, INITENTRY, 0)
init_entry := Linklookup(ctxt, *flagEntrySymbol, 0)
addr := uint64(init_entry.Value) - init_entry.Sect.Vaddr
switch obj.Getgoarch() {
......@@ -1168,7 +1168,7 @@ func Asmbpe(ctxt *Link) {
c = addinitarray(ctxt)
}
if !Debug['s'] {
if !*FlagS {
dwarfaddpeheaders(ctxt)
}
......
......@@ -226,7 +226,7 @@ func putplan9sym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64,
'Z',
'm':
l := 4
if HEADTYPE == obj.Hplan9 && SysArch.Family == sys.AMD64 && !Debug['8'] {
if HEADTYPE == obj.Hplan9 && SysArch.Family == sys.AMD64 && !Flag8 {
Lputb(uint32(addr >> 32))
l = 8
}
......@@ -483,7 +483,7 @@ func (ctxt *Link) symtab() {
}
if Buildmode == BuildmodeShared {
abihashgostr := Linklookup(ctxt, "go.link.abihash."+filepath.Base(outfile), 0)
abihashgostr := Linklookup(ctxt, "go.link.abihash."+filepath.Base(*flagOutfile), 0)
abihashgostr.Attr |= AttrReachable
abihashgostr.Type = obj.SRODATA
hashsym := Linklookup(ctxt, "go.link.abihashbytes", 0)
......@@ -538,7 +538,7 @@ func (ctxt *Link) symtab() {
adduint(ctxt, moduledata, uint64(nitablinks))
adduint(ctxt, moduledata, uint64(nitablinks))
if len(ctxt.Shlibs) > 0 {
thismodulename := filepath.Base(outfile)
thismodulename := filepath.Base(*flagOutfile)
switch Buildmode {
case BuildmodeExe, BuildmodePIE:
// When linking an executable, outfile is just "a.out". Make
......
......@@ -7,10 +7,7 @@ package ld
import (
"bytes"
"encoding/binary"
"log"
"os"
"runtime"
"runtime/pprof"
"strings"
"time"
)
......@@ -82,40 +79,6 @@ func Exit(code int) {
os.Exit(code)
}
var (
cpuprofile string
memprofile string
memprofilerate int64
)
func startProfile() {
if cpuprofile != "" {
f, err := os.Create(cpuprofile)
if err != nil {
log.Fatalf("%v", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatalf("%v", err)
}
AtExit(pprof.StopCPUProfile)
}
if memprofile != "" {
if memprofilerate != 0 {
runtime.MemProfileRate = int(memprofilerate)
}
f, err := os.Create(memprofile)
if err != nil {
log.Fatalf("%v", err)
}
AtExit(func() {
runtime.GC() // profile all outstanding allocations
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatalf("%v", err)
}
})
}
}
func artrim(x []byte) string {
i := 0
j := len(x)
......
......@@ -226,7 +226,7 @@ func asmb(ctxt *ld.Link) {
ld.Lcsize = 0
symo := uint32(0)
if ld.Debug['s'] {
if *ld.FlagS {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
......@@ -236,7 +236,7 @@ func asmb(ctxt *ld.Link) {
default:
if ld.Iself {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND)))
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
case obj.Hplan9:
......@@ -306,7 +306,7 @@ func asmb(ctxt *ld.Link) {
}
ld.Cflush()
if ld.Debug['c'] {
if *ld.FlagC {
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)
......
......@@ -42,7 +42,7 @@ import (
func Main() {
linkarchinit()
ld.Ldmain()
ld.Main()
}
func linkarchinit() {
......@@ -119,45 +119,45 @@ func archinit(ctxt *ld.Link) {
case obj.Hplan9: /* plan 9 */
ld.HEADR = 32
if ld.INITTEXT == -1 {
ld.INITTEXT = 16*1024 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 16*1024 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 16 * 1024
if *ld.FlagRound == -1 {
*ld.FlagRound = 16 * 1024
}
case obj.Hlinux: /* mips64 elf */
ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x10000 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
case obj.Hnacl:
ld.Elfinit(ctxt)
ld.HEADR = 0x10000
ld.Funcalign = 16
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x20000
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x20000
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
}
if ld.INITDAT != 0 && ld.INITRND != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(ld.INITDAT), uint32(ld.INITRND))
if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(*ld.FlagDataAddr), uint32(*ld.FlagRound))
}
}
......@@ -847,7 +847,7 @@ func asmb(ctxt *ld.Link) {
ld.Lcsize = 0
symo := uint32(0)
if !ld.Debug['s'] {
if !*ld.FlagS {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
......@@ -857,7 +857,7 @@ func asmb(ctxt *ld.Link) {
default:
if ld.Iself {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND)))
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
case obj.Hplan9:
......@@ -923,7 +923,7 @@ func asmb(ctxt *ld.Link) {
}
ld.Cflush()
if ld.Debug['c'] {
if *ld.FlagC {
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)
......
......@@ -42,7 +42,7 @@ import (
func Main() {
linkarchinit()
ld.Ldmain()
ld.Main()
}
func linkarchinit() {
......@@ -105,7 +105,7 @@ func archinit(ctxt *ld.Link) {
ld.Linkmode = ld.LinkExternal
}
if ld.Linkshared {
if *ld.FlagLinkshared {
ld.Linkmode = ld.LinkExternal
}
......@@ -134,48 +134,48 @@ func archinit(ctxt *ld.Link) {
case obj.Hplan9: /* plan 9 */
ld.HEADR = 32
if ld.INITTEXT == -1 {
ld.INITTEXT = 4128
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4128
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
case obj.Hlinux: /* ppc64 elf */
if ld.SysArch == sys.ArchPPC64 {
ld.Debug['d'] = true // TODO(austin): ELF ABI v1 not supported yet
*ld.FlagD = true // TODO(austin): ELF ABI v1 not supported yet
}
ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x10000 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
case obj.Hnacl:
ld.Elfinit(ctxt)
ld.HEADR = 0x10000
ld.Funcalign = 16
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x20000
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x20000
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
}
if ld.INITDAT != 0 && ld.INITRND != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(ld.INITDAT), uint32(ld.INITRND))
if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(*ld.FlagDataAddr), uint32(*ld.FlagRound))
}
}
......@@ -542,7 +542,7 @@ func asmb(ctxt *ld.Link) {
ld.Lcsize = 0
symo := uint32(0)
if !ld.Debug['s'] {
if !*ld.FlagS {
if !ld.Iself {
ctxt.Diag("unsupported executable format")
}
......@@ -551,7 +551,7 @@ func asmb(ctxt *ld.Link) {
}
ctxt.Bso.Flush()
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND)))
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
ld.Cseek(int64(symo))
if ctxt.Debugvlog != 0 {
......@@ -584,7 +584,7 @@ func asmb(ctxt *ld.Link) {
}
ld.Cflush()
if ld.Debug['c'] {
if *ld.FlagC {
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)
......
......@@ -41,7 +41,7 @@ import (
func Main() {
linkarchinit()
ld.Ldmain()
ld.Main()
}
func linkarchinit() {
......@@ -97,18 +97,18 @@ func archinit(ctxt *ld.Link) {
case obj.Hlinux: // s390x ELF
ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x10000 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x10000 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
}
if ld.INITDAT != 0 && ld.INITRND != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(ld.INITDAT), uint32(ld.INITRND))
if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(*ld.FlagDataAddr), uint32(*ld.FlagRound))
}
}
......@@ -662,7 +662,7 @@ func asmb(ctxt *ld.Link) {
ld.Spsize = 0
ld.Lcsize = 0
symo := uint32(0)
if !ld.Debug['s'] {
if !*ld.FlagS {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
......@@ -672,14 +672,14 @@ func asmb(ctxt *ld.Link) {
default:
if ld.Iself {
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND)))
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
case obj.Hplan9:
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case obj.Hdarwin:
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(ld.INITRND))) + uint64(machlink))
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(*ld.FlagRound))) + uint64(machlink))
case obj.Hwindows:
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
......
......@@ -42,7 +42,7 @@ import (
func Main() {
linkarchinit()
ld.Ldmain()
ld.Main()
}
func linkarchinit() {
......@@ -117,28 +117,28 @@ func archinit(ctxt *ld.Link) {
case obj.Hplan9: /* plan 9 */
ld.HEADR = 32
if ld.INITTEXT == -1 {
ld.INITTEXT = 4096 + 32
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4096 + 32
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
case obj.Hdarwin: /* apple MACH */
ld.Machoinit()
ld.HEADR = ld.INITIAL_MACHO_HEADR
if ld.INITTEXT == -1 {
ld.INITTEXT = 4096 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 4096 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
case obj.Hlinux, /* elf32 executable */
......@@ -148,46 +148,46 @@ func archinit(ctxt *ld.Link) {
ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x08048000 + int64(ld.HEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x08048000 + int64(ld.HEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 4096
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
case obj.Hnacl:
ld.Elfinit(ctxt)
ld.HEADR = 0x10000
ld.Funcalign = 32
if ld.INITTEXT == -1 {
ld.INITTEXT = 0x20000
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0x20000
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = 0x10000
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
case obj.Hwindows: /* PE executable */
ld.Peinit(ctxt)
ld.HEADR = ld.PEFILEHEADR
if ld.INITTEXT == -1 {
ld.INITTEXT = ld.PEBASE + int64(ld.PESECTHEADR)
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = ld.PEBASE + int64(ld.PESECTHEADR)
}
if ld.INITDAT == -1 {
ld.INITDAT = 0
if *ld.FlagDataAddr == -1 {
*ld.FlagDataAddr = 0
}
if ld.INITRND == -1 {
ld.INITRND = ld.PESECTALIGN
if *ld.FlagRound == -1 {
*ld.FlagRound = ld.PESECTALIGN
}
}
if ld.INITDAT != 0 && ld.INITRND != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(ld.INITDAT), uint32(ld.INITRND))
if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(*ld.FlagDataAddr), uint32(*ld.FlagRound))
}
}
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