From 2da0341b4d6828479c5dc75a233b47732f53cf6c Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Thu, 16 Aug 2018 18:12:37 +0200 Subject: [PATCH] Genode fixes (#8501) * Genode fixes - wrap strings in "Genode::Cstring" when logging - define SIGABRT for Genode - disable GCC -fstack-protector - use log RPC for fatal messages - add --os:genode build to appveyor - define paramStr and paramCount * Select fixups for Genode POSIX --- appveyor.yml | 1 + compiler/ccgexprs.nim | 5 +++-- config/nim.cfg | 17 +++++++++++------ lib/nimbase.h | 4 ++-- lib/pure/ioselects/ioselectors_select.nim | 6 ++++-- lib/pure/os.nim | 10 ++++++++-- lib/system.nim | 9 +++++++-- lib/system/ansi_c.nim | 2 +- lib/system/excpt.nim | 6 +++++- 9 files changed, 42 insertions(+), 18 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5aa3798b16..cb4ac9e00b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -55,6 +55,7 @@ build_script: - nimble install jester@#head -y - nimble install niminst - nim c --taintMode:on -d:nimCoroutines tests/testament/tester + - nim c --taintMode:on -d:nimCoroutines --os:genode -d:posix --compileOnly tests/testament/tester test_script: - tests\testament\tester --pedantic all -d:nimCoroutines diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index dd1c72ab63..9ec034f677 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -982,7 +982,7 @@ proc genEcho(p: BProc, n: PNode) = # is threadsafe. internalAssert p.config, n.kind == nkBracket if p.config.target.targetOS == osGenode: - # bypass libc and print directly to the Genode LOG session + # echo directly to the Genode LOG session var args: Rope = nil var a: TLoc for it in n.sons: @@ -990,8 +990,9 @@ proc genEcho(p: BProc, n: PNode) = add(args, ", \"\"") else: initLocExpr(p, it, a) - add(args, ropecg(p.module, ", #nimToCStringConv($1)", [rdLoc(a)])) + add(args, ropecg(p.module, ", Genode::Cstring($1->data, $1->len)", [rdLoc(a)])) p.module.includeHeader("") + p.module.includeHeader("") linefmt(p, cpsStmts, """Genode::log(""$1);$n""", args) else: if n.len == 0: diff --git a/config/nim.cfg b/config/nim.cfg index af9df9c555..9626a31971 100644 --- a/config/nim.cfg +++ b/config/nim.cfg @@ -255,9 +255,14 @@ vcc.cpp.options.size = "/O1" tcc.options.always = "-w" # Configuration for the Genode toolchain -amd64.genode.gcc.cpp.exe = "genode-x86-g++" -amd64.genode.gcc.exe = "genode-x86-gcc" -amd64.genode.gcc.path = "/usr/local/genode-gcc/bin" -arm.genode.gcc.cpp.exe = "genode-arm-g++" -arm.genode.gcc.exe = "genode-arm-gcc" -arm.genode.gcc.path = "/usr/local/genode-gcc/bin" +@if genode: + gcc.path = "/usr/local/genode-gcc/bin" + gcc.cpp.options.always = "-D__GENODE__ -fno-stack-protector" + @if i386 or amd64: + gcc.exe = "genode-x86-gcc" + gcc.cpp.exe = "genode-x86-g++" + @elif arm: + gcc.exe = "genode-arm-gcc" + gcc.cpp.exe = "genode-arm-g++" + @end +@end diff --git a/lib/nimbase.h b/lib/nimbase.h index 6dc7429103..84972fcb0e 100644 --- a/lib/nimbase.h +++ b/lib/nimbase.h @@ -129,13 +129,13 @@ __clang__ defined __DMC__ || \ defined __BORLANDC__ ) # define NIM_THREADVAR __declspec(thread) +#elif defined(__TINYC__) || defined(__GENODE__) +# define NIM_THREADVAR /* note that ICC (linux) and Clang are covered by __GNUC__ */ #elif defined __GNUC__ || \ defined __SUNPRO_C || \ defined __xlC__ # define NIM_THREADVAR __thread -#elif defined __TINYC__ -# define NIM_THREADVAR #else # error "Cannot define NIM_THREADVAR" #endif diff --git a/lib/pure/ioselects/ioselectors_select.nim b/lib/pure/ioselects/ioselectors_select.nim index cd6a72b446..521b31a640 100644 --- a/lib/pure/ioselects/ioselectors_select.nim +++ b/lib/pure/ioselects/ioselectors_select.nim @@ -310,7 +310,10 @@ proc selectInto*[T](s: Selector[T], timeout: int, var rset, wset, eset: FdSet if timeout != -1: - tv.tv_sec = timeout.int32 div 1_000 + when defined(genode): + tv.tv_sec = Time(timeout div 1_000) + else: + tv.tv_sec = timeout.int32 div 1_000 tv.tv_usec = (timeout.int32 %% 1_000) * 1_000 else: ptv = nil @@ -391,7 +394,6 @@ proc contains*[T](s: Selector[T], fd: SocketHandle|int): bool {.inline.} = for i in 0..