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