aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2020-01-15 15:59:51 +0100
committerRon Evans <[email protected]>2020-03-22 17:14:59 +0100
commitf316ebc23b025e497931cfe420ec143f1a217b57 (patch)
tree62099034937787559599a42a6adbd820417df7b3 /testdata
parent9ec426e25e6738be6e09e0239445d1ca558cbf57 (diff)
downloadtinygo-f316ebc23b025e497931cfe420ec143f1a217b57.tar.gz
tinygo-f316ebc23b025e497931cfe420ec143f1a217b57.zip
all: include picolibc for bare metal targets
This is necessary for better CGo support on bare metal. Existing libraries expect to be able to include parts of libc and expect to be able to link to those symbols. Because with this all targets have a working libc, it is now possible to add tests to check that a libc in fact works basically. Not all parts of picolibc are included, such as the math or stdio parts. These should be added later, when needed. This commit also avoids the need for the custom memcpy/memset/memcmp symbols that are sometimes emitted by LLVM. The C library will take care of that.
Diffstat (limited to 'testdata')
-rw-r--r--testdata/cgo/main.go7
-rw-r--r--testdata/cgo/out.txt1
2 files changed, 8 insertions, 0 deletions
diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go
index 41bc6892c..557dea5cf 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 73cb2b990..fcb688467 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