]> Cypherpunks repositories - gostls13.git/commit
cmd/link: fix malformed .shstrtab section
authorThan McIntosh <thanm@google.com>
Wed, 13 Sep 2023 13:26:41 +0000 (09:26 -0400)
committerThan McIntosh <thanm@google.com>
Wed, 13 Sep 2023 16:29:40 +0000 (16:29 +0000)
commit3251006291c3e09c6ea40b6a65e5f05d9b9de573
treefe4f11203fd8595fc856446f05ac9f75e01cf189
parent584aad5c57f559fd2d6b9215eafd05f25937839f
cmd/link: fix malformed .shstrtab section

For ELF targets, the code in the go linker that generates the
".shstrtab" section was using a loader symbol to accumulate the
contents of the section, then setting the section type to
sym.SELFROSECT. This resulted in a section whose offset indicated that
it fell into a loadable ELF segment, which is not how the .shstrtab is
supposed to work (it should be outside of all loadable segments,
similar to .strtab and .symtab). The peculiar .shstrtab caused
confusion in third party tools that operate on ELF files, notably
llvm-strip.

This patch rewrites the .shstrtab generation code to avoid using a
loader.Symbol and instead accumulate the contents of the section into
a regular byte slice, then emit the section's data in the same way
that .strtab is handled.

Fixes #62600.

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Change-Id: Ie54020d7b2d779d3ac9f5465fd505217d0681f79
Reviewed-on: https://go-review.googlesource.com/c/go/+/528036
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/elf_test.go
src/cmd/link/internal/ld/symtab.go