aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/cgo/out.go
AgeCommit message (Collapse)Author
2026-02-04cmd/cgo: use objdir consistently, create it as neededIan Lance Taylor
Previously we added a slash to the end of objdir only after processing input files. The effect was that the temporary gcc output files were placed in /tmp, using objdir as a prefix. Those output files were not removed by anything. Now we consistently use objdir as a directory, not a prefix. We only create it when needed; there is already a test for that in cmd/go/testdata/script/build_cwd_newline.txt. Change-Id: Ie66d9c04ecc3c0f5950fc1111c74e1d01c67304c Reviewed-on: https://go-review.googlesource.com/c/go/+/740742 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-12-16cmd/cgo: don't emit C local if it is not usedIan Lance Taylor
Fixes #76861 Change-Id: Icc8452e48ed736e8240f8afea18637c33b8e3ef8 Reviewed-on: https://go-review.googlesource.com/c/go/+/730600 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Joe Richey <joerichey@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2025-11-24runtime/cgo: add support for `any` param and return typeAlexandre Daubois
When using `any` as param or return type of an exported function, we currently have the error `unrecognized Go type any`. `any` is an alias of `interface{}` which is already supported. This would avoid such change: https://github.com/php/frankenphp/pull/1976 Fixes #76340 Change-Id: I301838ff72e99ae78b035a8eff2405f6a145ed1a GitHub-Last-Rev: 7dfbccfa582bbc6e79ed29677391b9ae81a9b5bd GitHub-Pull-Request: golang/go#76325 Reviewed-on: https://go-review.googlesource.com/c/go/+/720960 Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-21cmd/cgo: strip top-level const qualifier from argument frame structIan Lance Taylor
Otherwise we can't assign to it. Fixes #75751 Change-Id: Iba680db672297bca1a1d1a33912b80863da66a08 Reviewed-on: https://go-review.googlesource.com/c/go/+/717342 Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.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-11-05cmd/cgo: skip escape checks if call site has no argumentAriel Otilibili
This CL improves on CL 579955. When the call site has no argument, 1 package main 2 3 /* 4 #include <stdio.h> 5 void foo() {printf("Hello from C\n");} 6 */ 7 import "C" 8 9 func main() { 10 C.foo() 11 } Escape checks are not needed, $ go tool cgo -objdir dir cgonoargs.go $ cat -n dir/_cgo_gotypes.go | sed -n '43,$p' 43 func _Cfunc_foo() (r1 _Ctype_void) { 44 _cgo_runtime_cgocall(_cgo_c8ba2f813f11_Cfunc_foo, uintptr(unsafe.Pointer(&r1))) 45 if _Cgo_always_false { 46 } 47 return 48 } Skip escape checks if call site has no argument. $ cat -n dir/_cgo_gotypes.go | sed -n '43,$p' 43 func _Cfunc_foo() (r1 _Ctype_void) { 44 _cgo_runtime_cgocall(_cgo_c8ba2f813f11_Cfunc_foo, uintptr(unsafe.Pointer(&r1))) 45 return 46 } For #75856 Change-Id: I9aac0b6fb2985f6833976099e7eead1f28971bee GitHub-Last-Rev: 1aacde448c922903980420cf8a38a4827d76ad28 GitHub-Pull-Request: golang/go#76186 Reviewed-on: https://go-review.googlesource.com/c/go/+/718060 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org>
2025-11-03cmd/cgo: use the export'ed file/line in error messagesAriel Otilibili
When an unpinned Go pointer (or a pointer to an unpinned Go pointer) is returned from Go to C, 1 package main 2 3 import ( 4 "C" 5 ) 6 7 //export foo 8 func foo(CLine *C.char) string { 9 return C.GoString(CLine) 10 } 11 12 13 func main() { 14 } The error message mentions the file/line of the cgo wrapper, panic: runtime error: cgo result is unpinned Go pointer or points to unpinned Go pointer goroutine 17 [running, locked to thread]: panic({0x798f2341a4c0?, 0xc000112000?}) /usr/lib/go/src/runtime/panic.go:802 +0x168 runtime.cgoCheckArg(0x798f23417e20, 0xc000066e50, 0x0?, 0x0, {0x798f233f5a62, 0x42}) /usr/lib/go/src/runtime/cgocall.go:679 +0x35b runtime.cgoCheckResult({0x798f23417e20, 0xc000066e50}) /usr/lib/go/src/runtime/cgocall.go:795 +0x4b _cgoexp_3c910ddb72c4_foo(0x7ffc9fa9bfa0) _cgo_gotypes.go:65 +0x5d runtime.cgocallbackg1(0x798f233ec780, 0x7ffc9fa9bfa0, 0x0) /usr/lib/go/src/runtime/cgocall.go:446 +0x289 runtime.cgocallbackg(0x798f233ec780, 0x7ffc9fa9bfa0, 0x0) /usr/lib/go/src/runtime/cgocall.go:350 +0x132 runtime.cgocallbackg(0x798f233ec780, 0x7ffc9fa9bfa0, 0x0) <autogenerated>:1 +0x2b runtime.cgocallback(0x0, 0x0, 0x0) /usr/lib/go/src/runtime/asm_amd64.s:1082 +0xcd runtime.goexit({}) /usr/lib/go/src/runtime/asm_amd64.s:1693 +0x1 The cgo wrapper (_cgoexp_3c910ddb72c4_foo) is located in a temporary build artifact (_cgo_gotypes.go) $ go tool cgo -objdir objdir parse.go $ cat -n objdir/_cgo_gotypes.go | sed -n '55,70p' 55 //go:cgo_export_dynamic foo 56 //go:linkname _cgoexp_d48770e267d1_foo _cgoexp_d48770e267d1_foo 57 //go:cgo_export_static _cgoexp_d48770e267d1_foo 58 func _cgoexp_d48770e267d1_foo(a *struct { 59 p0 *_Ctype_char 60 r0 string 61 }) { 62 a.r0 = foo(a.p0) 63 _cgoCheckResult(a.r0) 64 } The file/line of the export'ed function is expected in the error message. Use it in error messages. panic: runtime error: cgo result is unpinned Go pointer or points to unpinned Go pointer goroutine 17 [running, locked to thread]: panic({0x7df72b1d8ae0?, 0x3ec8a1790030?}) /mnt/go/src/runtime/panic.go:877 +0x16f runtime.cgoCheckArg(0x7df72b1d62c0, 0x3ec8a16eee50, 0x68?, 0x0, {0x7df72b1ad44c, 0x42}) /mnt/go/src/runtime/cgocall.go:679 +0x35b runtime.cgoCheckResult({0x7df72b1d62c0, 0x3ec8a16eee50}) /mnt/go/src/runtime/cgocall.go:795 +0x4b _cgoexp_3c910ddb72c4_foo(0x7ffca1b21020) /mnt/tmp/parse.go:8 +0x5d runtime.cgocallbackg1(0x7df72b1a4360, 0x7ffca1b21020, 0x0) /mnt/go/src/runtime/cgocall.go:446 +0x289 runtime.cgocallbackg(0x7df72b1a4360, 0x7ffca1b21020, 0x0) /mnt/go/src/runtime/cgocall.go:350 +0x132 runtime.cgocallbackg(0x7df72b1a4360, 0x7ffca1b21020, 0x0) <autogenerated>:1 +0x2b runtime.cgocallback(0x0, 0x0, 0x0) /mnt/go/src/runtime/asm_amd64.s:1101 +0xcd runtime.goexit({}) /mnt/go/src/runtime/asm_amd64.s:1712 +0x1 So doing, fix typos in comments. Link: https://web.archive.org/web/20251008114504/https://dave.cheney.net/2018/01/08/gos-hidden-pragmas Suggested-by: Keith Randall <khr@golang.org> For #75856 Change-Id: I0bf36d5c8c5c0c7df13b00818bc4641009058979 GitHub-Last-Rev: e65839cfb2e28a879beac67c5c550de871b00018 GitHub-Pull-Request: golang/go#76118 Reviewed-on: https://go-review.googlesource.com/c/go/+/716441 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-03cmd/cgo: fix unaligned arguments typedmemmove crash on iOSTim Cooijmans
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments this is fixed. Fixes #46893 Change-Id: I7beb9fdc31053fcb71bee6c6cb906dea31718c56 GitHub-Last-Rev: 46ae8b96889644aab60ea4284cf447a740354c6a GitHub-Pull-Request: golang/go#74868 Reviewed-on: https://go-review.googlesource.com/c/go/+/692935 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
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-07-24cmd/cgo: compare malloc return value to NULL instead of literal 0Tobias Klauser
Follow the pattern used in the other _cgoPREFIX_Cfunc* functions. This also avoids a -Wzero-as-null-pointer-constant warning when compiling with g++. Change-Id: I95ac8842df048105f4c738f3603136d9cfa2dfdc Reviewed-on: https://go-review.googlesource.com/c/go/+/664916 Auto-Submit: Keith Randall <khr@golang.org> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> 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> Reviewed-by: Keith Randall <khr@golang.org>
2025-04-16all: use strings.ReplaceAll where applicableMarcel Meyer
``` find . \ -not -path './.git/*' \ -not -path './test/*' \ -not -path './src/cmd/vendor/*' \ -not -wholename './src/strings/example_test.go' \ -type f \ -exec \ sed -i -E 's/strings\.Replace\((.+), -1\)/strings\.ReplaceAll\(\1\)/g' {} \; ``` Change-Id: I59e2e91b3654c41a32f17dd91ec56f250198f0d6 GitHub-Last-Rev: 0868b1eccc945ca62a5ed0e56a4054994d4bd659 GitHub-Pull-Request: golang/go#73370 Reviewed-on: https://go-review.googlesource.com/c/go/+/665395 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Robert Griesemer <gri@google.com>
2025-02-28cmd/cgo: update generated headers for compatibility with latest MSVC C++ ↵KangJi
standards Updates #71921 Change-Id: Idfbb72e259b169121c8ced6d89ee2f13d6254d0d GitHub-Last-Rev: fcf12e5a221621f749841055df1d2c2ada3bf844 GitHub-Pull-Request: golang/go#72004 Reviewed-on: https://go-review.googlesource.com/c/go/+/653141 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-18cmd/cgo: explicitly use void for functions with no parametersMauri de Souza Meneguzzo
Currently, exported Go functions with no parameters generate C functions with an empty parameter list. In C, a function with an empty parameter list can accept any number of arguments, whereas a function with a single void parameter explicitly declares that it takes no arguments. To align the generated C functions with their Go prototypes, update the code generation to explicitly include a void parameter for functions with no parameters. Fixes #68411 Change-Id: Iab9456aa0236200bf21d1181a2e18e82869df63f GitHub-Last-Rev: 6ff21a98dfef81df649c76221d9c0858dc0e35e1 GitHub-Pull-Request: golang/go#70981 Reviewed-on: https://go-review.googlesource.com/c/go/+/638635 Reviewed-by: Michael Knyszek <mknyszek@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>
2025-02-06cmd/cgo: use strings.Builder to build long stringsIan Lance Taylor
Change-Id: I33ba7c8a7b731647cdff3ffe7c4274f76f8923ee Reviewed-on: https://go-review.googlesource.com/c/go/+/638736 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
2025-02-03cmd/cgo: declare _GoString{Len,Ptr} in _cgo_export.hIan Lance Taylor
Fixes #71226 Change-Id: I91c46a4310a9c7a9fcd1e3a131ca16e46949edb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/642235 Auto-Submit: Ian Lance Taylor <iant@golang.org> 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@google.com>
2025-02-03cmd/cgo: add C declaration parameter unused attributeIan Lance Taylor
Fixes #71225 Change-Id: I3e60fdf632f2aa0e63b24225f13e4ace49906925 Reviewed-on: https://go-review.googlesource.com/c/go/+/642196 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-12-11cmd/cgo: use full prototype for main in C codeIan Lance Taylor
Avoids pedantic errors from modern C compilers. Fixes #70769 Change-Id: Ibe0d9960e998eb0346b97d7bd69eb7de0d0e6c60 Reviewed-on: https://go-review.googlesource.com/c/go/+/635095 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: 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>
2024-10-04cmd/cgo: avoid endless recursion on recursive typeIan Lance Taylor
Fixes #69176 Change-Id: I2e3b2a7cf7699697b957fc69ecf5200ebb137bc3 Reviewed-on: https://go-review.googlesource.com/c/go/+/609975 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-09-26cmd/cgo: add missing args for fatalfJes Cok
Change-Id: I56b40a9d2ff85fdbc0d170aec686f1868176e068 GitHub-Last-Rev: 9424faf0f8e1fa7c63ae3195f255e7f112444871 GitHub-Pull-Request: golang/go#69578 Reviewed-on: https://go-review.googlesource.com/c/go/+/614556 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Zxilly Chou <zxilly@outlook.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2024-08-16cmd/cgo: enable #cgo noescape/nocallbackdoujiang24
In Go 1.22 we added code to the go/build package to ignore #cgo noescape and nocallback directives. That permits us to enable these directives in Go 1.24. Also, this fixed a Bug in CL 497837: After retiring _Cgo_use for parameters, the compiler will treat the parameters, start from the second, as non-alive. Then, they will be marked as scalar in stackmap, which means the pointer won't be copied correctly in copystack. Fixes #56378. Fixes #63739. Change-Id: I46e773240f8a467c3c4ba201dc5b4ee473cf6e3e GitHub-Last-Rev: 42fcc506d6a7681ef24ac36a5904b57bda4b15cd GitHub-Pull-Request: golang/go#66879 Reviewed-on: https://go-review.googlesource.com/c/go/+/579955 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-07-29cmd,log,net,runtime: simplify string prefix and suffix processingapocelipes
Use the TrimPrefix, TrimSuffix and CutPrefix to simplify the code. Change-Id: I3e2b271ec0d3f9ce664b830e2b0c21ab47337ed0 GitHub-Last-Rev: 4bd1577d2496173800d609da75b08f6de177aba9 GitHub-Pull-Request: golang/go#68629 Reviewed-on: https://go-review.googlesource.com/c/go/+/601675 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-03-29cmd/cgo: close the file opened in the dynimport functionguoguangwu
Change-Id: Ic457e994b50a0e8c1769311937eede1e710a1293 GitHub-Last-Rev: a8af7b5e6710687273203235c19d5402d7f28832 GitHub-Pull-Request: golang/go#66549 Reviewed-on: https://go-review.googlesource.com/c/go/+/574537 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-18cmd/cgo: silence unaligned-accessEgon Elbre
Clang 14+ introduced a warning when using mixed packed and unpacked structs. This can cause problems when taking an address of the unpacked struct, which may end up having a different alignment than expected. This is not a problem in cgo, which does not take pointers from the packed struct. Updated version of https://go.dev/cl/526915, which includes "-Wunknown-warning-option" for compilers that do not have the specific flag. Fixes #62480 Change-Id: I788c6604d0ed5267949f4367f148fa26d2116f51 Reviewed-on: https://go-review.googlesource.com/c/go/+/528935 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2023-09-08Revert "cmd/cgo: silence unaligned-access"Than McIntosh
This reverts commit http://go.dev/cl/c/go/+/526915 Reason for revert: darwin builders unhappy with '-Wunaligned-access' C compiler flag Change-Id: I5e6ca7c9a0ca08b7e758b7f603da70a2fca79b58 Reviewed-on: https://go-review.googlesource.com/c/go/+/526978 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-08cmd/cgo: silence unaligned-accessEgon Elbre
Clang 14+ introduced a warning when using mixed packed and unpacked structs. This can cause problems when taking an address of the unpacked struct, which may end up having a different alignment than expected. This is not a problem in cgo, which does not take pointers from the packed struct. Fixes #62480 Change-Id: If5879eea5e1b77bc6dc7430f68f8c916bff9b090 Reviewed-on: https://go-review.googlesource.com/c/go/+/526915 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-08-30cmd/cgo: only write _cgo_flags for gccgoIan Lance Taylor
We only use it for gccgo. Also only write out LDFLAGS, as that is all that cmd/go uses. Fixes #60642 Change-Id: I6ccc419a17a433583d9868dd63aa7ec41c2b22c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/524556 Auto-Submit: 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: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-08-25cmd/cgo: add #cgo noescape/nocallback annotationsdoujiang24
When passing pointers of Go objects from Go to C, the cgo command generate _Cgo_use(pN) for the unsafe.Pointer type arguments, so that the Go compiler will escape these object to heap. Since the C function may callback to Go, then the Go stack might grow/shrink, that means the pointers that the C function have will be invalid. After adding the #cgo noescape annotation for a C function, the cgo command won't generate _Cgo_use(pN), and the Go compiler won't force the object escape to heap. After adding the #cgo nocallback annotation for a C function, which means the C function won't callback to Go, if it do callback to Go, the Go process will crash. Fixes #56378 Change-Id: Ifdca070584e0d349c7b12276270e50089e481f7a GitHub-Last-Rev: f1a17b08b0590eca2670e404bbfedad5461df72f GitHub-Pull-Request: golang/go#60399 Reviewed-on: https://go-review.googlesource.com/c/go/+/497837 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-06-07cmd/cgo: error out if the source path used in line directives would contain ↵Bryan C. Mills
a newline cmd/cgo uses '//line' directives to map generated source files back to the original source file and line nmubers. The line directives have no way to escape newline characters, so cmd/cgo must not be used if the line directives would contain such characters. Updates #60167. Change-Id: I8581cea74d6c08f82e86ed87127e81252e1bf78c Reviewed-on: https://go-review.googlesource.com/c/go/+/501576 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-06-06cmd/go,cmd/cgo: in _cgo_flags use one line per flagIan Lance Taylor
The flags that we recorded in _cgo_flags did not use any quoting, so a flag containing embedded spaces was mishandled. Change the _cgo_flags format to put each flag on a separate line. That is a simple format that does not require any quoting. As far as I can tell only cmd/go uses _cgo_flags, and it is only used for gccgo. If this patch doesn't cause any trouble, then in the next release we can change to only using _cgo_flags for gccgo. Thanks to Juho Nurminen of Mattermost for reporting this issue. Fixes #60306 Fixes CVE-2023-29405 Change-Id: I81fb5337db8a22e1f4daca22ceff4b79b96d0b4f Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1875094 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Roland Shoemaker <bracewell@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/501224 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-29cmd/go, cmd/cgo: support older versions of gccgo that lack cgo.IncompleteIan Lance Taylor
Test whether gccgo/GoLLVM supports cgo.Incomplete. If it doesn't, use a local definition rather than importing it. Roll back 426496, which skipped a gccgo test, as it now works. For #46731 Fixes #54761 Change-Id: I8bb2ad84c317094495405e178bf5c9694f82af56 Reviewed-on: https://go-review.googlesource.com/c/go/+/446260 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-29cmd/cgo: use strings.TrimSuffixcuiweixie
Change-Id: I97b5592c678c350fd77069d7c40a98864733707a Reviewed-on: https://go-review.googlesource.com/c/go/+/435946 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-09-29cmd/cgo: use strings.Contains instead of strings.Indexcuiweixie
Change-Id: Iaa623dae50ccae36ad44af25899c6453b6108046 Reviewed-on: https://go-review.googlesource.com/c/go/+/435944 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-09-27all: replace [0-9] with \d in regexpsTomCao New Macbook Pro
1. replace [0-9] with \d in regexps 2. replace [a-zA-Z0-9_] with \w in regexps Change-Id: I9e260538252a0c1071e76aeb1c5f885c6843a431 GitHub-Last-Rev: 286e1a4619c4bdda7f461afbd6d30b9f312c0486 GitHub-Pull-Request: golang/go#54874 Reviewed-on: https://go-review.googlesource.com/c/go/+/428435 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-09-08cmd/cgo: use strings.Buildercuiweixie
Change-Id: I427776e5b2d9c7279932548c86c8faded0eed041 Reviewed-on: https://go-review.googlesource.com/c/go/+/428285 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: xie cui <523516579@qq.com>
2022-08-28cmd/cgo: add and use runtime/cgo.Incomplete instead of //go:notinheapCuong Manh Le
Updates #46731 Change-Id: Ia83f27c177cc2f57e240cb5c6708d4552423f5be Reviewed-on: https://go-review.googlesource.com/c/go/+/421879 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-07-20cmd/cgo: allow cgo to pass strings or []bytes bigger than 1<<30Keith Randall
There's no real reason to limit to 1<<30 bytes. Maybe it would catch some mistakes, but probably ones that would quickly manifest in other ways. We can't use the fancy new unsafe.Slice function because this code may still be generated for people with 1.16 or earlier in their go.mod file. Use unsafe shenanigans instead. Fixes #53965 Fixes #53958 Change-Id: Ibfa095192f50276091d6c2532e8ccd7832b57ca8 Reviewed-on: https://go-review.googlesource.com/c/go/+/418557 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-17all: fix spellingJohn Bampton
Change-Id: Iee18987c495d1d4bde9da888d454eea8079d3ebc GitHub-Last-Rev: ff5e01599ddf7deb3ab6ce190ba92eb02ae2cb15 GitHub-Pull-Request: golang/go#52949 Reviewed-on: https://go-review.googlesource.com/c/go/+/406915 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-02all: use os/exec instead of internal/execabsRuss Cox
We added internal/execabs back in January 2021 in order to fix a security problem caused by os/exec's handling of the current directory. Now that os/exec has that code, internal/execabs is superfluous and can be deleted. This commit rewrites all the imports back to os/exec and deletes internal/execabs. For #43724. Change-Id: Ib9736baf978be2afd42a1225e2ab3fd5d33d19df Reviewed-on: https://go-review.googlesource.com/c/go/+/381375 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-04-08cmd/go: cgo export header to be compatible with MSVC complex typesqmuntal
After CL 379474 has landed, the only remaining cgo export header incompatibility with MSVC is the use of the _Complex macro, which is not supported in MSVC even when it is part of the ISO C99 standard (1). Since MSVC 2015 (2), complex math are supported via _Fcomplex and _Dcomplex, which are equivalent to float _Complex and double _Complex. As MSVC and C complex types have the same memory layout, we should be able to typedef GoComplex64 and GoComplex128 to the appropriate type in MSVC. It is important to note that this CL is not adding MSVC support to cgo. C compilers should still be GCC-compatible. This CL is about allowing to include, without further modifications, a DLL export header generated by cgo, normally using Mingw-W64 compiler, into a MSVC project. This was already possible if the export header changes introduced in this CL were done outside cgo, either manually or in a post-build script. Fixes #36233 1: https://docs.microsoft.com/en-us/cpp/c-runtime-library/complex-math-support 2: https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?c-standard-library-features-1 Change-Id: Iad8f26984b115c728e3b73f3a8334ade7a11cfa1 Reviewed-on: https://go-review.googlesource.com/c/go/+/397134 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> Auto-Submit: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-31cmd/cgo: use size_t instead of __SIZE_TYPE__qmuntal
__SIZE_TYPE__ is a GCC type which has been superseded by size_t -define in stddef.h- since ISO C99. cmd/cgo already uses size_t in many places, but still generates several files using __SIZE_TYPES__, most notably the _cgo_export.h. This change replaces all __SIZE_TYPES__ occurrences with size_t. Updates #36233 Change-Id: Id8a99b5d7763caab9333eab9b585e78249a37415 Reviewed-on: https://go-review.googlesource.com/c/go/+/379474 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2022-03-31cmd/go: add comments to C.* special functionsqmuntal
Adding comments to these functions help IDE tooling to display meaningful documentation, p.e. on hover. Tested with gopls and vscode. Updates #51134 Change-Id: Ie956f7cf192af0e828def4a141783f3a2589f77d Reviewed-on: https://go-review.googlesource.com/c/go/+/386414 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
2021-09-22cmd/cgo: add go:notinheap annotation to Windows handle typesElias Naur
Fixes #42018 Change-Id: I6a40f3effe860e67a45fca2e8ab86f3e9887ffee Reviewed-on: https://go-review.googlesource.com/c/go/+/350070 Trust: Elias Naur <mail@eliasnaur.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org>
2021-09-16cmd/cgo: add missing tab in exports for a result of voidLeonard Wang
Change-Id: I45575afbad364c13b7179ebe3f3dfc4ed9671d2b Reviewed-on: https://go-review.googlesource.com/c/go/+/336891 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: Meng Zhuo <mzh@golangcn.org>
2021-09-09cmd/cgo, runtime/cgo: avoid GCC/clang conversion warningsIan Lance Taylor
Add explicit conversions to avoid warnings from -Wsign-conversion and -Wshorten-64-to-32. Also avoid runtime errors from -fsanitize=undefined. Fixes #48121 Change-Id: I29dc8d976884fc42826392c10f1e1759bb1a3989 Reviewed-on: https://go-review.googlesource.com/c/go/+/348739 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-08-16cmd/cgo: fix unused parameter warnings in generated _cgo_main.cHans
Applying -Werror compiler option to request warnings is an usual way to discover potential errors. Go user may put a cgo directive in preamble: `// #cgo CFLAGS: -Werror=unused-parameter`. However, the directive also takes effect on the cgo generated files. I cleaned _cgo_main.c to help Go user only concentrate on warnings of their own file. Fixes #43639 Change-Id: I9112f02ae5226f2fc87a8650d19faee59cddd588 GitHub-Last-Rev: f09d172f979acfba855be8108e7d79ec2778c406 GitHub-Pull-Request: golang/go#46358 Reviewed-on: https://go-review.googlesource.com/c/go/+/322232 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Bryan C. Mills <bcmills@google.com>
2021-06-01cmd/link, cmd/cgo: support -flto in CFLAGSIan Lance Taylor
The linker now accepts unrecognized object files in external linking mode. These objects will simply be passed to the external linker. This permits using -flto which can generate pure byte code objects, whose symbol table the linker does not know how to read. The cgo tool now passes -fno-lto when generating objects whose symbols it needs to read. The cgo tool now emits matching types in different objects, so that the lto linker does not report a mismatch. This is based on https://golang.org/cl/293290 by Derek Parker. For #43505 Fixes #43830 Fixes #46295 Change-Id: I6787de213417466784ddef5af8899e453b4ae1ad Reviewed-on: https://go-review.googlesource.com/c/go/+/322614 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
2021-04-13cmd/cgo: document generated cgo directivesAustin Clements
This took me a while to figure out. Save the next person some trouble. Change-Id: Ifab2d426f67c21b08ef225c79125805a9008e578 Reviewed-on: https://go-review.googlesource.com/c/go/+/309336 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2021-04-12cmd/cgo: throw if C.malloc returns NULL in C.CString or C.CBytesTobias Klauser
Change-Id: Iea07b7f3e64f5938cfb1cd1c07bdce4adf8e4470 Reviewed-on: https://go-review.googlesource.com/c/go/+/308992 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-04-12cmd/cgo: use tabs to indent _cgoPREFIX_Cfunc__CMalloc function bodyTobias Klauser
All other _cgoPREFIX_Cfunc_* functions are indented using tabs. Change-Id: Ic5cfccd3000d34d0bbe08d035f18640af5e05473 Reviewed-on: https://go-review.googlesource.com/c/go/+/308993 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-01-21all: introduce and use internal/execabsRoland Shoemaker
Introduces a wrapper around os/exec, internal/execabs, for use in all commands. This wrapper prevents exec.LookPath and exec.Command from running executables in the current directory. All imports of os/exec in non-test files in cmd/ are replaced with imports of internal/execabs. This issue was reported by RyotaK. Fixes CVE-2021-3115 Fixes #43783 Change-Id: I0423451a6e27ec1e1d6f3fe929ab1ef69145c08f Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/955304 Reviewed-by: Russ Cox <rsc@google.com> Reviewed-by: Katie Hockman <katiehockman@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/284783 Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org>