go/misc
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
..
android all: update references to symbols moved from io/ioutil to io 2021-04-05 17:51:15 +00:00
arm all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
cgo misc/cgo/test: do not redeclare exported Go functions 2021-04-23 21:42:52 +00:00
chrome/gophertool docs: fix case of GitHub 2021-03-05 02:35:21 +00:00
ios all: update references to symbols moved from io/ioutil to io 2021-04-05 17:51:15 +00:00
linkcheck all: update references to symbols moved from io/ioutil to io 2021-04-05 17:51:15 +00:00
reboot all: update references to symbols moved from io/ioutil to io 2021-04-05 17:51:15 +00:00
swig cmd/go: fix swig support and run swig tests during run.bash 2017-11-16 17:19:19 +00:00
trace all: use HTML5 br tags 2021-03-13 03:38:42 +00:00
wasm misc/wasm: check type of argument to Go.run 2020-11-02 13:02:40 +00:00
editors all: don't refer to code.google.com/p/go{,-wiki}/ 2015-02-06 14:41:47 +00:00
go.mod misc: add go.mod file 2019-02-27 17:47:31 +00:00