Commit 743fe069 authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle

cmd/link: replace Segment's linked list of Sections with a slice

Just noticed this in passing.

Change-Id: I58fa828ef58598209ed4cbe4abc6f9f02ffc4844
Reviewed-on: https://go-review.googlesource.com/40896
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 46ecac99
...@@ -659,11 +659,11 @@ func asmb(ctxt *ld.Link) { ...@@ -659,11 +659,11 @@ func asmb(ctxt *ld.Link) {
ld.Asmbelfsetup() ld.Asmbelfsetup()
} }
sect := ld.Segtext.Sect sect := ld.Segtext.Sections[0]
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
// 0xCC is INT $3 - breakpoint instruction // 0xCC is INT $3 - breakpoint instruction
ld.CodeblkPad(ctxt, int64(sect.Vaddr), int64(sect.Length), []byte{0xCC}) ld.CodeblkPad(ctxt, int64(sect.Vaddr), int64(sect.Length), []byte{0xCC})
for sect = sect.Next; sect != nil; sect = sect.Next { for _, sect = range ld.Segtext.Sections[1:] {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
} }
......
...@@ -755,10 +755,10 @@ func asmb(ctxt *ld.Link) { ...@@ -755,10 +755,10 @@ func asmb(ctxt *ld.Link) {
ld.Asmbelfsetup() ld.Asmbelfsetup()
} }
sect := ld.Segtext.Sect sect := ld.Segtext.Sections[0]
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
for sect = sect.Next; sect != nil; sect = sect.Next { for _, sect = range ld.Segtext.Sections[1:] {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
} }
......
...@@ -400,10 +400,10 @@ func asmb(ctxt *ld.Link) { ...@@ -400,10 +400,10 @@ func asmb(ctxt *ld.Link) {
ld.Asmbelfsetup() ld.Asmbelfsetup()
} }
sect := ld.Segtext.Sect sect := ld.Segtext.Sections[0]
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
for sect = sect.Next; sect != nil; sect = sect.Next { for _, sect = range ld.Segtext.Sections[1:] {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
} }
......
...@@ -605,7 +605,7 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -605,7 +605,7 @@ func relocsym(ctxt *Link, s *Symbol) {
// to the start of the first text section, even if there are multiple. // to the start of the first text section, even if there are multiple.
if r.Sym.Sect.Name == ".text" { if r.Sym.Sect.Name == ".text" {
o = Symaddr(r.Sym) - int64(Segtext.Sect.Vaddr) + r.Add o = Symaddr(r.Sym) - int64(Segtext.Sections[0].Vaddr) + r.Add
} else { } else {
o = Symaddr(r.Sym) - int64(r.Sym.Sect.Vaddr) + r.Add o = Symaddr(r.Sym) - int64(r.Sym.Sect.Vaddr) + r.Add
} }
...@@ -1856,23 +1856,23 @@ func (ctxt *Link) dodata() { ...@@ -1856,23 +1856,23 @@ func (ctxt *Link) dodata() {
/* number the sections */ /* number the sections */
n := int32(1) n := int32(1)
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
sect.Extnum = int16(n) sect.Extnum = int16(n)
n++ n++
} }
for sect := Segrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrodata.Sections {
sect.Extnum = int16(n) sect.Extnum = int16(n)
n++ n++
} }
for sect := Segrelrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrelrodata.Sections {
sect.Extnum = int16(n) sect.Extnum = int16(n)
n++ n++
} }
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdata.Sections {
sect.Extnum = int16(n) sect.Extnum = int16(n)
n++ n++
} }
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdwarf.Sections {
sect.Extnum = int16(n) sect.Extnum = int16(n)
n++ n++
} }
...@@ -2024,7 +2024,7 @@ func (ctxt *Link) textaddress() { ...@@ -2024,7 +2024,7 @@ func (ctxt *Link) textaddress() {
// Assign PCs in text segment. // Assign PCs in text segment.
// Could parallelize, by assigning to text // Could parallelize, by assigning to text
// and then letting threads copy down, but probably not worth it. // and then letting threads copy down, but probably not worth it.
sect := Segtext.Sect sect := Segtext.Sections[0]
sect.Align = int32(Funcalign) sect.Align = int32(Funcalign)
...@@ -2132,7 +2132,7 @@ func (ctxt *Link) address() { ...@@ -2132,7 +2132,7 @@ func (ctxt *Link) address() {
Segtext.Rwx = 05 Segtext.Rwx = 05
Segtext.Vaddr = va Segtext.Vaddr = va
Segtext.Fileoff = uint64(HEADR) Segtext.Fileoff = uint64(HEADR)
for s := Segtext.Sect; s != nil; s = s.Next { for _, s := range Segtext.Sections {
va = uint64(Rnd(int64(va), int64(s.Align))) va = uint64(Rnd(int64(va), int64(s.Align)))
s.Vaddr = va s.Vaddr = va
va += s.Length va += s.Length
...@@ -2144,7 +2144,7 @@ func (ctxt *Link) address() { ...@@ -2144,7 +2144,7 @@ func (ctxt *Link) address() {
va += 32 // room for the "halt sled" va += 32 // room for the "halt sled"
} }
if Segrodata.Sect != nil { if len(Segrodata.Sections) > 0 {
// 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.
// //
...@@ -2164,7 +2164,7 @@ func (ctxt *Link) address() { ...@@ -2164,7 +2164,7 @@ func (ctxt *Link) address() {
Segrodata.Vaddr = va Segrodata.Vaddr = va
Segrodata.Fileoff = va - Segtext.Vaddr + Segtext.Fileoff Segrodata.Fileoff = va - Segtext.Vaddr + Segtext.Fileoff
Segrodata.Filelen = 0 Segrodata.Filelen = 0
for s := Segrodata.Sect; s != nil; s = s.Next { for _, s := range Segrodata.Sections {
va = uint64(Rnd(int64(va), int64(s.Align))) va = uint64(Rnd(int64(va), int64(s.Align)))
s.Vaddr = va s.Vaddr = va
va += s.Length va += s.Length
...@@ -2173,7 +2173,7 @@ func (ctxt *Link) address() { ...@@ -2173,7 +2173,7 @@ func (ctxt *Link) address() {
Segrodata.Length = va - Segrodata.Vaddr Segrodata.Length = va - Segrodata.Vaddr
Segrodata.Filelen = Segrodata.Length Segrodata.Filelen = Segrodata.Length
} }
if Segrelrodata.Sect != nil { if len(Segrelrodata.Sections) > 0 {
// align to page boundary so as not to mix // align to page boundary so as not to mix
// rodata, rel-ro data, and executable text. // rodata, rel-ro data, and executable text.
va = uint64(Rnd(int64(va), int64(*FlagRound))) va = uint64(Rnd(int64(va), int64(*FlagRound)))
...@@ -2182,7 +2182,7 @@ func (ctxt *Link) address() { ...@@ -2182,7 +2182,7 @@ func (ctxt *Link) address() {
Segrelrodata.Vaddr = va Segrelrodata.Vaddr = va
Segrelrodata.Fileoff = va - Segrodata.Vaddr + Segrodata.Fileoff Segrelrodata.Fileoff = va - Segrodata.Vaddr + Segrodata.Fileoff
Segrelrodata.Filelen = 0 Segrelrodata.Filelen = 0
for s := Segrelrodata.Sect; s != nil; s = s.Next { for _, s := range Segrelrodata.Sections {
va = uint64(Rnd(int64(va), int64(s.Align))) va = uint64(Rnd(int64(va), int64(s.Align)))
s.Vaddr = va s.Vaddr = va
va += s.Length va += s.Length
...@@ -2208,13 +2208,13 @@ func (ctxt *Link) address() { ...@@ -2208,13 +2208,13 @@ func (ctxt *Link) address() {
var bss *Section var bss *Section
var noptrbss *Section var noptrbss *Section
var vlen int64 var vlen int64
for s := Segdata.Sect; s != nil; s = s.Next { for i, s := range Segdata.Sections {
if Iself && s.Name == ".tbss" { if Iself && s.Name == ".tbss" {
continue continue
} }
vlen = int64(s.Length) vlen = int64(s.Length)
if s.Next != nil && !(Iself && s.Next.Name == ".tbss") { if i+1 < len(Segdata.Sections) && !(Iself && Segdata.Sections[i+1].Name == ".tbss") {
vlen = int64(s.Next.Vaddr - s.Vaddr) vlen = int64(Segdata.Sections[i+1].Vaddr - s.Vaddr)
} }
s.Vaddr = va s.Vaddr = va
va += uint64(vlen) va += uint64(vlen)
...@@ -2243,10 +2243,10 @@ func (ctxt *Link) address() { ...@@ -2243,10 +2243,10 @@ func (ctxt *Link) address() {
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)))
} }
for s := Segdwarf.Sect; s != nil; s = s.Next { for i, s := range Segdwarf.Sections {
vlen = int64(s.Length) vlen = int64(s.Length)
if s.Next != nil { if i+1 < len(Segdwarf.Sections) {
vlen = int64(s.Next.Vaddr - s.Vaddr) vlen = int64(Segdwarf.Sections[i+1].Vaddr - s.Vaddr)
} }
s.Vaddr = va s.Vaddr = va
va += uint64(vlen) va += uint64(vlen)
...@@ -2259,7 +2259,7 @@ func (ctxt *Link) address() { ...@@ -2259,7 +2259,7 @@ func (ctxt *Link) address() {
Segdwarf.Filelen = va - Segdwarf.Vaddr Segdwarf.Filelen = va - Segdwarf.Vaddr
var ( var (
text = Segtext.Sect text = Segtext.Sections[0]
rodata = ctxt.Syms.Lookup("runtime.rodata", 0).Sect rodata = ctxt.Syms.Lookup("runtime.rodata", 0).Sect
itablink = ctxt.Syms.Lookup("runtime.itablink", 0).Sect itablink = ctxt.Syms.Lookup("runtime.itablink", 0).Sect
symtab = ctxt.Syms.Lookup("runtime.symtab", 0).Sect symtab = ctxt.Syms.Lookup("runtime.symtab", 0).Sect
...@@ -2268,8 +2268,10 @@ func (ctxt *Link) address() { ...@@ -2268,8 +2268,10 @@ func (ctxt *Link) address() {
) )
lasttext := text lasttext := text
// Could be multiple .text sections // Could be multiple .text sections
for sect := text.Next; sect != nil && sect.Name == ".text"; sect = sect.Next { for _, sect := range Segtext.Sections {
lasttext = sect if sect.Name == ".text" {
lasttext = sect
}
} }
for _, s := range datap { for _, s := range datap {
...@@ -2303,10 +2305,14 @@ func (ctxt *Link) address() { ...@@ -2303,10 +2305,14 @@ func (ctxt *Link) address() {
// If there are multiple text sections, create runtime.text.n for // If there are multiple text sections, create runtime.text.n for
// their section Vaddr, using n for index // their section Vaddr, using n for index
n := 1 n := 1
for sect := Segtext.Sect.Next; sect != nil && sect.Name == ".text"; sect = sect.Next { for _, sect := range Segtext.Sections[1:] {
symname := fmt.Sprintf("runtime.text.%d", n) if sect.Name == ".text" {
ctxt.xdefine(symname, obj.STEXT, int64(sect.Vaddr)) symname := fmt.Sprintf("runtime.text.%d", n)
n++ ctxt.xdefine(symname, obj.STEXT, int64(sect.Vaddr))
n++
} else {
break
}
} }
ctxt.xdefine("runtime.rodata", obj.SRODATA, int64(rodata.Vaddr)) ctxt.xdefine("runtime.rodata", obj.SRODATA, int64(rodata.Vaddr))
......
...@@ -1618,7 +1618,7 @@ func dwarfaddpeheaders(ctxt *Link) { ...@@ -1618,7 +1618,7 @@ func dwarfaddpeheaders(ctxt *Link) {
if *FlagW { // disable dwarf if *FlagW { // disable dwarf
return return
} }
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdwarf.Sections {
h := newPEDWARFSection(ctxt, sect.Name, int64(sect.Length)) h := newPEDWARFSection(ctxt, sect.Name, int64(sect.Length))
fileoff := sect.Vaddr - Segdwarf.Vaddr + Segdwarf.Fileoff fileoff := sect.Vaddr - Segdwarf.Vaddr + Segdwarf.Fileoff
if uint64(h.PointerToRawData) != fileoff { if uint64(h.PointerToRawData) != fileoff {
......
...@@ -1831,7 +1831,7 @@ func Elfemitreloc(ctxt *Link) { ...@@ -1831,7 +1831,7 @@ func Elfemitreloc(ctxt *Link) {
Cput(0) Cput(0)
} }
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
if sect.Name == ".text" { if sect.Name == ".text" {
elfrelocsect(ctxt, sect, ctxt.Textp) elfrelocsect(ctxt, sect, ctxt.Textp)
} else { } else {
...@@ -1839,16 +1839,16 @@ func Elfemitreloc(ctxt *Link) { ...@@ -1839,16 +1839,16 @@ func Elfemitreloc(ctxt *Link) {
} }
} }
for sect := Segrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrodata.Sections {
elfrelocsect(ctxt, sect, datap) elfrelocsect(ctxt, sect, datap)
} }
for sect := Segrelrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrelrodata.Sections {
elfrelocsect(ctxt, sect, datap) elfrelocsect(ctxt, sect, datap)
} }
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdata.Sections {
elfrelocsect(ctxt, sect, datap) elfrelocsect(ctxt, sect, datap)
} }
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdwarf.Sections {
elfrelocsect(ctxt, sect, dwarfp) elfrelocsect(ctxt, sect, dwarfp)
} }
} }
...@@ -2167,7 +2167,7 @@ func Asmbelfsetup() { ...@@ -2167,7 +2167,7 @@ func Asmbelfsetup() {
/* This null SHdr must appear before all others */ /* This null SHdr must appear before all others */
elfshname("") elfshname("")
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
// There could be multiple .text sections. Instead check the Elfsect // There could be multiple .text sections. Instead check the Elfsect
// field to determine if already has an ElfShdr and if not, create one. // field to determine if already has an ElfShdr and if not, create one.
if sect.Name == ".text" { if sect.Name == ".text" {
...@@ -2178,16 +2178,16 @@ func Asmbelfsetup() { ...@@ -2178,16 +2178,16 @@ func Asmbelfsetup() {
elfshalloc(sect) elfshalloc(sect)
} }
} }
for sect := Segrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrodata.Sections {
elfshalloc(sect) elfshalloc(sect)
} }
for sect := Segrelrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrelrodata.Sections {
elfshalloc(sect) elfshalloc(sect)
} }
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdata.Sections {
elfshalloc(sect) elfshalloc(sect)
} }
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdwarf.Sections {
elfshalloc(sect) elfshalloc(sect)
} }
} }
...@@ -2216,7 +2216,7 @@ func Asmbelf(ctxt *Link, symo int64) { ...@@ -2216,7 +2216,7 @@ func Asmbelf(ctxt *Link, symo int64) {
elfreserve := int64(ELFRESERVE) elfreserve := int64(ELFRESERVE)
numtext := int64(0) numtext := int64(0)
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
if sect.Name == ".text" { if sect.Name == ".text" {
numtext++ numtext++
} }
...@@ -2367,10 +2367,10 @@ func Asmbelf(ctxt *Link, symo int64) { ...@@ -2367,10 +2367,10 @@ func Asmbelf(ctxt *Link, symo int64) {
// Additions to the reserved area must be above this line. // Additions to the reserved area must be above this line.
elfphload(&Segtext) elfphload(&Segtext)
if Segrodata.Sect != nil { if len(Segrodata.Sections) > 0 {
elfphload(&Segrodata) elfphload(&Segrodata)
} }
if Segrelrodata.Sect != nil { if len(Segrelrodata.Sections) > 0 {
elfphload(&Segrelrodata) elfphload(&Segrelrodata)
elfphrelro(&Segrelrodata) elfphrelro(&Segrelrodata)
} }
...@@ -2523,7 +2523,7 @@ func Asmbelf(ctxt *Link, symo int64) { ...@@ -2523,7 +2523,7 @@ func Asmbelf(ctxt *Link, symo int64) {
* Thread-local storage segment (really just size). * Thread-local storage segment (really just size).
*/ */
tlssize := uint64(0) tlssize := uint64(0)
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdata.Sections {
if sect.Name == ".tbss" { if sect.Name == ".tbss" {
tlssize = sect.Length tlssize = sect.Length
} }
...@@ -2566,33 +2566,33 @@ elfobj: ...@@ -2566,33 +2566,33 @@ elfobj:
elfshname(".strtab") elfshname(".strtab")
} }
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
elfshbits(sect) elfshbits(sect)
} }
for sect := Segrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrodata.Sections {
elfshbits(sect) elfshbits(sect)
} }
for sect := Segrelrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrelrodata.Sections {
elfshbits(sect) elfshbits(sect)
} }
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdata.Sections {
elfshbits(sect) elfshbits(sect)
} }
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdwarf.Sections {
elfshbits(sect) elfshbits(sect)
} }
if Linkmode == LinkExternal { if Linkmode == LinkExternal {
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
elfshreloc(sect) elfshreloc(sect)
} }
for sect := Segrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrodata.Sections {
elfshreloc(sect) elfshreloc(sect)
} }
for sect := Segrelrodata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segrelrodata.Sections {
elfshreloc(sect) elfshreloc(sect)
} }
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdata.Sections {
elfshreloc(sect) elfshreloc(sect)
} }
for _, s := range dwarfp { for _, s := range dwarfp {
......
...@@ -141,12 +141,12 @@ const ( ...@@ -141,12 +141,12 @@ const (
) )
type Segment struct { type Segment struct {
Rwx uint8 // permission as usual unix bits (5 = r-x etc) Rwx uint8 // permission as usual unix bits (5 = r-x etc)
Vaddr uint64 // virtual address Vaddr uint64 // virtual address
Length uint64 // length in memory Length uint64 // length in memory
Fileoff uint64 // file offset Fileoff uint64 // file offset
Filelen uint64 // length on disk Filelen uint64 // length on disk
Sect *Section Sections []*Section
} }
type Section struct { type Section struct {
...@@ -156,7 +156,6 @@ type Section struct { ...@@ -156,7 +156,6 @@ type Section struct {
Name string Name string
Vaddr uint64 Vaddr uint64
Length uint64 Length uint64
Next *Section
Seg *Segment Seg *Segment
Elfsect *ElfShdr Elfsect *ElfShdr
Reloff uint64 Reloff uint64
...@@ -1603,16 +1602,12 @@ func pathtoprefix(s string) string { ...@@ -1603,16 +1602,12 @@ func pathtoprefix(s string) string {
} }
func addsection(seg *Segment, name string, rwx int) *Section { func addsection(seg *Segment, name string, rwx int) *Section {
var l **Section
for l = &seg.Sect; *l != nil; l = &(*l).Next {
}
sect := new(Section) sect := new(Section)
sect.Rwx = uint8(rwx) sect.Rwx = uint8(rwx)
sect.Name = name sect.Name = name
sect.Seg = seg sect.Seg = seg
sect.Align = int32(SysArch.PtrSize) // everything is at least pointer-aligned sect.Align = int32(SysArch.PtrSize) // everything is at least pointer-aligned
*l = sect seg.Sections = append(seg.Sections, sect)
return sect return sect
} }
...@@ -1913,7 +1908,7 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, * ...@@ -1913,7 +1908,7 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, *
n := 0 n := 0
// Generate base addresses for all text sections if there are multiple // Generate base addresses for all text sections if there are multiple
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
if n == 0 { if n == 0 {
n++ n++
continue continue
......
...@@ -472,7 +472,7 @@ func Asmbmacho(ctxt *Link) { ...@@ -472,7 +472,7 @@ func Asmbmacho(ctxt *Link) {
ms.prot2 = 5 ms.prot2 = 5
} }
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
machoshbits(ctxt, ms, sect, "__TEXT") machoshbits(ctxt, ms, sect, "__TEXT")
} }
...@@ -488,7 +488,7 @@ func Asmbmacho(ctxt *Link) { ...@@ -488,7 +488,7 @@ func Asmbmacho(ctxt *Link) {
ms.prot2 = 3 ms.prot2 = 3
} }
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdata.Sections {
machoshbits(ctxt, ms, sect, "__DATA") machoshbits(ctxt, ms, sect, "__DATA")
} }
...@@ -501,7 +501,7 @@ func Asmbmacho(ctxt *Link) { ...@@ -501,7 +501,7 @@ func Asmbmacho(ctxt *Link) {
ms.fileoffset = Segdwarf.Fileoff ms.fileoffset = Segdwarf.Fileoff
ms.filesize = Segdwarf.Filelen ms.filesize = Segdwarf.Filelen
} }
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdwarf.Sections {
machoshbits(ctxt, ms, sect, "__DWARF") machoshbits(ctxt, ms, sect, "__DWARF")
} }
} }
...@@ -892,14 +892,14 @@ func Machoemitreloc(ctxt *Link) { ...@@ -892,14 +892,14 @@ func Machoemitreloc(ctxt *Link) {
Cput(0) Cput(0)
} }
machorelocsect(ctxt, Segtext.Sect, ctxt.Textp) machorelocsect(ctxt, Segtext.Sections[0], ctxt.Textp)
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections[1:] {
machorelocsect(ctxt, sect, datap) machorelocsect(ctxt, sect, datap)
} }
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdata.Sections {
machorelocsect(ctxt, sect, datap) machorelocsect(ctxt, sect, datap)
} }
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdwarf.Sections {
machorelocsect(ctxt, sect, dwarfp) machorelocsect(ctxt, sect, dwarfp)
} }
} }
...@@ -887,8 +887,8 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) { ...@@ -887,8 +887,8 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
} }
peemitsectreloc(text, func() int { peemitsectreloc(text, func() int {
n := perelocsect(ctxt, Segtext.Sect, ctxt.Textp, Segtext.Vaddr) n := perelocsect(ctxt, Segtext.Sections[0], ctxt.Textp, Segtext.Vaddr)
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections[1:] {
n += perelocsect(ctxt, sect, datap, Segtext.Vaddr) n += perelocsect(ctxt, sect, datap, Segtext.Vaddr)
} }
return n return n
...@@ -896,14 +896,14 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) { ...@@ -896,14 +896,14 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
peemitsectreloc(data, func() int { peemitsectreloc(data, func() int {
var n int var n int
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdata.Sections {
n += perelocsect(ctxt, sect, datap, Segdata.Vaddr) n += perelocsect(ctxt, sect, datap, Segdata.Vaddr)
} }
return n return n
}) })
dwarfLoop: dwarfLoop:
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for _, sect := range Segdwarf.Sections {
for i, name := range shNames { for i, name := range shNames {
if sect.Name == name { if sect.Name == name {
peemitsectreloc(&sh[i], func() int { peemitsectreloc(&sh[i], func() int {
......
...@@ -311,7 +311,7 @@ func textsectionmap(ctxt *Link) uint32 { ...@@ -311,7 +311,7 @@ func textsectionmap(ctxt *Link) uint32 {
t.Attr |= AttrReachable t.Attr |= AttrReachable
nsections := int64(0) nsections := int64(0)
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
if sect.Name == ".text" { if sect.Name == ".text" {
nsections++ nsections++
} else { } else {
...@@ -332,8 +332,8 @@ func textsectionmap(ctxt *Link) uint32 { ...@@ -332,8 +332,8 @@ func textsectionmap(ctxt *Link) uint32 {
// order of creation starting with 1. These symbols provide the section's // order of creation starting with 1. These symbols provide the section's
// address after relocation by the linker. // address after relocation by the linker.
textbase := Segtext.Sect.Vaddr textbase := Segtext.Sections[0].Vaddr
for sect := Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range Segtext.Sections {
if sect.Name != ".text" { if sect.Name != ".text" {
break break
} }
......
...@@ -185,10 +185,10 @@ func asmb(ctxt *ld.Link) { ...@@ -185,10 +185,10 @@ func asmb(ctxt *ld.Link) {
ld.Asmbelfsetup() ld.Asmbelfsetup()
} }
sect := ld.Segtext.Sect sect := ld.Segtext.Sections[0]
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
for sect = sect.Next; sect != nil; sect = sect.Next { for _, sect = range ld.Segtext.Sections[1:] {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
} }
......
...@@ -192,10 +192,10 @@ func asmb(ctxt *ld.Link) { ...@@ -192,10 +192,10 @@ func asmb(ctxt *ld.Link) {
ld.Asmbelfsetup() ld.Asmbelfsetup()
} }
sect := ld.Segtext.Sect sect := ld.Segtext.Sections[0]
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
for sect = sect.Next; sect != nil; sect = sect.Next { for _, sect = range ld.Segtext.Sections[1:] {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
} }
......
...@@ -880,7 +880,7 @@ func asmb(ctxt *ld.Link) { ...@@ -880,7 +880,7 @@ func asmb(ctxt *ld.Link) {
ld.Asmbelfsetup() ld.Asmbelfsetup()
} }
for sect := ld.Segtext.Sect; sect != nil; sect = sect.Next { for _, sect := range ld.Segtext.Sections {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
// Handle additional text sections with Codeblk // Handle additional text sections with Codeblk
if sect.Name == ".text" { if sect.Name == ".text" {
......
...@@ -512,10 +512,10 @@ func asmb(ctxt *ld.Link) { ...@@ -512,10 +512,10 @@ func asmb(ctxt *ld.Link) {
ld.Asmbelfsetup() ld.Asmbelfsetup()
} }
sect := ld.Segtext.Sect sect := ld.Segtext.Sections[0]
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
for sect = sect.Next; sect != nil; sect = sect.Next { for _, sect = range ld.Segtext.Sections[1:] {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
} }
......
...@@ -637,11 +637,11 @@ func asmb(ctxt *ld.Link) { ...@@ -637,11 +637,11 @@ func asmb(ctxt *ld.Link) {
ld.Asmbelfsetup() ld.Asmbelfsetup()
} }
sect := ld.Segtext.Sect sect := ld.Segtext.Sections[0]
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
// 0xCC is INT $3 - breakpoint instruction // 0xCC is INT $3 - breakpoint instruction
ld.CodeblkPad(ctxt, int64(sect.Vaddr), int64(sect.Length), []byte{0xCC}) ld.CodeblkPad(ctxt, int64(sect.Vaddr), int64(sect.Length), []byte{0xCC})
for sect = sect.Next; sect != nil; sect = sect.Next { for _, sect = range ld.Segtext.Sections[1:] {
ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
} }
......
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