Conversation
93a6b62 to
a316bf1
Compare
|
Note: there are no tests yet, because otherwise bare-metal CGo tests would break. I intend to add tests when a bare metal libc has been added. |
|
This PR can be tested with the following patch: diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go
index 41bc6892..557dea5c 100644
--- a/testdata/cgo/main.go
+++ b/testdata/cgo/main.go
@@ -4,6 +4,7 @@ package main
int fortytwo(void);
#include "main.h"
int mul(int, int);
+#include <string.h>
*/
import "C"
@@ -109,6 +110,12 @@ func main() {
var _ C.option3_t = C.option3A
println("option 2A:", C.option2A)
println("option 3A:", C.option3A)
+
+ // libc: test whether C functions work at all.
+ buf1 := []byte("foobar\x00")
+ buf2 := make([]byte, len(buf1))
+ C.strcpy((*C.char)(unsafe.Pointer(&buf2[0])), (*C.char)(unsafe.Pointer(&buf1[0])))
+ println("copied string:", string(buf2[:C.strlen((*C.char)(unsafe.Pointer(&buf2[0])))]))
}
func printUnion(union C.joined_t) C.joined_t {
diff --git a/testdata/cgo/out.txt b/testdata/cgo/out.txt
index 73cb2b99..fcb68846 100644
--- a/testdata/cgo/out.txt
+++ b/testdata/cgo/out.txt
@@ -55,3 +55,4 @@ option F: 11
option G: 12
option 2A: 20
option 3A: 21
+copied string: foobar |
This allows CGo code to call some libc functions. Additionally, by putting memset/memmove/memcpy in an archive they're not included anymore when not necessary, reducing code size for small programs.
|
Look good to me. Basically since it does not cause anything else to fail, it is a step forward that we need. Now merging. |
|
Hmm spoke too soon. Azure build did not succeed. Rerunning just to be sure... |
|
WebAssembly/wasi-libc#46 might be helpful? |
|
Actually i am thinking it might be the |
|
I suspect the self-test at the end somehow included system headers instead of the ones from wasi. |
|
If we want to skip those tests at the end, we can run |
|
Interesting: Especially the |
This allows CGo code to call some libc functions.
Fixes part of #844.