Skip to content

Commit

Permalink
cmd/link: make .dynamic section read-only for MIPS ELF
Browse files Browse the repository at this point in the history
For #36435

Change-Id: Ie733b641f20ca5bcee3784c088eb27699890a151
Reviewed-on: https://go-review.googlesource.com/c/go/+/463982
Reviewed-by: Joel Sing <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
Reviewed-by: Than McIntosh <[email protected]>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Jan 31, 2023
1 parent 00e1091 commit 47e205c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cmd/link/internal/ld/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/link/internal/mips/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
4 changes: 4 additions & 0 deletions src/cmd/link/internal/mips64/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down

0 comments on commit 47e205c

Please sign in to comment.