aboutsummaryrefslogtreecommitdiff
path: root/src/debug/elf
AgeCommit message (Collapse)Author
2025-03-14debug/elf: add riscv attributes definitionsMeng Zhuo
This CL adds `riscv.attributes` related ELF section header type and program header type according to [RISC-V ELF Specification](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/download/v1.0/riscv-abi.pdf) Also an riscv64/linux testcase binary built from: ``` gcc -march=rv64g -no-pie -o gcc-riscv64-linux-exec hello.c strip gcc-riscv64-linux-exec ``` Fixes #72843 Change-Id: I7710a0516f69141c0efaba71dd997f05b4c88421 Reviewed-on: https://go-review.googlesource.com/c/go/+/657515 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-12-17debug/elf: adjust version API per issue discussionIan Lance Taylor
This updates the new version API for the discussion on #63952. Note that the current tests do not have symbols with hidden versions. Leaving that for later. For #63952 Change-Id: I1ad4b1e485429a216ba8e5b68f7f4299d120628f Reviewed-on: https://go-review.googlesource.com/c/go/+/637235 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Austin Clements <austin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
2024-12-11debug/elf: adjust version API per issue discussionIan Lance Taylor
This updates the new version API for the discussion on #63952. This change reveals that in fact none of the tests set the VERSYM_HIDDEN bit. The code before this CL set the hidden flag for symbols that appear in DynamicVersionNeed, but that is not an accurate representation of the ELF. The readelf program does print undefined symbols that way (with a single '@'), but that doesn't mean that the hidden flag is set. Leaving tests with the hidden bit set for later. For #63952 Change-Id: Ida60831e0c9922dfc10f10c7a64bc76a2b197537 Reviewed-on: https://go-review.googlesource.com/c/go/+/635079 Reviewed-by: Austin Clements <austin@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-11-27debug/elf: check for multiplication overflow for shnum * shentsizeIan Lance Taylor
No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. For #47653 Fixes #70584 Change-Id: I8a69a27dcb5b258b88f8e01ebaf0ec20cfcd489b Reviewed-on: https://go-review.googlesource.com/c/go/+/632035 Reviewed-by: Veronica Silina <veronicasilina@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-11-07debug/elf: add SHT_GNU_VERDEF section parsingbenbaker76
Fixes #63952 Change-Id: Icf93e57e62243d9c3306d4e1c5dadb3f62747710 GitHub-Last-Rev: 5c2952760063474f3aac338fe5bdb65bde238ab6 GitHub-Pull-Request: golang/go#69850 Reviewed-on: https://go-review.googlesource.com/c/go/+/619077 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-23debug/elf: remove incorrect doc linkIan Lance Taylor
Here Version is a field in Symbol, not the elf.Version type. Change-Id: I0285937d806d1a9b53b49420b45a07744be244c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/563095 Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Austin Clements <austin@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-04-16debug/elf: define non-standard but well-known symbol typesIan Lance Taylor
Fixes #66836 Change-Id: I603faca2acd2bcffabbcaca8b8670d46387d2a5b Reviewed-on: https://go-review.googlesource.com/c/go/+/578995 Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-03-15debug/elf: avoid using binary.Read() in NewFile()Peter Collingbourne
With this change my test program that reads a tree of ELF files runs 1.71 ± 0.12 times faster without parallelism or 1.39 ± 0.06 times faster using 8 goroutines. Change-Id: I443d1a02736f16f5532ef28e1447c97aa87c7126 Reviewed-on: https://go-review.googlesource.com/c/go/+/571436 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-03-10cmd/link,debug/elf: mark Go binaries with no branch target CFI on openbsdJoel Sing
OpenBSD enables Indirect Branch Tracking (IBT) on amd64 and Branch Target Identification (BTI) on arm64, where hardware permits. Since Go generated binaries do not currently support IBT or BTI, temporarily mark them with PT_OPENBSD_NOBTCFI which prevents branch target CFI from being enforced on execution. This should be removed as soon asn IBT and BTI support are available. Fixes #66040 Updates #66054 Change-Id: I91ac05736e6942c54502bef4b8815eb8740d2d5e Reviewed-on: https://go-review.googlesource.com/c/go/+/568435 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Josh Rickmar <jrick@zettaport.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Joel Sing <joel@sing.id.au> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2023-12-30all: replace outdated linkscui fliter
Change-Id: I7156e7858e8f06459818e03729c644d64e04d43c Reviewed-on: https://go-review.googlesource.com/c/go/+/549356 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-30debug/elf: return error in DynValue for invalid dynamic section sizeJes Cok
This is a follow-up to CL 536400. Fixes #64446 Change-Id: I35646732f62cb1937fd448f94ea518544d4295d4 GitHub-Last-Rev: 55db18a909fd44e6b2f2b98fd1a44ad01bb37932 GitHub-Pull-Request: golang/go#64448 Reviewed-on: https://go-review.googlesource.com/c/go/+/545835 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: Jes Cok <xigua67damn@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-11-02debug/elf,cmd/link: add additional relocations for loong64Guoqi Chen
The Linker Relaxation feature on Loong64 is already supported in binutils 2.41. The intermediate code generated after enabling this feature introduces three reloc types R_LARCH_B26, R_LARCH_ADD32 and R_LARCH_SUB32. The other relocation types are not currently used when running all.bash, but in order to avoid the host tool chain making the decision to use it we don't have to catch it every time. The LoongArch ABI at here: https://github.com/loongson/la-abi-specs/blob/release/la-abi.adoc Corresponding binutils implementation: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=be1ebb6710a8f707bd4b0eecbd00f4f4964050e5 https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=1b6fccd28db14fffe75ff6755307047ef932c81e Fixes #63725 Change-Id: I891115cfdbcf785ab494c881d5f9d1bf8748da8b Reviewed-on: https://go-review.googlesource.com/c/go/+/537615 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Meidan Li <limeidan@loongson.cn> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-25debug/elf: return error in DynString for invalid dynamic section sizeIan Lance Taylor
No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. Fixes #63610 Change-Id: I797b4d9bdb08286ad3e3a9a6f800ee8c90cb7261 Reviewed-on: https://go-review.googlesource.com/c/go/+/536400 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
2023-10-18debug: add available godoc linkcui fliter
Change-Id: I9e7b7e10d9e3d23e4ed540eb8137cd1f4d103711 Reviewed-on: https://go-review.googlesource.com/c/go/+/534761 Reviewed-by: Carlos Amedee <carlos@golang.org> Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-22all: clean unnecessary casts for test filesJes Cok
This is a follow up of CL 528696. Change-Id: I5b71eabedb12567c4b1b36f7182a3d2b0ed662a5 GitHub-Last-Rev: acaf3ac11c38042ad27b99e1c70a3c9f1a554a15 GitHub-Pull-Request: golang/go#62713 Reviewed-on: https://go-review.googlesource.com/c/go/+/529197 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-20debug/elf: don't crash on empty symbol sectionIan Lance Taylor
No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. Fixes #62649 Change-Id: Ia40b4d415e3bbffaffd143ee280949ba41346579 Reviewed-on: https://go-review.googlesource.com/c/go/+/528655 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2023-09-08debug/elf,cmd/link: add additional MIPS64 relocation typeJoel Sing
Add R_MIPS_PC32 which is a 32 bit PC relative relocation. These are produced by LLVM on mips64. Fixes #61974 Change-Id: I7b6c6848e40249e6d5ea474ea53c9d7e3ab23f88 Reviewed-on: https://go-review.googlesource.com/c/go/+/469395 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Joel Sing <joel@sing.id.au> Reviewed-by: Junxian Zhu <zhujunxian@oss.cipunited.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-07all: use io.{SeekStart, SeekCurrent, SeekEnd}Jes Cok
Currently we include these symbols in bootstrap code. Change-Id: I19b504237b0344f0e87cda0fbe651811c72daba1 GitHub-Last-Rev: 5134baec387659c5e2ca8c4fc65a5e73c07f00ce GitHub-Pull-Request: golang/go#62368 Reviewed-on: https://go-review.googlesource.com/c/go/+/524258 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-08-31all: rewrite internal/saferio.SliceCap using generics and add func ↵Jes Cok
SliceCapWithSize Change-Id: I265173bf2722796c4be545c968efef3a1a6f7a7d GitHub-Last-Rev: 04d95cdd615f906167545f246f707e1440c39374 GitHub-Pull-Request: golang/go#62365 Reviewed-on: https://go-review.googlesource.com/c/go/+/524257 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-07-31debug/elf: don't use reflection in File.SymbolsTolya Korniltsev
cpu: AMD Ryzen 9 5950X 16-Core Processor | old.txt | new.txt | | sec/op | sec/op vs base | Symbols64-32 18.486µ ± 2% 4.509µ ± 24% -75.61% (p=0.000 n=10) Symbols32-32 17.823µ ± 3% 4.798µ ± 2% -73.08% (p=0.000 n=10) geomean 18.15µ 4.651µ -74.38% | old.txt | new.txt | | B/op | B/op vs base | Symbols64-32 10.680Ki ± 0% 8.922Ki ± 0% -16.46% (p=0.000 n=10) Symbols32-32 9.773Ki ± 0% 8.570Ki ± 0% -12.31% (p=0.000 n=10) geomean 10.22Ki 8.744Ki -14.41% | old.txt | new.txt | | allocs/op | allocs/op vs base | Symbols64-32 119.00 ± 0% 45.00 ± 0% -62.18% (p=0.000 n=10) Symbols32-32 125.00 ± 0% 50.00 ± 0% -60.00% (p=0.000 n=10) geomean 122.0 47.43 -61.11% Fixes #61534 Change-Id: I13a96467108771df31f018853df754e42100e773 Reviewed-on: https://go-review.googlesource.com/c/go/+/512395 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-05-24all: fix unavailable urlcui fliter
RISC-V modified the address of github and the suffix of the file. The previous link is no longer accessible. use latest link. Change-Id: I5e33ea8447a59b8183658248df05c79ddd380cba Reviewed-on: https://go-review.googlesource.com/c/go/+/497378 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-05-23debug/elf: define R_PPC64_REL24_P9NOTOCPaul E. Murphy
This relocation is not (yet?) defined in ELFv2, but has been added to gnu gas a couple years ago. It is the same reloc as R_PPC64_REL24_NOTOC, but hints power10 instructions should not be emitted. See binutils commit 7aba54da426b9999085d8f84e7896b8afdbb9ca6. Fixes #60348 Change-Id: Ie953cd7bf1ffc621b498d4dbebb5de1231833c8f Reviewed-on: https://go-review.googlesource.com/c/go/+/496918 Run-TryBot: Paul Murphy <murp@ibm.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-04-18debug/elf: support zstd compressionIan Lance Taylor
Test cases added to debug/dwarf because that is where it matters in practice. The new test binary line-gcc-zstd.elf built with gcc -g -no-pie -Wl,--compress-debug-sections=zstd line[12].c using gcc (Debian 12.2.0-10) 12.2.0 with a development version of the GNU binutils. Fixes #55107 Change-Id: I48507c96902e1f83a174e5647b5cc403d965b52b Reviewed-on: https://go-review.googlesource.com/c/go/+/473256 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2023-04-11all: add wasip1 supportJohan Brandhorst-Satzkorn
Fixes #58141 Co-authored-by: Richard Musiol <neelance@gmail.com> Co-authored-by: Achille Roussel <achille.roussel@gmail.com> Co-authored-by: Julien Fabre <ju.pryz@gmail.com> Co-authored-by: Evan Phoenix <evan@phx.io> Change-Id: I49b66946acc90fdf09ed9223096bfec9a1e5b923 Reviewed-on: https://go-review.googlesource.com/c/go/+/479627 Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Bypass: Ian Lance Taylor <iant@golang.org>
2023-04-11debug/elf: avoid decompress of section twiceMeng Zhuo
In rare cases, elf will get a corrupted section starts with 0x1, which happens to be COMPRESS_ZLIB that causing decompress twice. This CL drops sectionData decompress data after open section. Fixes #59208 Change-Id: I7999a55868b3b3481509e1ac35985f7580f0f688 Reviewed-on: https://go-review.googlesource.com/c/go/+/480895 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: M Zhuo <mzh@golangcn.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-03-07debug/elf: retrieve values for dynamic section tagsFlorin Papa
Add functionality to retrieve values for .dynamic entries that don't correspond to entries in the string table. Fixes #56892 Change-Id: I6edabc8ca331c819e442d06e19b7f4df8343372b Reviewed-on: https://go-review.googlesource.com/c/go/+/452617 Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-03debug/elf: add DT_FLAGS_1 constantsFlorin Papa
Add constants for all ELF dynamic flags (pertaining to DT_FLAGS_1). This will help, for example, determining whether an object is a position-independent executable (PIE). The constants are defined according to Table 15-10 in https://docs.oracle.com/en/operating-systems/solaris/oracle-solaris/11.4/linkers-libraries/dynamic-section.html. Fixes #56887 Change-Id: I6cd501af50d9dbcc2aa8a9a002e12c6fb6726761 Reviewed-on: https://go-review.googlesource.com/c/go/+/452496 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-26debug/elf: guard access to File.gnuVersymZeke Lu
The size of gnuVersym should be multiples of 2. If not, the input is invalid. No Library and Version information is added to sym in this case. The current implementation of gnuVersion does not report errors for invalid input. While at here, bring back the comment that states that the undef entry at the beginning is skipped. This is not an off-by-one error. No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. Fixes #56429. Change-Id: Ia39ad8bd509088a81cc77f7a76e23185d40a5765 GitHub-Last-Rev: 3be0cc1b1522874cf5dc509678aa6a5658b6bad5 GitHub-Pull-Request: golang/go#56431 Reviewed-on: https://go-review.googlesource.com/c/go/+/445555 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Meng Zhuo <mzh@golangcn.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-10-25debug/elf: use saferio.SliceCap when decoding ELF sectionsZeke Lu
This avoids allocating an overly large slice for corrupt input. No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. Updates #33121. Change-Id: Ie2d947a3865d3499034286f2d08d3e3204015f3e GitHub-Last-Rev: 6c62fc3cec1c6343c76f22f6a2a4ddae060fa2f4 GitHub-Pull-Request: golang/go#56405 Reviewed-on: https://go-review.googlesource.com/c/go/+/445076 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-10-14debug/elf: fix inccorrect value in COMPRESS_ZLIB string nameFlorian Zenker
LLVM recently introduced ZSTD compression for ELF sections. The error message when failing to read the compressed section calls this COMPRESS_ZLIB+2 while it should report it as COMPRESS_ZLIB+1. Change-Id: I869aa69baf0c8c86665475b47343c790587cb39b Reviewed-on: https://go-review.googlesource.com/c/go/+/443035 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-13debug: add top level security docs for dwarf, elf, macho, pe, and plan9objRoland Shoemaker
Adds a package level doc comment to the debug/dwarf, debug/elf, debug/macho, debug/pe, and debug/plan9obj noting that these packages are not designed to be hardened against adversarial inputs. Change-Id: I678d01bcdc8ad01c23805f09cc59e64cec6c3f76 Reviewed-on: https://go-review.googlesource.com/c/go/+/435417 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Julie Qiu <julieqiu@google.com> Run-TryBot: Roland Shoemaker <roland@golang.org> Auto-Submit: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-12debug/elf: validate phentsize and shentsizeIan Lance Taylor
No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. Fixes #56129 Change-Id: I6c81933781384c5e2c8ba0fd99cec50455b9664a Reviewed-on: https://go-review.googlesource.com/c/go/+/441976 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Joedian Reid <joedian@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2022-09-29debug/elf: fix typo in R_PPC64_TPREL34 and R_PPC64_DTPREL34Paul E. Murphy
The suffix should be 34 not 28. I misread the name because the reloc listed before these two in the ABI is named "R_PC64_PCREL28". Updates #54345 Change-Id: Ie8238f55e441c787d70ead58e0a177c650f8b89e Reviewed-on: https://go-review.googlesource.com/c/go/+/435415 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Paul Murphy <murp@ibm.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-27debug/elf: return error on reading from SHT_NOBITS sectionsZeke Lu
An SHT_NOBITS section contains no bytes and occupies no space in the file. This change makes it return an error on reading from this section so that it will force the caller to check for an SHT_NNOBITS section. We have considered another option to return "nil, nil" for the Data method. It's abandoned because it might lead a program to simply do the wrong thing, thinking that the section is empty. Please note that it breaks programs which expect a byte slice with the length described by the sh_size field. There are two reasons to introduce this breaking change: 1. SHT_NOBITS means no data and it's unnecessary to allocate memory for it; 2. it could result in an OOM if the file is corrupted and has a huge sh_size. Fixes #54967. Change-Id: I0c3ed4e097214fe88413d726a89122105ad45d4f GitHub-Last-Rev: 994c12d9da8c7029ce1d26eb1eb4d333ef3b1f97 GitHub-Pull-Request: golang/go#54994 Reviewed-on: https://go-review.googlesource.com/c/go/+/429601 Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-09-27debug/elf: suport files with >= 65280 (0xff00) sectionsZeke Lu
The spec https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html states: 1. e_shnum: If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), this member has the value zero and the actual number of section header table entries is contained in the sh_size field of the section header at index 0. 2. e_shstrndx: If the section name string table section index is greater than or equal to SHN_LORESERVE (0xff00), this member has the value SHN_XINDEX (0xffff) and the actual index of the section name string table section is contained in the sh_link field of the section header at index 0. This CL makes these changes to support files with >= 0xff00 sections: 1. if shoff > 0 && shnum == 0, read sh_size from the initial section header entry as shnum. 2. if shstrndx == SHN_XINDEX, read sh_link from the initial section header entry as shstrndx. It returns an error if the type of the initial section is not SHT_NULL. A file with >= 0xff00 sections is too big to include in the repository, so the test case constructs one on the fly, with some of the sections zeroed out. While here, remove the unnecessary use of reflect.DeepEqual in the test. Fixes #55294. Change-Id: I15ec43612c7cce6e8decfe4e81da3a5b16de47f7 GitHub-Last-Rev: 797c16480bc76524ff1a7c01ed09b759fcd7d45b GitHub-Pull-Request: golang/go#55295 Reviewed-on: https://go-review.googlesource.com/c/go/+/432255 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-09-19debug/elf: validate shstrndxZeke Lu
Changes: 1. When e_shstrndx holds the value SHN_UNDEF (0), the file has no section name string table. In this case, do not try to set section names . 2. e_shstrndx should point to an SHT_STRTAB section. If it does not, returns an error. Reference: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html Updates #54967. Change-Id: Ic8f228061d996fd7845dfa630719a1ba12d2bb60 GitHub-Last-Rev: aeb70ca8a08e7dbc36ed61bd5a2dabcf432540e9 GitHub-Pull-Request: golang/go#55001 Reviewed-on: https://go-review.googlesource.com/c/go/+/430155 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-08debug/elf: define additional PPC64 ELFv2 relocationsPaul E. Murphy
The PPC64 ELFv2 supplement version 1.5 defines a handful of new relocation types, similarly some were not added. Fixes #54345 Change-Id: Id39b29d404298fca4a10ccf1e96b5964dc452c9e Reviewed-on: https://go-review.googlesource.com/c/go/+/425555 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-29debug/elf: validate offset and file size rangesDan Kortschak
Change-Id: Iebe31b91c6e81438120f50a8089a8efca3d5339d Reviewed-on: https://go-review.googlesource.com/c/go/+/426115 Run-TryBot: Dan Kortschak <dan@kortschak.io> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-27debug/elf: fix reloc number of R_PPC64_SECTOFF_LO_DSPaul E. Murphy
R_PPC64_SECTOFF_LO_DS is defined as reloc 62 on all PPC64 ELF ABIs. Fixes #53356 Change-Id: I5fabf6be32f3310c5aed47d4d654e05fb7bc9de0 Reviewed-on: https://go-review.googlesource.com/c/go/+/411915 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Paul Murphy <murp@ibm.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-11debug/elf: use saferio to read section dataIan Lance Taylor
For #47653 Fixes #45599 Fixes #52522 Change-Id: Id6a80186434080cb0a205978ad7f224252674604 Reviewed-on: https://go-review.googlesource.com/c/go/+/408679 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-08-11debug/elf: add new-style LoongArch reloc typesWANG Xuerui
LoongArch ELF psABI spec update: https://github.com/loongson/LoongArch-Documentation/pull/57 Corresponding binutils implementation: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6d13722a97cee3fd397e116bde3bcedbb1e220be https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9801120721c3a702ce3bd50433ef920f92a83502 For #54222 Change-Id: I51e72294205847a69c01d741a3126248f7a7e41c Reviewed-on: https://go-review.googlesource.com/c/go/+/420982 Reviewed-by: Meng Zhuo <mzh@golangcn.org> Run-TryBot: Meng Zhuo <mzh@golangcn.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: abner chenc <chenguoqi@loongson.cn>
2022-04-04debug: define ELF relocation for loong64Xiaodong Liu
Contributors to the loong64 port are: Weining Lu <luweining@loongson.cn> Lei Wang <wanglei@loongson.cn> Lingqin Gong <gonglingqin@loongson.cn> Xiaolin Zhao <zhaoxiaolin@loongson.cn> Meidan Li <limeidan@loongson.cn> Xiaojuan Zhai <zhaixiaojuan@loongson.cn> Qiyuan Pu <puqiyuan@loongson.cn> Guoqi Chen <chenguoqi@loongson.cn> This port has been updated to Go 1.15.6: https://github.com/loongson/go For #46229 Change-Id: I0c58305754c20d2a59328adbd82caa527de254ec Reviewed-on: https://go-review.googlesource.com/c/go/+/396735 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Cherry Mui <cherryyz@google.com>
2022-04-01debug/elf: ajdust SectionOverlap test for proper fieldsMeng Zhuo
The current SectionOverlap tests Size (addr) with Offset (file) This CL set this test for overlap of Size + Addr and Offset + FileSize Fixes #51939 Change-Id: Ied4c0b87f61c4d5e52139a8295c371f55abc776f Reviewed-on: https://go-review.googlesource.com/c/go/+/395920 Trust: mzh <mzh@golangcn.org> Trust: Than McIntosh <thanm@google.com> Run-TryBot: mzh <mzh@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-03-31debug/elf: check for negative shoff and phoff fieldsIan Lance Taylor
No test because we could add an infinite number of tests of bogus data. For #47653 Fixes #52035 Change-Id: Iec7e2fe23f2dd1cf14bad2475422f243f51028f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/396880 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com>
2022-03-16cmd/link: default generic ABI compression for ELFMeng Zhuo
This CL change all debug dwarf headers to generic ABI "Compression header" for ELF (http://www.sco.com/developers/gabi/latest/ch4.sheader.html#compression_header) Fixes #50796 Change-Id: I188625e596f11cd120dbd802ac2d79341d5eaf41 Reviewed-on: https://go-review.googlesource.com/c/go/+/380755 Trust: mzh <mzh@golangcn.org> Run-TryBot: mzh <mzh@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-01-14debug/elf: do not read unrelated bytes for SHT_NOBITS sectionsAlessandro Arzilli
SHT_NOBITS sections do not occupy space in the file and their offset is "conceptual", reading their data should return all zeroes instead of reading bytes from the section that follows them. Change-Id: Iaa9634792c1909c3e87dab841dd646cd6dcf9027 Reviewed-on: https://go-review.googlesource.com/c/go/+/375216 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-05cmd/link: enable internal linking of PIE binaries on ppc64lePaul E. Murphy
The amd64/arm64 relocation processing is used as a template and updated for ppc64le. This requires updating the TOC relocation handling code to support linux type TOC relocations too (note, AIX uses TOC-indirect accesses). Noteably, the shared flag of go functions is used as a proxy for the local entry point offset encoded in elf objects. Functions in go ppc64le shared objects always[1] insert 2 instructions to regenerate the TOC pointer. [1] excepting a couple special runtime functions, see preprocess in obj9.go for specific details of this behavior. Change-Id: I3646e6dc8a0a0ffe712771a976983315eae5c418 Reviewed-on: https://go-review.googlesource.com/c/go/+/352829 Run-TryBot: Paul Murphy <murp@ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
2021-09-10debug/elf: retain original error message when getSymbols fails.Florin Papa
The original error is currently discarded, and that makes it difficult to know what failed, in case we want to retry only certain errors. Change-Id: Id7e927ec242464249c4dfa5cda0f264adef3c898 Reviewed-on: https://go-review.googlesource.com/c/go/+/317851 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Than McIntosh <thanm@google.com>
2021-06-14debug/elf: don't apply DWARF relocations for ET_EXEC binariesVictor Michel
Some ET_EXEC binaries might have relocations for non-loadable sections like .debug_info. These relocations must not be applied, because: * They may be incorrect * The correct relocations were already applied at link time Binaries in Linux Kernel debug packages like Fedora/Centos kernel-debuginfo are such examples. Relocations for .debug_* sections are included in the final binaries because they are compiled with --emit-relocs, but the resulting relocations are incorrect and shouldn't be used when reading DWARF sections. Fixes #46673 Change-Id: I2b4214f1584bfc243446d0eaee41512657325b95 GitHub-Last-Rev: 8350fad059e70422d13dfaa5bab7fb8a56c0f76f GitHub-Pull-Request: golang/go#46698 Reviewed-on: https://go-review.googlesource.com/c/go/+/327009 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>