Skip to content

Commit be1da9c

Browse files
committed
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 <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 8327d21 commit be1da9c

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

src/cmd/link/internal/ld/asmb.go

+6-17
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ func asmb(ctxt *Link) {
2929
}
3030

3131
var wg sync.WaitGroup
32-
sect := Segtext.Sections[0]
33-
offset := sect.Vaddr - Segtext.Vaddr + Segtext.Fileoff
3432
f := func(ctxt *Link, out *OutBuf, start, length int64) {
3533
pad := thearch.CodePad
3634
if pad == nil {
@@ -39,23 +37,14 @@ func asmb(ctxt *Link) {
3937
CodeblkPad(ctxt, out, start, length, pad)
4038
}
4139

42-
if !thearch.WriteTextBlocks {
43-
writeParallel(&wg, f, ctxt, offset, sect.Vaddr, sect.Length)
44-
for _, sect := range Segtext.Sections[1:] {
45-
offset := sect.Vaddr - Segtext.Vaddr + Segtext.Fileoff
40+
for _, sect := range Segtext.Sections {
41+
offset := sect.Vaddr - Segtext.Vaddr + Segtext.Fileoff
42+
// Handle text sections with Codeblk
43+
if sect.Name == ".text" {
44+
writeParallel(&wg, f, ctxt, offset, sect.Vaddr, sect.Length)
45+
} else {
4646
writeParallel(&wg, datblk, ctxt, offset, sect.Vaddr, sect.Length)
4747
}
48-
} else {
49-
// TODO why can't we handle all sections this way?
50-
for _, sect := range Segtext.Sections {
51-
offset := sect.Vaddr - Segtext.Vaddr + Segtext.Fileoff
52-
// Handle additional text sections with Codeblk
53-
if sect.Name == ".text" {
54-
writeParallel(&wg, f, ctxt, offset, sect.Vaddr, sect.Length)
55-
} else {
56-
writeParallel(&wg, datblk, ctxt, offset, sect.Vaddr, sect.Length)
57-
}
58-
}
5948
}
6049

6150
if Segrodata.Filelen > 0 {

src/cmd/link/internal/ld/lib.go

-3
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ type Arch struct {
203203
// are padded with zeros.
204204
CodePad []byte
205205

206-
// Set to true to write all text blocks in with CodeBlkWrite
207-
WriteTextBlocks bool
208-
209206
// Plan 9 variables.
210207
Plan9Magic uint32
211208
Plan9_64Bit bool

src/cmd/link/internal/ppc64/obj.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ func Init() (*sys.Arch, ld.Arch) {
4444
}
4545

4646
theArch := ld.Arch{
47-
Funcalign: funcAlign,
48-
Maxalign: maxAlign,
49-
Minalign: minAlign,
50-
Dwarfregsp: dwarfRegSP,
51-
Dwarfreglr: dwarfRegLR,
52-
TrampLimit: 0x1c00000,
53-
WriteTextBlocks: true,
47+
Funcalign: funcAlign,
48+
Maxalign: maxAlign,
49+
Minalign: minAlign,
50+
Dwarfregsp: dwarfRegSP,
51+
Dwarfreglr: dwarfRegLR,
52+
TrampLimit: 0x1c00000,
5453

5554
Adddynrel: adddynrel,
5655
Archinit: archinit,

0 commit comments

Comments
 (0)