]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: unify text segment write
authorCherry Zhang <cherryyz@google.com>
Sat, 1 May 2021 19:00:03 +0000 (15:00 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 3 May 2021 16:20:10 +0000 (16:20 +0000)
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>
src/cmd/link/internal/ld/asmb.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ppc64/obj.go

index fda043945506ca7d0c5b6a4e021feaff78ece8f6..375466955568689d4b1e8a48ffcae28f0c011742 100644 (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 {
index fd687df9efa39b8c91e26c9fa64bd7a2dd050797..e8f001ba8ec095f5e3e73a363db3b4537ee025a3 100644 (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
index f56fa76b5bbbade5a54ceb677803ab9af96246f7..b6d5ad92afa11d00923464d55522ea5a7e65184e 100644 (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,