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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Michael Hudson-Doyle 2017-04-18 21:52:06 +12:00
parent 46ecac99fb
commit 743fe0697d
15 changed files with 92 additions and 91 deletions

View file

@ -141,12 +141,12 @@ const (
)
type Segment struct {
Rwx uint8 // permission as usual unix bits (5 = r-x etc)
Vaddr uint64 // virtual address
Length uint64 // length in memory
Fileoff uint64 // file offset
Filelen uint64 // length on disk
Sect *Section
Rwx uint8 // permission as usual unix bits (5 = r-x etc)
Vaddr uint64 // virtual address
Length uint64 // length in memory
Fileoff uint64 // file offset
Filelen uint64 // length on disk
Sections []*Section
}
type Section struct {
@ -156,7 +156,6 @@ type Section struct {
Name string
Vaddr uint64
Length uint64
Next *Section
Seg *Segment
Elfsect *ElfShdr
Reloff uint64
@ -1603,16 +1602,12 @@ func pathtoprefix(s string) string {
}
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.Rwx = uint8(rwx)
sect.Name = name
sect.Seg = seg
sect.Align = int32(SysArch.PtrSize) // everything is at least pointer-aligned
*l = sect
seg.Sections = append(seg.Sections, sect)
return sect
}
@ -1913,7 +1908,7 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, *
n := 0
// 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 {
n++
continue