]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: make .dynamic section read-only for MIPS ELF
authorIan Lance Taylor <iant@golang.org>
Sun, 29 Jan 2023 03:55:19 +0000 (19:55 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 31 Jan 2023 16:53:10 +0000 (16:53 +0000)
For #36435

Change-Id: Ie733b641f20ca5bcee3784c088eb27699890a151
Reviewed-on: https://go-review.googlesource.com/c/go/+/463982
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/mips/obj.go
src/cmd/link/internal/mips64/obj.go

index 738bea11c8ae9307c954e4a870e5d108d5cf87ad..2c6ea643fc76529bb18a1fd48f1e1e5cabf80e1f 100644 (file)
@@ -209,6 +209,11 @@ type ELFArch struct {
        Elfreloc1    func(*Link, *OutBuf, *loader.Loader, loader.Sym, loader.ExtReloc, int, int64) bool
        ElfrelocSize uint32 // size of an ELF relocation record, must match Elfreloc1.
        Elfsetupplt  func(ctxt *Link, plt, gotplt *loader.SymbolBuilder, dynamic loader.Sym)
+
+       // DynamicReadOnly can be set to true to make the .dynamic
+       // section read-only. By default it is writable.
+       // This is used by MIPS targets.
+       DynamicReadOnly bool
 }
 
 type Elfstring struct {
@@ -1563,7 +1568,11 @@ func (ctxt *Link) doelf() {
 
                /* define dynamic elf table */
                dynamic := ldr.CreateSymForUpdate(".dynamic", 0)
-               dynamic.SetType(sym.SELFSECT) // writable
+               if thearch.ELF.DynamicReadOnly {
+                       dynamic.SetType(sym.SELFROSECT)
+               } else {
+                       dynamic.SetType(sym.SELFSECT)
+               }
 
                if ctxt.IsS390X() {
                        // S390X uses .got instead of .got.plt
index 709c493a536538676af379d004f7533857da5bf5..61c22d986fc4576a0d378c6da54c56723aaaf9a8 100644 (file)
@@ -72,6 +72,10 @@ func Init() (*sys.Arch, ld.Arch) {
                        Elfreloc1:    elfreloc1,
                        ElfrelocSize: 8,
                        Elfsetupplt:  elfsetupplt,
+
+                       // Historically GNU ld creates a read-only
+                       // .dynamic section.
+                       DynamicReadOnly: true,
                },
        }
 
index 986cd078be6ceb2ad6c4cbb677df060c17b8d713..ce4494c61d9cb6a156e4fc1a7fff9ec71a669b7a 100644 (file)
@@ -70,6 +70,10 @@ func Init() (*sys.Arch, ld.Arch) {
                        Elfreloc1:    elfreloc1,
                        ElfrelocSize: 24,
                        Elfsetupplt:  elfsetupplt,
+
+                       // Historically GNU ld creates a read-only
+                       // .dynamic section.
+                       DynamicReadOnly: true,
                },
        }