1
0
mirror of https://github.com/golang/go synced 2024-11-17 15:04:45 -07:00

cmd/link: make .dynamic section read-only for MIPS ELF

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>
This commit is contained in:
Ian Lance Taylor 2023-01-28 19:55:19 -08:00 committed by Gopher Robot
parent 00e1091bfd
commit 47e205c344
3 changed files with 18 additions and 1 deletions

View 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

View 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,
},
}

View 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,
},
}