scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 912d4bdc80191728ba6dfb225acd71951acde04f
parent 6ac01512d50b19e600c21d689e4dc5b49c3d2687
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 21 Sep 2018 21:03:05 +0100

[lib/c] Fix NetBSD runtime

NetBSD was setting _environ but it was generating a segfault.

Diffstat:
Mlib/c/target/amd64-sysv-netbsd/Makefile | 2+-
Mlib/c/target/posix/getenv.c | 4++--
Mlib/c/target/posix/objlst.mk | 3+++
Mlib/crt/amd64-sysv-netbsd/crt.s | 4++--
4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/c/target/amd64-sysv-netbsd/Makefile b/lib/c/target/amd64-sysv-netbsd/Makefile @@ -8,7 +8,7 @@ ARCH = amd64 ABI = sysv SYSERRTBL = ../posix/netbsd.e MORECFLAGS = -std=c99 -g -static -nostdinc -SYSOBJ = raise.o signal.o _sigaction.o _sigaction2.o _setcontext.o +SYSOBJ = getenv.o raise.o signal.o _sigaction.o _sigaction2.o _setcontext.o include syscall.mk include ../amd64-sysv/objlst.mk diff --git a/lib/c/target/posix/getenv.c b/lib/c/target/posix/getenv.c @@ -2,7 +2,7 @@ #include <string.h> #undef getenv -extern char **environ; +extern char **_environ; char * getenv(const char *name) @@ -10,7 +10,7 @@ getenv(const char *name) char **p; size_t len = strlen(name); - for (p = environ; *p; ++p) { + for (p = _environ; *p; ++p) { if (!memcmp(name, *p, len) && (*p)[len] == '=') break; } diff --git a/lib/c/target/posix/objlst.mk b/lib/c/target/posix/objlst.mk @@ -4,3 +4,6 @@ raise.o: ../posix/raise.c ../../syscall.h signal.o: ../posix/signal.c ../../syscall.h $(CC) $(SCC_CFLAGS) ../posix/signal.c -c + +getenv.o: ../posix/getenv.c + $(CC) $(SCC_CFLAGS) ../posix/getenv.c -c diff --git a/lib/crt/amd64-sysv-netbsd/crt.s b/lib/crt/amd64-sysv-netbsd/crt.s @@ -9,7 +9,7 @@ .long 200000000 .bss -environ: +_environ: .quad 0 .text @@ -19,7 +19,7 @@ _start: movq %rsp,%rbp andq $-16,%rsp movq 16(%rbp),%rbx - movq %rbx,environ + movq %rbx,_environ call main movl %eax,%edi jmp exit