Skip to content

Commit 6525f46

Browse files
ianlancetaylorgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Junyang Shao <[email protected]>
1 parent d3aeba1 commit 6525f46

File tree

1 file changed

+6
-19
lines changed
  • src/cmd/link/internal/ld

1 file changed

+6
-19
lines changed

src/cmd/link/internal/ld/elf.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ var elfstrdat, elfshstrdat []byte
101101
// On FreeBSD, cannot be larger than a page.
102102
const ELFRESERVE = 4096
103103

104-
const (
105-
NSECT = 400
106-
)
107-
108104
var (
109105
Nelfsym = 1
110106

@@ -114,8 +110,8 @@ var (
114110
elfRelType string
115111

116112
ehdr ElfEhdr
117-
phdr [NSECT]*ElfPhdr
118-
shdr [NSECT]*ElfShdr
113+
phdr = make([]*ElfPhdr, 0, 8)
114+
shdr = make([]*ElfShdr, 0, 64)
119115

120116
interp string
121117
)
@@ -334,12 +330,8 @@ func elfwritephdrs(out *OutBuf) uint32 {
334330

335331
func newElfPhdr() *ElfPhdr {
336332
e := new(ElfPhdr)
337-
if ehdr.Phnum >= NSECT {
338-
Errorf("too many phdrs")
339-
} else {
340-
phdr[ehdr.Phnum] = e
341-
ehdr.Phnum++
342-
}
333+
phdr = append(phdr, e)
334+
ehdr.Phnum++
343335
if elf64 {
344336
ehdr.Shoff += ELF64PHDRSIZE
345337
} else {
@@ -352,13 +344,8 @@ func newElfShdr(name int64) *ElfShdr {
352344
e := new(ElfShdr)
353345
e.Name = uint32(name)
354346
e.shnum = elf.SectionIndex(ehdr.Shnum)
355-
if ehdr.Shnum >= NSECT {
356-
Errorf("too many shdrs")
357-
} else {
358-
shdr[ehdr.Shnum] = e
359-
ehdr.Shnum++
360-
}
361-
347+
shdr = append(shdr, e)
348+
ehdr.Shnum++
362349
return e
363350
}
364351

0 commit comments

Comments
 (0)