aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld/lib.go
AgeCommit message (Collapse)Author
2026-02-03all: prealloc slice with possible minimum capabilitiesShulhan
2025-12-15cmd/link: set canUsePlugins only on platforms that support pluginCherry Mui
If a program imports the plugin package, but the plugin build mode is not supported on the platform, it still cannot use plugin. Don't treat it like so. Updates #76815. Change-Id: I0fd719427d7c3cc96a94ce1f92d6e4457da92a90 Reviewed-on: https://go-review.googlesource.com/c/go/+/730164 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-26cmd/link: put moduledata in its own .go.module sectionIan Lance Taylor
There is a test for this in CL 721480 later in this series. For #76038 Change-Id: Ib7ed1f0b0aed2d929ca0f135b54d6b62112cae30 Reviewed-on: https://go-review.googlesource.com/c/go/+/720660 TryBot-Bypass: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com>
2025-10-07Revert "cmd/compile: redo arm64 LR/FP save and restore"Keith Randall
This reverts commit 719dfcf8a8478d70360bf3c34c0e920be7b32994. Reason for revert: Causing crashes. Change-Id: I0b8526dd03d82fa074ce4f97f1789eeac702b3eb Reviewed-on: https://go-review.googlesource.com/c/go/+/709755 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-10-06cmd/compile: redo arm64 LR/FP save and restoreKeith Randall
Instead of storing LR (the return address) at 0(SP) and the FP (parent's frame pointer) at -8(SP), store them at framesize-8(SP) and framesize-16(SP), respectively. We push and pop data onto the stack such that we're never accessing anything below SP. The prolog/epilog lengths are unchanged (3 insns for a typical prolog, 2 for a typical epilog). We use 8 bytes more per frame. Typical prologue: STP.W (FP, LR), -16(SP) MOVD SP, FP SUB $C, SP Typical epilogue: ADD $C, SP LDP.P 16(SP), (FP, LR) RET The previous word where we stored LR, at 0(SP), is now unused. We could repurpose that slot for storing a local variable. The new prolog and epilog instructions are recognized by libunwind, so pc-sampling tools like perf should now be accurate. (TODO: except maybe after the first RET instruction? Have to look into that.) Update #73753 (fixes, for arm64) Update #57302 (Quim thinks this will help on that issue) Change-Id: I4800036a9a9a08aaaf35d9f99de79a36cf37ebb8 Reviewed-on: https://go-review.googlesource.com/c/go/+/674615 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
2025-10-03cmd/link: support .def file with MSVC clang toolchainCherry Mui
lld-link supports .def file, but requires a "-def:" (or "/def:") flag. (MinGW linker, on the other hand, requires no flag.) Pass the flag when using MSVC-based toolchain. CL originally authored by Chressie Himpel. Change-Id: I8c327ab48d36b0bcbb1d127cff544ffdb06be38e Reviewed-on: https://go-review.googlesource.com/c/go/+/708716 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Chressie Himpel <chressie@google.com>
2025-09-29cmd/link: use a .def file to mark exported symbols on Windowsqmuntal
Binutils defaults to exporting all symbols when building a Windows DLL. To avoid that we were marking symbols with __declspec(dllexport) in the cgo-generated headers, which instructs ld to export only those symbols. However, that approach makes the headers hard to reuse when importing the resulting DLL into other projects, as imported symbols should be marked with __declspec(dllimport). A better approach is to generate a .def file listing the symbols to export, which gets the same effect without having to modify the headers. Updates #30674 Fixes #56994 Change-Id: I22bd0aa079e2be4ae43b13d893f6b804eaeddabf Reviewed-on: https://go-review.googlesource.com/c/go/+/705776 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-29cmd/link: don't pass -Wl,-S on SolarisCherry Mui
Solaris linker's -S has a different meaning. Fixes #75637. Change-Id: I51e641d5bc6d7f64ab5aa280090c70ec787a1fbf Reviewed-on: https://go-review.googlesource.com/c/go/+/707096 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-09-26cmd/link: don't pass -Wl,-S on AIXCherry Mui
The AIX linker's -S flag has a different meaning. Don't pass it. Updates #75618. Change-Id: I98faabea3435cde255f4c2d25f34dde9f69b7ec9 Reviewed-on: https://go-review.googlesource.com/c/go/+/707097 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-09-25cmd/link: handle -w flag in external linking modeCherry Mui
Currently, when the -w flag is set, it doesn't actually disable the debug info generation with in external linking mode. (It does make the Go object have no debug info, but C objects may still have.) Pass "-Wl,-S" to let the external linker disable debug info generation. Change-Id: I0fce56b9f23a45546b69b9e6dd027c5527b1bc87 Reviewed-on: https://go-review.googlesource.com/c/go/+/705857 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2025-09-15cmd/link: support race mode with MSVC clangCherry Mui
I couldn't make --print-file-name work with -msvc clang. (The library name is synchronization.lib, but even with that name it still doesn't print the full path.) Assume it always synchronization.lib. Change-Id: I22e8f14824f7f7e96b71b913217b1f604f1e2da7 Reviewed-on: https://go-review.googlesource.com/c/go/+/703398 Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Florian Zenker <floriank@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-12cmd/link: support MSVC clangCherry Mui
Currently on Windows, for cgo, we support MinGW-based C toolchain, that is, with a -windows-gnu target. This CL makes it work with clang with a -windows-msvc target. The LLVM toolchain bundled in MSVC (https://learn.microsoft.com/en-us/cpp/build/clang-support-msbuild) is such an example. Currently it is expecting lld-link as the C linker, which is also bundled in MSVC, can be requested with -fuse-ld=lld, but is not the default. This is the first step, which makes it generate a working cgo binary. There are still more work to do, e.g. there are some linker warnings, and the binary doesn't have symbol table. all.bat doesn't pass with this setting. Change-Id: I54d33f7dd5f5eeeafa0735cd52f4127fe4865636 Reviewed-on: https://go-review.googlesource.com/c/go/+/703055 Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Florian Zenker <floriank@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-04-03cmd/link/internal/ld: introduce -funcalign=N optionAleksey Markin
This patch adds linker option -funcalign=N that allows to set alignment for function entries. This CL is based on vasiliy.leonenko@gmail.com's cl/615736. For #72130 Change-Id: I57e5c9c4c71a989533643fda63a9a79c5c897dea Reviewed-on: https://go-review.googlesource.com/c/go/+/660996 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-02-13cmd: use cmd/internal/hash.New32 and Sum32 onlyRuss Cox
Do not use New16, New20, Sum16, Sum20 anymore. As of CL 641096, these are just wrappers around New32 and Sum32. Change call sites to use them directly. Change-Id: Icea91a77449f6839b903894997057ba404bd04e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/641076 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2024-12-03cmd/link/internal/ld: work around FreeBSD 14.1 cmd/cgo test link failureMichael Anthony Knyszek
On FreeBSD 14.1 we fail to link against C code with internal linking. The symptom is apparently undefined symbols, but explicitly pointing the linker at compiler-rt for -libgcc fixes the issue. This looks a lot like the workaround on OpenBSD, but the symptom is different. --print-libgcc-file-name produces libclang_rt.builtins-x86_64.a which appears to be an insufficient subset of libcompiler_rt.a. For #61095. Change-Id: Iff5affbc923d69c89d671a69d8f4ecaadac42177 Cq-Include-Trybots: luci.golang.try:gotip-freebsd-amd64 Reviewed-on: https://go-review.googlesource.com/c/go/+/632975 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-11-18runtime: get rid of gc programs for typesKeith Randall
Instead, have the runtime build the gc bitmaps on demand at runtime. Change-Id: If7a245bc62e4bce3ce80972410b0ed307d921abe Reviewed-on: https://go-review.googlesource.com/c/go/+/616255 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com>
2024-11-18cmd/link: use types (and not GC programs) to build data/bss ptrmaskskhr@golang.org
The linker knows the types of the global variables. We can use those types to build the GC programs that describe the data and bss pointer masks. That way we don't use the GC programs of the constituent types. This is part of an effort to remove GC programs from the runtime. There's a major complication in that when we're linking against a shared library (typically, libstd.so), the relocations we need to break apart arrays and structs into constituent types are difficult to find. Load that additional data when linking against shared libraries. Change-Id: I8516b24a0604479895c7b8a8a358d3cd8d421530 Reviewed-on: https://go-review.googlesource.com/c/go/+/546216 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-11-13cmd/compile, cmd/link: add FIPS verification supportRuss Cox
For FIPS init-time code+data verification, we need to arrange to put the FIPS symbols into contiguous regions of the executable and then record those sections along with the expected checksum. The cmd/internal/obj changes identify the FIPS symbols and give them distinguished types, which the linker then places in contiguous regions. The linker also writes out information to use at run time to find the FIPS sections, along with the expected hash. See cmd/internal/obj/fips.go and cmd/link/internal/ld/fips.go for more details. The code is disabled in this commit. CL 625998 and 625999 adds tests. CL 626000 enables the code. For #69536. Change-Id: I48da6db94bc0bea7428c43d4abcf999527bccfcd Reviewed-on: https://go-review.googlesource.com/c/go/+/625997 Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.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-11-07cmd/link: remove dummy argument from ld.ErrorfRuss Cox
As the comment notes, all calls to Errorf now pass nil, so remove that argument entirely. There is a TODO to remove uses of Errorf entirely, but that seems wrong: sometimes there is no symbol on which to report the error, and in that situation, Errorf is appropriate. So clarify that in the docs. Change-Id: I92b3b6e8e3f61ba8356ace8cd09573d0b55d7869 Reviewed-on: https://go-review.googlesource.com/c/go/+/625617 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-10-24cmd/link: don't pass --build-id if C linker doesn't support itCherry Mui
On Solaris the default (non-GNU) C linker doesn't support the --build-id flag (and I'm not aware of any alternative). So check that the linker supports the flag before passing it. Updates #41004, #63934. Cq-Include-Trybots: luci.golang.try:gotip-solaris-amd64 Change-Id: I4379e5bf6eb495154d663ac4ed802ecb11fcf91c Reviewed-on: https://go-review.googlesource.com/c/go/+/621639 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-23cmd/link: fix flags order in linkerFlagSupportedSiddhartha Bagaria
Flags from CGo directives should be placed before extldflags so that extldflags get more preference. This is also the order followed by the final link command. Fixes #69350 Change-Id: I2cfb22ae4ea7a160cc614440e88ef2eb82ea7399 Reviewed-on: https://go-review.googlesource.com/c/go/+/614275 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Commit-Queue: Ian Lance Taylor <iant@golang.org>
2024-10-21cmd/link: on ELF, generate GNU build ID by defaultCherry Mui
On ELF, default to "-B gobuildid", so it generates GNU build ID based on Go buildid by default. Updates #41004. Fixes #63934. Fixes #68652. Change-Id: I5619dfaa4eeb6575c52922ae1de3430b46e31db6 Reviewed-on: https://go-review.googlesource.com/c/go/+/618601 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Than McIntosh <thanm@golang.org>
2024-10-21cmd/link: apply -B UUID to external linking on Mach-OCherry Mui
Currently, on Mach-O, the -B UUID setting is only applied in internal linking mode, whereas in external linking mode the UUID is always rewritten to a hash of Go build ID. This CL makes it apply to external linking as well. This makes the behavior consistent on both linkmodes, and also consistent with the -B flag's behavior for GNU build ID on ELF. Add tests. Updates #68678. Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64_14,gotip-darwin-arm64_13 Change-Id: I276a5930e231141440cdba16e8812df28ac4237b Reviewed-on: https://go-review.googlesource.com/c/go/+/618599 Reviewed-by: Than McIntosh <thanm@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-09-13cmd/link/internal: use slices.ContainsTobias Klauser
Change-Id: Ib437e272e0eb7d1b0969a4ed94d264ca3aad7c59 Reviewed-on: https://go-review.googlesource.com/c/go/+/612696 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Tim King <taking@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Tim King <taking@google.com>
2024-09-04cmd: use 20 bytes hash when possibleCuong Manh Le
CL 402595 changes all usages of 20 bytes hash to 32 bytes hash by using notsha256. However, since CL 454836, notsha256 is not necessary anymore, so this CL reverts those changes to 20 bytes hash using cmd/internal/hash package. Updates #51940 Updates #64751 Change-Id: Icb08d5a0d8032a3c4d050ff7b2298d31c483b88b Reviewed-on: https://go-review.googlesource.com/c/go/+/610597 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org>
2024-09-04cmd: do not use notsha256Cuong Manh Le
CL 402595 used notsha256 to prevent the compiler from depending on cgo-based implementations of sha1 and sha256. However, since CL 454836, cmd is built with CGO_ENABLED=0, which will disable boringcrypto. Thus all usages of notsha256 is not necessary anymore. Updates #51940 Updates #64751 Change-Id: I503090f7a2efb5723e8a79523b143dc7cdb4edd0 Reviewed-on: https://go-review.googlesource.com/c/go/+/610596 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2024-08-19all: remove duplicated words in commentsOleksandr Redko
Change-Id: Id991ec0826a4e2857f00330b4b7ff2b71907b789 Reviewed-on: https://go-review.googlesource.com/c/go/+/606615 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
2024-07-03cmd/link: don't disable memory profiling when pprof.WriteHeapProfile is usedCherry Mui
We have an optimization that if the memory profile is not consumed anywhere, we set the memory profiling rate to 0 to disable the "background" low-rate profiling. We detect whether the memory profile is used by checking whether the runtime.MemProfile function is reachable at link time. Previously, all APIs that access the memory profile go through runtime.MemProfile. But the code was refactored in CL 572396, and now the legacy entry point WriteHeapProfile uses pprof_memProfileInternal without going through runtime.MemProfile. In fact, even with the recommended runtime/pprof.Profile API (pprof.Lookup or pprof.Profiles), runtime.MemProfile is only (happen to be) reachable through countHeap. Change the linker to check runtime.memProfileInternal instead, which is on all code paths that retrieve the memory profile. Add a test case for WriteHeapProfile, so we cover all entry points. Fixes #68136. Change-Id: I075c8d45c95c81825a1822f032e23107aea4303c Reviewed-on: https://go-review.googlesource.com/c/go/+/596538 Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-26cmd/link: don't skip code sign even if dsymutil didn't generate a fileCherry Mui
Even if dsymutil didn't generate a file (which should not happen with the Apple toolchain with the correct setup), we should not skip next steps, e.g. code sign. A return statement makes it exit too early. Updates #68088. Change-Id: Ic1271ed1b7fe5bdee5a25cc5d669a105173b389e Reviewed-on: https://go-review.googlesource.com/c/go/+/593660 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com>
2024-06-26cmd/link: don't let dsymutil delete our temp directoryCherry Mui
To work around #59026, where dsymutil may not clean up its temp directory at exit, we set DSYMUTIL_REPRODUCER_PATH to our temp directory so it uses that, and we can delete it at the end. In Xcode 16 beta, dsymutil deletes the DSYMUTIL_REPRODUCER_PATH directory even if it is not empty. We still need our tmpdir at the point, so give a subdirectory to dsymutil instead. For #68088. Change-Id: I18759cc39512819bbd0511793ce917eae72245d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/593659 Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-23cmd/link/internal/ld: handle "\r" in MinGW "--print-prog-name" outputDavis Goodin
Fix the "gcc --print-prog-name" output parser to handle "\r\n", not only "\n". The MinGW compiler on Windows uses "\r\n" as line endings, causing the existing parser to create paths like ".../x86_64-w64-mingw32/bin/ar.exe\r", which is not correct. By trimming the "\r\n" cutset, both types of line endings are handled correctly. Fixes #68121 Change-Id: I04b8bf9b6a5b29a1e59a6aa07fa4faa4c5bdeee6 Reviewed-on: https://go-review.googlesource.com/c/go/+/593916 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
2024-06-13cmd/link: use path from "cc --print-prog-name ar" for c-archive buildmodeThan McIntosh
[This is a roll-forward of CL 479775, which had to be rolled back due to bad interactions with the wrappers used by the ios-arm64-corellium builder. ios-arm64-corellium is no longer being maintained AFAICT, meaning that it should be ok to move ahead with this patch again]. When external linking with -buildmode=c-archive, the Go linker eventually invokes the "ar" tool to create the final archive library. Prior to this patch, if the '-extar' flag was not in use, we would just run "ar". This works well in most cases but breaks down if we're doing cross-compilation targeting Windows (macos system "ar" apparently doesn't create the windows symdef section correctly). To fix the problem, capture the output of "cc --print-prog-name ar" and invoke "ar" using the path returned by that command. Fixes #59221. Change-Id: Ie367541b23641266a6f48ac68adf971501bff9fb Reviewed-on: https://go-review.googlesource.com/c/go/+/592375 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-05-21cmd/link/internal/ld: rewrite LC_UUID for darwin external linksThan McIntosh
When building Go binaries using external linking, rewrite the LC_UUID Macho load command to replace the content placed there by the external linker, so as to ensure that we get reproducible builds. Updates #64947. Change-Id: I263a89d1a067807404febbc801d4dade33bc3288 Reviewed-on: https://go-review.googlesource.com/c/go/+/586079 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-05-15cmd/link: disallow pull-only linknamesCherry Mui
As mentioned in CL 584598, linkname is a mechanism that, when abused, can break API integrity and even safety of Go programs. CL 584598 is a first step to restrict the use of linknames, by implementing a blocklist. This CL takes a step further, tightening up the restriction by allowing linkname references ("pull") only when the definition side explicitly opts into it, by having a linkname on the definition (possibly to itself). This way, it is at least clear on the definition side that the symbol, despite being unexported, is accessed outside of the package. Unexported symbols without linkname can now be actually private. This is similar to the symbol visibility rule used by gccgo for years (which defines unexported non-linknamed symbols as C static symbols). As there can be pull-only linknames in the wild that may be broken by this change, we currently only enforce this rule for symbols defined in the standard library. Push linknames are added in the standard library to allow things build. Linkname references to external (non-Go) symbols are still allowed, as their visibility is controlled by the C symbol visibility rules and enforced by the C (static or dynamic) linker. Assembly symbols are treated similar to linknamed symbols. This is controlled by -checklinkname linker flag, currently not enabled by default. A follow-up CL will enable it by default. Change-Id: I07344f5c7a02124dbbef0fbc8fec3b666a4b2b0e Reviewed-on: https://go-review.googlesource.com/c/go/+/585358 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2024-05-14cmd/link/internal/ld: clean tmpdir obj timestampsThan McIntosh
This patch changes the Go linker to "clean" (reset to Unix epoch) the timestamps on object files copied to the tmpdir that is presented to the external linker or archive tool. The intent is to improve build reproducibility on Darwin, where later versions of xcode seem to want to incorporate object file timestamps into the hash used for the final build ID (which precludes the possibility of having reproducible Go builds). Credit for this idea goes to Cherry (see https://github.com/golang/go/issues/64947#issuecomment-1887667189). Updates #64947. Change-Id: I2eb7dddff538e247122b04fdcf8a57c923f61201 Reviewed-on: https://go-review.googlesource.com/c/go/+/585355 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-08cmd/link: close the file opened in the captureHostObj functionguoguangwu
Change-Id: I940c63c3040035e507428798d50060cfd0d04e16 GitHub-Last-Rev: e27484cd43e21599ba6e798ab74a703ad290ae7c GitHub-Pull-Request: golang/go#66706 Reviewed-on: https://go-review.googlesource.com/c/go/+/577055 Reviewed-by: Than McIntosh <thanm@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: Cherry Mui <cherryyz@google.com> Auto-Submit: Than McIntosh <thanm@google.com>
2024-03-16cmd/dist,cmd/link: enable PIE buildmode on openbsd/arm64Joel Sing
The PIE buildmode works correctly on openbsd/arm64, hence enable it. Updates #59866 Change-Id: I2f3c2839893659391539fafa12891d64f867e189 Reviewed-on: https://go-review.googlesource.com/c/go/+/570375 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: Joel Sing <joel@sing.id.au>
2024-03-15cmd/link: support -bindnow option and permit use of "-Wl,-z,now"Than McIntosh
This is a partial roll-forward of CL 473495, which was subsequently reverted. The second half of CL 473495 will appear in a future CL. In this patch we introduce a new Go linker "-bindnow" command line flag, and update the Go command to permit the use of the -Wl,-z,now option, to allow users to produce binaries that have immediate binding. Updates #45681. Change-Id: Idd61b0d6597bcd37b16c343714c55a4ef6dfb534 Reviewed-on: https://go-review.googlesource.com/c/go/+/571416 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-14Revert: "cmd/link: add option to enable full RELRO for ELF"Than McIntosh
This reverts https://go.dev/cl/c/go/+/473495. Reason for revert: breaks some Google-internal tests. This revert will be temporary until we can gather more info on the nature of the failures and hopefully develop an upstream test case, etc. Updates #45681. Change-Id: Ib628ddc53bc5489e4f76c0f4ad809b75e899102c Reviewed-on: https://go-review.googlesource.com/c/go/+/571415 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@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>
2024-02-29cmd/link: add option to enable full RELRO for ELFNick Revin
-bindnow linker option enables full RELRO on ELF targets. This options defaults to false and preserves current behavior - partial relro for buildmode=pie. Also, the following changes were made to align internal linker's behavior with external ELF linkers: - GNU_RELRO segment is marked Read-only - .dynamic is a relro section for partial and full RELRO - .got is a relro section for partial and full RELRO - .got.plt is a relro section for full RELRO only Supersedes #45681 (golang.org/cl/312509) Change-Id: I51c4ef07b14beceb7cd6fd989f323e45f89a63ca GitHub-Last-Rev: bc6826441065395b80a2b66cde67466c4d9bce2e GitHub-Pull-Request: golang/go#58869 Reviewed-on: https://go-review.googlesource.com/c/go/+/473495 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-01-26cmd/link: print failed external command invocationCherry Mui
When the invocation of the external linker, dsymutil or strip command fails, print the command we invoked. For #65292. Change-Id: Icdb5f9ee942ebda4276f6373c3fbbf5222088d0b Reviewed-on: https://go-review.googlesource.com/c/go/+/558856 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2024-01-22cmd/link,runtime: merge minfunc const info internal/abiqiulaidongfeng
For #59670 Change-Id: If2b05b1ba30b607b518577b0e11ba5a0b07999c5 GitHub-Last-Rev: a664aa18b5ef674dc2d05c1f7533e1974d265894 GitHub-Pull-Request: golang/go#64906 Reviewed-on: https://go-review.googlesource.com/c/go/+/553276 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-11-20all: add floating point option for ARM targetsLudi Rehak
This change introduces new options to set the floating point mode on ARM targets. The GOARM version number can optionally be followed by ',hardfloat' or ',softfloat' to select whether to use hardware instructions or software emulation for floating point computations, respectively. For example, GOARM=7,softfloat. Previously, software floating point support was limited to GOARM=5. With these options, software floating point is now extended to all ARM versions, including GOARM=6 and 7. This change also extends hardware floating point to GOARM=5. GOARM=5 defaults to softfloat and GOARM=6 and 7 default to hardfloat. For #61588 Change-Id: I23dc86fbd0733b262004a2ed001e1032cf371e94 Reviewed-on: https://go-review.googlesource.com/c/go/+/514907 Run-TryBot: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
2023-11-09cmd/internal/link: merge .pdata and .xdata sections from host object filesqmuntal
The Go linker doesn't currently merge .pdata/.xdata sections from the host object files generated by the C compiler when using internal linking. This means that the stack can't be unwind in C -> Go. This CL fixes that and adds a test to ensure that the stack can be unwind in C -> Go and Go -> C transitions, which was not well tested. Updates #57302 Change-Id: Ie86a5e6e30b80978277e66ccc2c48550e51263c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/534555 Reviewed-by: Heschi Kreinick <heschi@google.com> 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>
2023-08-18cmd/link: don't mangle string symbol namesCherry Mui
String symbol names could contain weird characters as we put the string literal into the symbol name. So it may appear to need mangling. However, as string symbols are grouped into a single "go:string.*" symbol, the individual symbol names actually don't matter. So don't mangle them. Also make the mangling code more defensive in case of weird symbol names. Fixes #62098. Change-Id: I533012567a9fffab69debda934f426421c7abb04 Reviewed-on: https://go-review.googlesource.com/c/go/+/520856 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-16cmd/link: suppress -bind_at_load deprecation warning for ld-primeCherry Mui
ld-prime emits a deprecation warning for -bind_at_load. The flag is needed for plugins to not deadlock (#38824) when linking with older darwin linker. It is supposedly not needed with newer linker when chained fixups are used. For now, we always pass it, and suppress the warning. For #61229. Change-Id: I4b8a6f864a460c40dc38adbb533f664f7fd5343c Reviewed-on: https://go-review.googlesource.com/c/go/+/508696 Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com>
2023-07-21cmd/link: print dsymutil and strip commands in -v modeCherry Mui
If -v is specified, print dsymutil and strip commands. Change-Id: Icaff2b41ab582d8c58a4ec65438c2986d88def9f Reviewed-on: https://go-review.googlesource.com/c/go/+/506758 Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com>
2023-07-21cmd/link: rationalize -s and -w flags with Mach-O external linkingCherry Mui
Currently, on Mach-O in external linking mode, the handling of -s and -w flags are a bit mixed: neither flag disables the symbol table, and both flags disable DWARF. This CL makes it do what is documented: -s disables symbol table, and -w disables DWARF. For the Darwin system linker, the -s flag (strip symbol table) is obsolete. So we strip it afterwards. We already use the strip command to strip the debug STAB symbols if we need to combine DWARF. With this CL we'll use an additional flag to strip more symbols. And we now also use strip if -s is specified and we don't need to combine DWARF. Change-Id: I9bed24fd388f2bd5b0ffa4ec2db46a4a2f6b1016 Reviewed-on: https://go-review.googlesource.com/c/go/+/493136 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>