1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:20:22 -07:00

cmd/link: unify text segment write

Currently we have two code paths of writing the text segment. They
are semantically the same:

- if we split text sections, we write all ".text" sections as
  text and the the rest as data.
- if we do not split text sections, we write the first section
  as text and the rest as data. The first section is named ".text"
  and is the only one in this case.

Unify the code.

Change-Id: Ic639eed625615be3c8a8d41f5b47e901552f587a
Reviewed-on: https://go-review.googlesource.com/c/go/+/316049
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2021-05-01 15:00:03 -04:00
parent 8327d2150f
commit be1da9cdee
3 changed files with 12 additions and 27 deletions

View File

@ -29,8 +29,6 @@ func asmb(ctxt *Link) {
}
var wg sync.WaitGroup
sect := Segtext.Sections[0]
offset := sect.Vaddr - Segtext.Vaddr + Segtext.Fileoff
f := func(ctxt *Link, out *OutBuf, start, length int64) {
pad := thearch.CodePad
if pad == nil {
@ -39,23 +37,14 @@ func asmb(ctxt *Link) {
CodeblkPad(ctxt, out, start, length, pad)
}
if !thearch.WriteTextBlocks {
writeParallel(&wg, f, ctxt, offset, sect.Vaddr, sect.Length)
for _, sect := range Segtext.Sections[1:] {
offset := sect.Vaddr - Segtext.Vaddr + Segtext.Fileoff
for _, sect := range Segtext.Sections {
offset := sect.Vaddr - Segtext.Vaddr + Segtext.Fileoff
// Handle text sections with Codeblk
if sect.Name == ".text" {
writeParallel(&wg, f, ctxt, offset, sect.Vaddr, sect.Length)
} else {
writeParallel(&wg, datblk, ctxt, offset, sect.Vaddr, sect.Length)
}
} else {
// TODO why can't we handle all sections this way?
for _, sect := range Segtext.Sections {
offset := sect.Vaddr - Segtext.Vaddr + Segtext.Fileoff
// Handle additional text sections with Codeblk
if sect.Name == ".text" {
writeParallel(&wg, f, ctxt, offset, sect.Vaddr, sect.Length)
} else {
writeParallel(&wg, datblk, ctxt, offset, sect.Vaddr, sect.Length)
}
}
}
if Segrodata.Filelen > 0 {

View File

@ -203,9 +203,6 @@ type Arch struct {
// are padded with zeros.
CodePad []byte
// Set to true to write all text blocks in with CodeBlkWrite
WriteTextBlocks bool
// Plan 9 variables.
Plan9Magic uint32
Plan9_64Bit bool

View File

@ -44,13 +44,12 @@ func Init() (*sys.Arch, ld.Arch) {
}
theArch := ld.Arch{
Funcalign: funcAlign,
Maxalign: maxAlign,
Minalign: minAlign,
Dwarfregsp: dwarfRegSP,
Dwarfreglr: dwarfRegLR,
TrampLimit: 0x1c00000,
WriteTextBlocks: true,
Funcalign: funcAlign,
Maxalign: maxAlign,
Minalign: minAlign,
Dwarfregsp: dwarfRegSP,
Dwarfreglr: dwarfRegLR,
TrampLimit: 0x1c00000,
Adddynrel: adddynrel,
Archinit: archinit,