1
0
mirror of https://github.com/golang/go synced 2024-11-17 05:24:53 -07:00
go/misc/cgo/test
Russ Cox 19470dc535 misc/cgo/test: do not redeclare exported Go functions
An exported Go function like

	//export F
	func F() {}

gets declared in _cgo_export.h as something like

	extern void F(void);

The exact declaration varies by operating system.
In particular, Windows adds __declspec(dllimport).

Clang on Windows/ARM64 rejects code that contains
conflicting declarations for F, like:

	extern void F(void);
	extern void __declspec(dllimport) F(void);

This means that F must not be declared separately from _cgo_export.h:
any code that wants to refer to F must use #include "_cgo_export.h".

Unfortunately, the cgo prologue itself (the commented code before import "C")
cannot include "_cgo_export.h", because that file is itself produced from the
cgo Go sources and therefore cannot be a dependency of the cgo Go sources.

This CL rewrites misc/cgo/test to avoid redeclaring exported functions.
Most of the time, this is not a significant problem: just move the code
that needs the header into a .c file, perhaps with a wrapper exposed
to the cgo Go sources.

The one case that is potentially problematic is f7665, which is part of
the test for golang.org/issue/7665. That bug report explicitly identified
a bug in referring to the C name for an exported function in the same
Go source file as it was exported function. That is now impossible,
at least on Windows/ARM64, so the test is modified a bit and possibly
does not test what the original bug was. But the original bug should
be long gone: that part of the compiler has been rewritten.

Change-Id: I0d14d9336632f0e5e3db4273d9d32ef2cca0298d
Reviewed-on: https://go-review.googlesource.com/c/go/+/312029
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-04-23 21:42:52 +00:00
..
testdata all: use more precise build tags 2021-02-23 19:55:03 +00:00
backdoor.go
buildid_linux.go
callback_c_gc.c
callback_c_gccgo.c
callback_c.c
callback.go runtime: unify asmcgocall and systemstack traceback setup 2021-02-19 00:02:06 +00:00
cgo_linux_test.go syscall: support POSIX semantics for Linux syscalls 2020-10-23 20:53:14 +00:00
cgo_stubs_android_test.go
cgo_test.go reflect: panic on New of go:notinheap type 2021-04-09 23:54:31 +00:00
cgo_thread_lock.go
cgo_unix_test.go
cthread_unix.c
cthread_windows.c
issue1435.go all: update references to symbols moved from io/ioutil to io 2021-04-05 17:51:15 +00:00
issue4029.c cmd/link: support cgo internal/linking on darwin/arm64 2020-10-20 02:25:52 +00:00
issue4029.go cmd/link: support cgo internal/linking on darwin/arm64 2020-10-20 02:25:52 +00:00
issue4029w.go cmd/link: support cgo internal/linking on darwin/arm64 2020-10-20 02:25:52 +00:00
issue4273.c
issue4273b.c
issue4339.c
issue4339.h
issue5548_c.c
issue5740a.c
issue5740b.c
issue6833_c.c
issue6907export_c.c
issue6997_linux.c
issue6997_linux.go all: fix spellings 2021-04-10 01:46:41 +00:00
issue7234_test.go
issue8148.c misc/cgo/test: do not redeclare exported Go functions 2021-04-23 21:42:52 +00:00
issue8148.go misc/cgo/test: do not redeclare exported Go functions 2021-04-23 21:42:52 +00:00
issue8331.h
issue8517_windows.c
issue8517_windows.go
issue8517.go
issue8694.go
issue8811.c
issue18146.go all: add GOOS=ios 2020-09-23 18:12:59 +00:00
issue20910.c
issue21897.go
issue21897b.go
issue31891.c
issue42495.go cmd/cgo: fix initialization of empty argument types 2020-11-13 15:15:15 +00:00
overlaydir_test.go
pkg_test.go all: update references to symbols moved from io/ioutil to io 2021-04-05 17:51:15 +00:00
setgid_linux.go all: simplify the spelling of Linux 2021-04-13 13:56:21 +00:00
sigaltstack.go runtime: use sigaltstack on macOS/ARM64 2020-10-06 21:25:42 +00:00
sigprocmask.c
sigprocmask.go
test_unix.go
test_windows.go
test.go reflect: panic on New of go:notinheap type 2021-04-09 23:54:31 +00:00
testx.c misc/cgo/test: do not redeclare exported Go functions 2021-04-23 21:42:52 +00:00
testx.go misc/cgo/test: do not redeclare exported Go functions 2021-04-23 21:42:52 +00:00