aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/loadelf/ldelf.go
AgeCommit message (Collapse)Author
2026-03-18cmd/link: support loading R_LARCH_GOT64_PC_{LO12, HI20} relocs on loong64Guoqi Chen
On loong64, such relocations are increasingly common when built using an "extreme" code model. To ensure future interoperability with cgo, the linker needs to be made aware of these relocations. Ref: https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc Fixes #78047. Change-Id: Ibca205ab837279c69fb243a8e8519c952e11c99e Reviewed-on: https://go-review.googlesource.com/c/go/+/753521 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Meidan Li <limeidan@loongson.cn> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2026-02-06cmd/link: ignore GCC generated .wm4/.wm8 symbols with no typeIan Lance Taylor
Fixes #77436 Change-Id: I37d852a89678c929156c4765e774c819eb515e6f Reviewed-on: https://go-review.googlesource.com/c/go/+/742220 Reviewed-by: Michael Knyszek <mknyszek@google.com> 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>
2026-02-06cmd/link: correct error message in loadelf.LoadIan Lance Taylor
The message said we were ignoring the symbols, but we aren't. We are treating them as an error. For #77436 Change-Id: I5492d81717c539b09f6956b591178f1f3a42893d Reviewed-on: https://go-review.googlesource.com/c/go/+/742060 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-20cmd/link: support loading R_LARCH_PCREL20_S2 and R_LARCH_CALL36 relocsWANG Xuerui
Host libgcc.a (among other libraries) on loong64 systems may contain such relocs if built with the "medium" code model and/or linker relaxation, which is increasingly the case. Make the internal linker aware of these for cgo interopability going forward. While at it, fix some of the comments for the loong64-specific RelocTypes. Fixes #75562 Change-Id: I0810969dcd229c5131ef06b0f70f51d81a3be4cd Reviewed-on: https://go-review.googlesource.com/c/go/+/709717 Reviewed-by: abner chenc <chenguoqi@loongson.cn> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Meidan Li <limeidan@loongson.cn> Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-11-11std,cmd: go fix -any std cmdAlan Donovan
This change mechanically replaces all occurrences of interface{} by 'any' (where deemed safe by the 'any' modernizer) throughout std and cmd, minus their vendor trees. Since this fix is relatively numerous, it gets its own CL. Also, 'go generate go/types'. Change-Id: I14a6b52856c3291c1d27935409bca8d5fd4242a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/719702 Commit-Queue: Alan Donovan <adonovan@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Alan Donovan <adonovan@google.com>
2025-10-21all: eliminate unnecessary type conversionsJes Cok
Found by github.com/mdempsky/unconvert Change-Id: I88ce10390a49ba768a4deaa0df9057c93c1164de GitHub-Last-Rev: 3b0f7e8f74f58340637f33287c238765856b2483 GitHub-Pull-Request: golang/go#75974 Reviewed-on: https://go-review.googlesource.com/c/go/+/712940 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
2025-08-21cmd/internal/objabi,cmd/link: add support for additional riscv64 relocationsJoel Sing
These additional relocation types are encountered when using the Go race detector with riscv64. Updates #64345 Change-Id: I6de6430165fb378463da1af9402198a3a31485ca Reviewed-on: https://go-review.googlesource.com/c/go/+/690496 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
2025-05-19cmd/link/internal: add support for internal linking on loong64limeidan
Change-Id: Ic0d36f27481ac707d04aaf7001f26061e510dd8f Reviewed-on: https://go-review.googlesource.com/c/go/+/533716 Reviewed-by: Qiqi Huang <huangqiqi@loongson.cn> Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-12cmd/link: ignore mapping symbols on riscv64Yao Zi
Specified in RISC-V ELF psABI[1], mapping symbols are symbols starting with "$d" or "$x" with STT_NOTYPE, STB_LOCAL and zero sizes, indicating boundaries between code and data in the same section. Let's simply ignore them as they're only markers instead of real symbols. This fixes linking errors like sym#63 ("$d"): ignoring symbol in section 4 (".riscv.attributes") (type 0) when using CGO together with Clang and internal linker, which are caused by unnecessary (but technically correct) mapping symbols created by LLVM for various sections. [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/87aecf601722171c570120a46003be3c17ad3108/riscv-elf.adoc?plain=1#L1448 Fixes #73516 Change-Id: I02ca90c100ba8a38733fe3b8b8403836b44a3dd1 GitHub-Last-Rev: d7842ceafb840c511cf0c36295c353698898d399 GitHub-Pull-Request: golang/go#73592 Reviewed-on: https://go-review.googlesource.com/c/go/+/669675 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-04-30cmd/link: fix cgo on riscv64 when building with gcc-15Mark Ryan
It's not currently possible to build cgo programs that are partially compiled with gcc-15 on riscv64 using the internal linker. There are two reasons for this. 1. When gcc-15 compiles _cgo_export.c, which contains no actual code, for a riscv64 target, it emits a label in the .text section called .Letext0. This label is referred to by another section, .debug_line, and an entry is generated in the symbol table for it. The Go linker panics when processing the .Letext0 symbol in _cgo_export.o, as it occurs in an empty section. 2. GCC-15 is generating additional debug symbols with the .LVUS prefix, e.g., .LVUS33, that need to be ignored. We fix the issue by removing the check in cmd/link/internal/loader/loader.go that panics if we encounter a symbol in an empty section (the comments preceding this check suggest it's safe to remove it) and by adding .LVUS to the list of symbol prefixes to ignore. Fixes #72840 Change-Id: I00658b6bdd01606dde1581b5bc2f42edfc37de82 Reviewed-on: https://go-review.googlesource.com/c/go/+/668276 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Joel Sing <joel@sing.id.au> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
2024-11-07cmd/internal/objabi, cmd/link: introduce SymKind helper methodsRuss Cox
These will be necessary when we start using the new FIPS symbols. Split into a separate CL so that these refactoring changes can be tested separate from any FIPS-specific changes. Passes golang.org/x/tools/cmd/toolstash/buildall. Change-Id: I73e5873fcb677f1f572f0668b4dc6f3951d822bc Reviewed-on: https://go-review.googlesource.com/c/go/+/625996 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Russ Cox <rsc@golang.org>
2024-07-27cmd/link/internal/loadelf: remove useless relocation size information of loong64limeidan
As of CL 455017 we have switched to following the new style relocations on loong64, these stack based relocations should be removed. Change-Id: Ic129a5665cf6f183a32e13b6f1a55d712a99d721 Reviewed-on: https://go-review.googlesource.com/c/go/+/537335 Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: abner chenc <chenguoqi@loongson.cn> Commit-Queue: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Qiqi Huang <huangqiqi@loongson.cn> Reviewed-by: abner chenc <chenguoqi@loongson.cn>
2024-02-16cmd/link: replace function pointers to static calls in loadelfCherry Mui
When transitioning between the old object loader and the new object loader, to support both we made loadelf to take symbol loading functions as function pointers. Now we only have the new object loader. Change the function pointers back to static calls. Change-Id: Ia623a6010376a3d7c0be5eacae002144d956f28a Reviewed-on: https://go-review.googlesource.com/c/go/+/564635 Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
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-09-14cmd/link/internal/loadelf: correct the relocation size of R_LARCH_64limeidan
Change-Id: If3eaca8b92e8f5265c7763d13021a6353b9df9b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/528455 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: abner chenc <chenguoqi@loongson.cn> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.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-08-23cmd/internal/obj/riscv,cmd/link: add support for internal cgo linking on riscv64Joel Sing
Make it possible to internally link cgo on riscv64, which also adds support for SDYNIMPORT calls without external linking being required. This reduces the time of an ./all.bash run on a Sifive Hifive Unleashed by approximately 20% (~140 minutes down to ~110 minutes). Change-Id: I43f1348de31672718ae8676cc82f6fdc1dfee054 Reviewed-on: https://go-review.googlesource.com/c/go/+/431104 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Joel Sing <joel@sing.id.au> Reviewed-by: Than McIntosh <thanm@google.com>
2023-05-31cmd/link: support R_PPC64_REL24_P9NOTOCPaul E. Murphy
This can be treated identically to R_PPC64_REL24_NOTOC as stubs are generated based on GOPPC64 and -buildmode. Change-Id: I3c42a9bf3c08d107fb656e6bf59b2307783bd9af Reviewed-on: https://go-review.googlesource.com/c/go/+/497915 Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Paul Murphy <murp@ibm.com>
2023-04-28cmd/link: load external ELF PPC64 objects which set st_other=1Paul E. Murphy
This indicates the symbol does not use or preserve the TOC pointer in R2. Likewise, it does not have a distinct local entry point. This happens when gcc compiles an object with -mcpu=power10. Recycle the SymLocalentry field of a text symbol to pass through this hint as the bogus value 1 (A valid offset must be a multiple of 4 bytes), and update the usage to check and generate errors further into the linking process. This matches the behavior of st_other as used by ELFv2. Change-Id: Ic89ce17b57f400ab44213b21a3730a98c7cdf842 Reviewed-on: https://go-review.googlesource.com/c/go/+/490295 Run-TryBot: Paul Murphy <murp@ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-26cmd/link/internal/loadelf: set AttrExternal on text section symbolsPaul E. Murphy
PPC64 processes external object relocations against the section symbols. This needs to be set correctly to determine the type of PLT stub to generate when both Go and External code make PLT calls. Change-Id: I5abdd5a0473866164083c33e80324dffcc1707f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/488895 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Paul Murphy <murp@ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-28cmd/link/internal/loadelf: add additional relocations for riscv64Joel Sing
These relocations are produced by clang/llvm. Change-Id: I4820e7ed805d1b7341023b263c167a285ca32cf5 Reviewed-on: https://go-review.googlesource.com/c/go/+/431755 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Joel Sing <joel@sing.id.au> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-27cmd/link: refactor usage of SymLocalentry helper functionsPaul E. Murphy
PPC64 ELFv2 uses the st_other field of a symbol to specify an offset from the global entry point to its local entry point. Similarly, some values (i.e 1) may also require additional linker support which is missing today. For now, generate an error if we encounter unsupported local entry values on PPC64, and update the Localentry values to use bytes, not 32b instruction words. Similarly, ELFv2 1.5 also updates the wording of values 2-6. They now map to a specific number of bytes. Change-Id: Id1b71c3b0fea982bdcfb7eac91d9f93e04ae43f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/431876 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Paul Murphy <murp@ibm.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-09-15cmd/link: support -fno-plt compiled gcc objects on ppc64lePaul E. Murphy
This is the initial trivial implemenation. Further improvements can be made for local calls. A test is added, but the -fno-plt option is ignored by gcc if binutils does not support inline plt relocations, so the test is effectively skipped on such hosts. Fixes #53345 Change-Id: Ibf31c26b1a8551c942b21019df8782c00b7a563e Reviewed-on: https://go-review.googlesource.com/c/go/+/412714 Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Paul Murphy <murp@ibm.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jenny Rakoczy <jenny@golang.org> Auto-Submit: Jenny Rakoczy <jenny@golang.org> Run-TryBot: Jenny Rakoczy <jenny@golang.org>
2022-08-15cmd/link: recognize the new R_LARCH_32_PCREL type on loong64WANG Xuerui
Due to the latest binutils change [1], at least for certain 32-bit relocs in .eh_frame section, this new type of relocation record is emitted, leading to breakage on systems with bleeding-edge toolchain when trying to link with object(s) with such new-style relocs. Simply treating it the same as the existing reloc types seems enough. Fixes #54222 [1]: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=f09482a8747b6fd4c2d59a6a64677d3a3fe1e092 Change-Id: I876d6711d5d4a674bead37e57f9503f1622d1136 Reviewed-on: https://go-review.googlesource.com/c/go/+/420983 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: abner chenc <chenguoqi@loongson.cn> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-05-17cmd/link: support linker for linux/loong64Xiaodong Liu
The basic arch-specific hooks are implemented, which are used for internal and external linker. 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 Updates #46229 Change-Id: I4680eb0635dd0fa3d6ea8348a2488da9c7e33d3b Reviewed-on: https://go-review.googlesource.com/c/go/+/349514 Reviewed-by: Cherry Mui <cherryyz@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-05-06cmd/link: fix handling of visibility hidden symbolsCherry Mui
There is a TODO comment that checking hidden visibility is probably not the right thing to do. I think it is indeed not. Here we are not referencing symbols across DSO boundaries, just within an executable binary. The hidden visibility is for references from another DSO. So it doesn't actually matter. This makes cgo internal linking tests work on ARM64 with newer GCC. It failed and was disabled due to a visibility hidden symbol in libgcc.a that we didn't handle correctly. Specifically, the problem is that we didn't mark visibility hidden symbol references SXREF, which caused the loader to not think it is an unresolved external symbol, which in turn made it not loading an object file from the libgcc.a archive which contains the actual definition. Later stage when we try to resolve the relocation, we couldn't resolve it. Enable the test as it works now. Fixes #39466. Change-Id: I2759e3ae15e7a7a1ab9a820223b688ad894509ed Reviewed-on: https://go-review.googlesource.com/c/go/+/404296 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-11cmd/link/internal/loadelf: better error message for ignored symbolsDmitry Vyukov
Currently it's quite hard to debug these error messages about ignored symbols because there are only some numbers and no symbol name. Add symbol name. Before: 135029: sym#952: ignoring symbol in section 11 (type 0) After: 135029: sym#952 (_ZN11__sanitizer9SpinMutexC5Ev): ignoring symbol in section 11 (type 0) Change-Id: I7fec50b5798068c74827376613be529803838c5a Reviewed-on: https://go-review.googlesource.com/c/go/+/363034 Run-TryBot: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Dmitry Vyukov <dvyukov@google.com>
2021-08-13cmd/link: fix dead reference linkkorzhao
Change-Id: I0f53cc2b845f8a52fece2aaba1445a0ecb9cdc53 Reviewed-on: https://go-review.googlesource.com/c/go/+/341129 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org>
2021-04-13cmd/compile,cmd/link: resolve cgo symbols to the correct Go ABIAustin Clements
Currently, Go functions exported to cgo have some confusion around ABIs that leads to crashes. The cmd/cgo-generated C code references an exported Go wrapper function (which calls the underlying exported user function). The linker resolves this reference to the ABI0 entry-point to that Go wrapper function because all host object references are currently assumed to be to version 0 of a symbol. This gets passed via crosscall2 and winds its way to cgocallbackg1, which puts this ABI0 entry-point into a function value and calls it. Unfortunately, function values always use the ABIInternal calling convention, so calling this ABI0 entry-point goes poorly. Fix this by threading definition ABIs through the cgo export mechanism so the linker can resolve host object references (which have no concept of multiple ABIs) to the correct Go symbol. This involves a few pieces: - The compiler extends the cgo_export_{static,dynamic} directives that get passed on to the linker with symbol definition ABIs. - The linker parses the ABIs in the cgo_export_{static,dynamic} directives to look up the right symbol to apply export attributes to and put in the dynexp list. - For internal linking, the linker's Loader structure tracks the right symbol (in particular the right ABI) to resolve host object references to, and we use this in all of the host object loaders. - For external linking, we mangle only the non-ABIInternal symbols now, so the external linker is able to resolve the correct reference from host objects to Go symbols. Updates #40724. Change-Id: I70a0b1610596768c3f473745fa1a3e630afbf1a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/309341 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2021-03-24cmd/link: separate elf addend size from reloc sizePaul E. Murphy
The size of the field may be smaller than the addend, such is the case with R_PPC64_TOC16_HA/LO and similar relocations. Add an extra return value to ldelf.relSize to account for addend size which may be larger than the relocated field, and fix the related ppc64 relocations. Such relocs can be seen in large PIC blobs such as the ppc64le race detector included with golang. Change-Id: I457186fea5d0ec5572b9bbf79bb7fa21a36cc1b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/303990 Run-TryBot: Paul Murphy <murp@ibm.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
2021-03-16cmd/link: preserve elf phdr flags when loading external objectsPaul E. Murphy
Preserve program header flags when passing them through loadelf.Load. They shouldn't be coerced to 0 on non-ARM platforms which set them such as ppc64le. Change-Id: I022613356f910d812de2fc22eac949960eeb53b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/300950 Reviewed-by: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-05cmd/link: add relocs type for mips64xMeng Zhuo
The race detector of llvm adds four reloc types even with -fPIC elf.R_MIPS_CALL16 elf.R_MIPS_GPREL32 elf.R_MIPS_64 elf.R_MIPS_GOT_DISP Change-Id: If73119dcba14ef74395273eb680f52a0aa853217 Reviewed-on: https://go-review.googlesource.com/c/go/+/270297 Trust: Meng Zhuo <mzh@golangcn.org> Run-TryBot: Meng Zhuo <mzh@golangcn.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-12-11cmd/link/internal/loadelf: support additional ELF relocations on mips64Joel Sing
LLVM on openbsd/mips64 generates R_MIPS_GOT_HI16 and R_MIPS_GOT_LO16 relocations, so teach cmd/link/internal/loadelf about both of these. Updates #43005 Change-Id: Ic45ea8b901d44dcbdbf355411ee434dcd7670a92 Reviewed-on: https://go-review.googlesource.com/c/go/+/275894 Trust: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-11-25cmd/link: add relocation type R_AARCH64_LDST16_ABS_LO12_NC for arm64eric fang
The linker already has R_AARCH64_LDST{8,32,64,128}_ABS_LO12_NC, some cgo tests require R_AARCH64_LDST16_ABS_LO12_NC, this CL adds this relocation type. Fixes #42660 Change-Id: I9a5120cd872f5095c61175cb602427c6ab3225cc Reviewed-on: https://go-review.googlesource.com/c/go/+/271017 Reviewed-by: eric fang <eric.fang@arm.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Run-TryBot: eric fang <eric.fang@arm.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: eric fang <eric.fang@arm.com> Trust: Benny Siegert <bsiegert@gmail.com>
2020-10-29cmd/link: add loadelf support for riscv64Joel Sing
Update #36641 Change-Id: I8618da30d8940a56d6cc86a37a2f54b31ee029e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/263601 Trust: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Zhang <cherryyz@google.com> Run-TryBot: Joel Sing <joel@sing.id.au> TryBot-Result: Go Bot <gobot@golang.org>
2020-07-06[dev.link] cmd/link: better naming for Loader container/subsym methods, part ↵Than McIntosh
1 of 2 Introduce a new loader method "AddInteriorSym" to be used when establishing container/containee symbol relationships for host object sub-symbols and GOT/dynamic sub-symbols. Interior symbols are employed in situations where you have a "container" or "payload" symbol that has content, and then a series of "interior" sub-symbols that point into a portion of the container symbol's content. Each interior symbol will typically have a useful name / size / value, but no content of its own. From a symbol table perspective the container symbol is anonymous, but the interior symbols are added to the output symbol table. Change-Id: I919ed5dbbfe2ef2c9a76214f7ea9b384a1be6297 Reviewed-on: https://go-review.googlesource.com/c/go/+/240508 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-04-27cmd/link: use definition from debug/elf for ldelfMeng Zhuo
Change-Id: I92d0fb3a244d0151fcc4b25a20913ad69a89f198 Reviewed-on: https://go-review.googlesource.com/c/go/+/224977 Run-TryBot: Meng Zhuo <mengzhuo1203@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-04-10[dev.link] cmd/link: use new-style Reloc accessors in loadelfCherry Zhang
Change-Id: I9c283aa2631dc21c0567a0708b26cdf95a6dc9fb Reviewed-on: https://go-review.googlesource.com/c/go/+/227897 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-03-25[dev.link] cmd/link: convert doxcoff to new styleCherry Zhang
Change-Id: Ic1e4ed6c14e049b1ba2f7c00f986433ab7ebe932 Reviewed-on: https://go-review.googlesource.com/c/go/+/225202 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-02-18[dev.link] cmd/link: use RO memory (when avail) in elf loaderJeremy Faller
Recreation of CL 206139 in the new symbol hierarchy. Change-Id: Ic20c5c1b5db8f7eadf4c6ee4638e3c1a4e10ef3a Reviewed-on: https://go-review.googlesource.com/c/go/+/219317 Run-TryBot: Jeremy Faller <jeremy@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-02-13[dev.link] cmd/link: remove the second result of MakeSymbolUpdaterCherry Zhang
With unique global indices, MakeSymbolUpdater will not change the symbol's index. So no need to return a new index. Change-Id: I5b4fd6a0167cc74476880bbf4382c524ecde7721 Reviewed-on: https://go-review.googlesource.com/c/go/+/219227 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-01-31[dev.link] all: merge branch 'master' into dev.linkCherry Zhang
It has been a while we have not done this. Merge conflict resolution: - deleted/rewritten code modified on master - CL 214286, ported in CL 217317 (cmd/internal/obj/objfile.go) - CL 210678, it already includes a fix to new code (cmd/link/internal/ld/deadcode.go) - CL 209317, applied in this CL (cmd/link/internal/loadelf/ldelf.go) Change-Id: Ie927ea6a1d69ce49e8d03e56148cb2725e377876
2020-01-09[dev.link] cmd/link: convert ELF host object loading to new loaderThan McIntosh
This is a rewrite of the ELF host object loader to use just the Loader interfaces for symbol creation, without constructing sym.Symbols. At the moment this is gated under the temporary linker command line option "-newldelf". This version is able to get through all.bash on linux/amd64. Change-Id: I99f41368f75b0df9e35ef3c2cf2a702b732540c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/210779 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-12-12[dev.link] cmd/link: remove sym.Symbols from loaderJeremy Faller
Pushing the wavefront forward requires a single source of truth for symbols. This CL removes sym.Symbols from the loader for host object loaders, allowing us to have the single source of truth for symbols be the loader, not some strange combination of sym.Symbols and the loader. Change-Id: Ib8ff0117ebe6040fade346047535ff342d781081 Reviewed-on: https://go-review.googlesource.com/c/go/+/209217 Run-TryBot: Jeremy Faller <jeremy@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-12-09cmd/link: fix loadelf failed on MIPS familyMeng Zhuo
The relocation of MIPS64 family ELF is different with other architecure according to the document from Linux-MIPS https://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf In "2.9 Relocation" it shows relocation section contains five parts: 1. r_sym Elf64_Word Symbol index 2. r_ssym Elf64_Byte Special symbol 3. r_type3 Elf64_Byte Relocation type 4. r_type2 Elf64_Byte Relocation type 5. r_type Elf64_Byte Relocation type This CL makes loadelf aware the difference. Update #35779 Change-Id: Ib221665641972b1c2bfea5a496e3118e5dc0bc45 Reviewed-on: https://go-review.googlesource.com/c/go/+/209317 Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-12-03[dev.link] all: merge branch 'master' into dev.linkCherry Zhang
Bring in Than's fix of #35779. The only merge conflict is cmd/link/internal/loadelf/ldelf.go, with a modification-deletion conflict. Change-Id: Id2fcfd2094a31120966a6ea9c462b4ec76646b10
2019-11-23cmd/link: fix bug with -newobj and "ld -r" ELF host objectsThan McIntosh
When the ELF host object loader encounters a static/hidden symbol, it creates a sym.Symbol for it but does not enter it into the sym.Symbols lookup table. Under -newobj mode, this was not happening correctly; we were adding the sym via loader.LookupOrCreate, which resulted in collisions when it encountered symbols with the same name + version + section (this can happen for "ld -r" objects). Fixes #35779. Change-Id: I36d40fc1efc03fc1cd8ae6b76cb6a0d2a957389c Reviewed-on: https://go-review.googlesource.com/c/go/+/208479 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-11-11[dev.link] cmd/link: remove old objs from host obj loadersJeremy Faller
Change-Id: I9ee853e37090ea015aba817d9aeb2f4cc9ff5a1b Reviewed-on: https://go-review.googlesource.com/c/go/+/206539 Run-TryBot: Jeremy Faller <jeremy@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-11-02[dev.link] cmd/link: set cgo attributes early when internal cgo linkingCherry Zhang
In newobj mode, cgo attributes are typically set later, as we create sym.Symbols later. But when internal cgo linking, the host object loaders still work with sym.Symbols, and the cgo attributes need to be set for them to work properly. Therefore, set them early. This will cause creating some Symbols eagerly, but they are mostly host object symbols and will need to be created anyway. Now all cgo internal linking tests pass on ELF systems. Change-Id: I023a4df4429acc8ebf5e185f62e6809198497a78 Reviewed-on: https://go-review.googlesource.com/c/go/+/204857 Reviewed-by: Than McIntosh <thanm@google.com>
2019-10-31[dev.link] cmd/link: elf host obj support w/ new obj filesJeremy Faller
Add support for elf host objects with new object file format. Change-Id: Ic5be1953359b9b6b78d9a0b715af69763aefd227 Reviewed-on: https://go-review.googlesource.com/c/go/+/201728 Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>