From 00c3cbf4d7b6eb6dc1c18f0886f450b4c8550443 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 20 Jun 2018 20:06:35 -0700 Subject: [PATCH] hello world in C --- cmd/land/process.go | 2 +- cmd/land/process_test.go | 5 +++++ cmd/land/testdata/Tupfile | 3 ++- .../testdata/{helloworld.cbroke => helloworld.c} | 13 +++---------- cmd/land/testdata/land.syms | 6 ++++++ 5 files changed, 17 insertions(+), 12 deletions(-) rename cmd/land/testdata/{helloworld.cbroke => helloworld.c} (59%) create mode 100644 cmd/land/testdata/land.syms diff --git a/cmd/land/process.go b/cmd/land/process.go index c4e1662..58c8903 100644 --- a/cmd/land/process.go +++ b/cmd/land/process.go @@ -229,7 +229,7 @@ func (p *Process) open(fnamesP int32, flags int32) int32 { case "stdout": fi = stdFD{ ReadWriteCloser: loggerFile{ - Logger: log.New(os.Stdout, p.name, log.LstdFlags), + Logger: log.New(os.Stdout, p.name+" ", log.LstdFlags), }, } diff --git a/cmd/land/process_test.go b/cmd/land/process_test.go index 29d4c18..38ce7d2 100644 --- a/cmd/land/process_test.go +++ b/cmd/land/process_test.go @@ -20,6 +20,7 @@ func testWasmFile(t *testing.T, fname string) *Process { if err != nil { t.Fatal(err) } + p.name = fname ret, err := p.Main() if err != nil { @@ -111,3 +112,7 @@ func TestStruct(t *testing.T) { t.Fatalf("wanted foo.baz to be 255, got: %d", foo.Baz) } } + +func TestCHelloWorld(t *testing.T) { + testWasmFile(t, "./testdata/helloworld.wasm") +} diff --git a/cmd/land/testdata/Tupfile b/cmd/land/testdata/Tupfile index 586fd90..8d45897 100644 --- a/cmd/land/testdata/Tupfile +++ b/cmd/land/testdata/Tupfile @@ -2,7 +2,8 @@ include_rules CFLAGS += --target=wasm32-unknown-unknown-wasm CFLAGS += --sysroot=~/code/wasmception/sysroot/ -CFLAGS += -O0 -nostartfiles -Wl,--no-entry -nostdlib +CFLAGS += -O0 -nostartfiles -nostdlib -fvisibility=hidden +CFLAGS += -Wl,--no-entry,--allow-undefined-file=land.syms : foreach *.wast |> wat2wasm -o %o %f |> %B.wasm : foreach *.c |> ~/code/wasmception/dist/bin/clang $(CFLAGS) %f -o %o |> %B.wasm diff --git a/cmd/land/testdata/helloworld.cbroke b/cmd/land/testdata/helloworld.c similarity index 59% rename from cmd/land/testdata/helloworld.cbroke rename to cmd/land/testdata/helloworld.c index b08f327..5aea803 100644 --- a/cmd/land/testdata/helloworld.cbroke +++ b/cmd/land/testdata/helloworld.c @@ -4,18 +4,11 @@ extern int close(int); __attribute__ ((visibility ("default"))) int main() { - const char *name = "hello"; + const char *name = "stdout"; char *msg = "Hello, world!"; int fd = open(name, 0x42); - int num = write(fd, msg, 13); - if (num == 0) { - return 1; - } - - num = close(fd); - if (num == 0) { - return 1; - } + write(fd, msg, 13); + close(fd); return 0; } diff --git a/cmd/land/testdata/land.syms b/cmd/land/testdata/land.syms new file mode 100644 index 0000000..20e693d --- /dev/null +++ b/cmd/land/testdata/land.syms @@ -0,0 +1,6 @@ +open +read +write +close +unlink +isatty