1
0
mirror of https://github.com/golang/go synced 2024-11-19 05:04:43 -07:00

Revert "cmd/link: separate virtual address layout from file layout"

This reverts commit bd83774593.

Reason for revert: This broke ELF layout on arm, arm64, mips*, mips64*, ppc64*, and s390x.

Change-Id: I56a27b76e6f4b22ce39a99790af9116f8687eee9
Reviewed-on: https://go-review.googlesource.com/118675
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Austin Clements 2018-06-13 17:42:22 +00:00
parent 24d29e85cb
commit a1b85ee754
2 changed files with 29 additions and 42 deletions

View File

@ -1903,15 +1903,12 @@ func assignAddress(ctxt *Link, sect *sym.Section, n int, s *sym.Symbol, va uint6
return sect, n, va
}
// address assigns virtual addresses to all segments and sections and
// returns all segments in file order.
func (ctxt *Link) address() []*sym.Segment {
var order []*sym.Segment // Layout order
// assign addresses
func (ctxt *Link) address() {
va := uint64(*FlagTextAddr)
order = append(order, &Segtext)
Segtext.Rwx = 05
Segtext.Vaddr = va
Segtext.Fileoff = uint64(HEADR)
for _, s := range Segtext.Sections {
va = uint64(Rnd(int64(va), int64(s.Align)))
s.Vaddr = va
@ -1919,6 +1916,7 @@ func (ctxt *Link) address() []*sym.Segment {
}
Segtext.Length = va - uint64(*FlagTextAddr)
Segtext.Filelen = Segtext.Length
if ctxt.HeadType == objabi.Hnacl {
va += 32 // room for the "halt sled"
}
@ -1939,9 +1937,13 @@ func (ctxt *Link) address() []*sym.Segment {
// writable even for this short period.
va = uint64(Rnd(int64(va), int64(*FlagRound)))
order = append(order, &Segrodata)
Segrodata.Rwx = 04
Segrodata.Vaddr = va
Segrodata.Fileoff = va - Segtext.Vaddr + Segtext.Fileoff
Segrodata.Filelen = 0
if ctxt.HeadType == objabi.Hwindows {
Segrodata.Fileoff = Segtext.Fileoff + uint64(Rnd(int64(Segtext.Length), PEFILEALIGN))
}
for _, s := range Segrodata.Sections {
va = uint64(Rnd(int64(va), int64(s.Align)))
s.Vaddr = va
@ -1949,15 +1951,17 @@ func (ctxt *Link) address() []*sym.Segment {
}
Segrodata.Length = va - Segrodata.Vaddr
Segrodata.Filelen = Segrodata.Length
}
if len(Segrelrodata.Sections) > 0 {
// align to page boundary so as not to mix
// rodata, rel-ro data, and executable text.
va = uint64(Rnd(int64(va), int64(*FlagRound)))
order = append(order, &Segrelrodata)
Segrelrodata.Rwx = 06
Segrelrodata.Vaddr = va
Segrelrodata.Fileoff = va - Segrodata.Vaddr + Segrodata.Fileoff
Segrelrodata.Filelen = 0
for _, s := range Segrelrodata.Sections {
va = uint64(Rnd(int64(va), int64(s.Align)))
s.Vaddr = va
@ -1965,12 +1969,20 @@ func (ctxt *Link) address() []*sym.Segment {
}
Segrelrodata.Length = va - Segrelrodata.Vaddr
Segrelrodata.Filelen = Segrelrodata.Length
}
va = uint64(Rnd(int64(va), int64(*FlagRound)))
order = append(order, &Segdata)
Segdata.Rwx = 06
Segdata.Vaddr = va
Segdata.Fileoff = va - Segtext.Vaddr + Segtext.Fileoff
Segdata.Filelen = 0
if ctxt.HeadType == objabi.Hwindows {
Segdata.Fileoff = Segrodata.Fileoff + uint64(Rnd(int64(Segrodata.Length), PEFILEALIGN))
}
if ctxt.HeadType == objabi.Hplan9 {
Segdata.Fileoff = Segtext.Fileoff + Segtext.Filelen
}
var data *sym.Section
var noptr *sym.Section
var bss *sym.Section
@ -2000,14 +2012,16 @@ func (ctxt *Link) address() []*sym.Segment {
}
}
// Assign Segdata's Filelen omitting the BSS. We do this here
// simply because right now we know where the BSS starts.
Segdata.Filelen = bss.Vaddr - Segdata.Vaddr
va = uint64(Rnd(int64(va), int64(*FlagRound)))
order = append(order, &Segdwarf)
Segdwarf.Rwx = 06
Segdwarf.Vaddr = va
Segdwarf.Fileoff = Segdata.Fileoff + uint64(Rnd(int64(Segdata.Filelen), int64(*FlagRound)))
Segdwarf.Filelen = 0
if ctxt.HeadType == objabi.Hwindows {
Segdwarf.Fileoff = Segdata.Fileoff + uint64(Rnd(int64(Segdata.Filelen), PEFILEALIGN))
}
for i, s := range Segdwarf.Sections {
vlen := int64(s.Length)
if i+1 < len(Segdwarf.Sections) {
@ -2021,6 +2035,8 @@ func (ctxt *Link) address() []*sym.Segment {
Segdwarf.Length = va - Segdwarf.Vaddr
}
Segdwarf.Filelen = va - Segdwarf.Vaddr
var (
text = Segtext.Sections[0]
rodata = ctxt.Syms.Lookup("runtime.rodata", 0).Sect
@ -2107,34 +2123,6 @@ func (ctxt *Link) address() []*sym.Segment {
ctxt.xdefine("runtime.noptrbss", sym.SNOPTRBSS, int64(noptrbss.Vaddr))
ctxt.xdefine("runtime.enoptrbss", sym.SNOPTRBSS, int64(noptrbss.Vaddr+noptrbss.Length))
ctxt.xdefine("runtime.end", sym.SBSS, int64(Segdata.Vaddr+Segdata.Length))
return order
}
// layout assigns file offsets and lengths to the segments in order.
func (ctxt *Link) layout(order []*sym.Segment) {
var prev *sym.Segment
for _, seg := range order {
if prev == nil {
seg.Fileoff = uint64(HEADR)
} else {
switch ctxt.HeadType {
default:
seg.Fileoff = prev.Fileoff + uint64(Rnd(int64(prev.Filelen), int64(*FlagRound)))
case objabi.Hwindows:
seg.Fileoff = prev.Fileoff + uint64(Rnd(int64(prev.Filelen), PEFILEALIGN))
case objabi.Hplan9:
seg.Fileoff = prev.Fileoff + prev.Filelen
}
}
if seg != &Segdata {
// Link.address already set Segdata.Filelen to
// account for BSS.
seg.Filelen = seg.Length
}
prev = seg
}
}
// add a trampoline with symbol s (to be laid down after the current function)

View File

@ -224,9 +224,8 @@ func Main(arch *sys.Arch, theArch Arch) {
ctxt.typelink()
ctxt.symtab()
ctxt.dodata()
order := ctxt.address()
ctxt.address()
ctxt.reloc()
ctxt.layout(order)
thearch.Asmb(ctxt)
ctxt.undef()
ctxt.hostlink()