cmd/link: change shdr and phdr from arrays to slices

Removes an arbitrary and unnecessary limit.

Change-Id: Iba04568ed5e6b1a8f8f23369f51f068e830f1059
Reviewed-on: https://go-review.googlesource.com/c/go/+/718600
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
This commit is contained in:
Ian Lance Taylor 2025-11-06 14:20:02 -08:00 committed by Gopher Robot
parent d3aeba1670
commit 6525f46707

View file

@ -101,10 +101,6 @@ var elfstrdat, elfshstrdat []byte
// On FreeBSD, cannot be larger than a page. // On FreeBSD, cannot be larger than a page.
const ELFRESERVE = 4096 const ELFRESERVE = 4096
const (
NSECT = 400
)
var ( var (
Nelfsym = 1 Nelfsym = 1
@ -114,8 +110,8 @@ var (
elfRelType string elfRelType string
ehdr ElfEhdr ehdr ElfEhdr
phdr [NSECT]*ElfPhdr phdr = make([]*ElfPhdr, 0, 8)
shdr [NSECT]*ElfShdr shdr = make([]*ElfShdr, 0, 64)
interp string interp string
) )
@ -334,12 +330,8 @@ func elfwritephdrs(out *OutBuf) uint32 {
func newElfPhdr() *ElfPhdr { func newElfPhdr() *ElfPhdr {
e := new(ElfPhdr) e := new(ElfPhdr)
if ehdr.Phnum >= NSECT { phdr = append(phdr, e)
Errorf("too many phdrs")
} else {
phdr[ehdr.Phnum] = e
ehdr.Phnum++ ehdr.Phnum++
}
if elf64 { if elf64 {
ehdr.Shoff += ELF64PHDRSIZE ehdr.Shoff += ELF64PHDRSIZE
} else { } else {
@ -352,13 +344,8 @@ func newElfShdr(name int64) *ElfShdr {
e := new(ElfShdr) e := new(ElfShdr)
e.Name = uint32(name) e.Name = uint32(name)
e.shnum = elf.SectionIndex(ehdr.Shnum) e.shnum = elf.SectionIndex(ehdr.Shnum)
if ehdr.Shnum >= NSECT { shdr = append(shdr, e)
Errorf("too many shdrs")
} else {
shdr[ehdr.Shnum] = e
ehdr.Shnum++ ehdr.Shnum++
}
return e return e
} }