shithub: scc

Download patch

ref: 0ca62af5f0df449dd940cbd5b7e5723f739df8a0
parent: 4606d3ce5f3e8afbd0ba8d4d9971bf981838df16
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Sep 21 17:03:05 EDT 2018

[lib/c] Fix NetBSD runtime

NetBSD was setting _environ but it was generating a segfault.

--- a/lib/c/target/amd64-sysv-netbsd/Makefile
+++ b/lib/c/target/amd64-sysv-netbsd/Makefile
@@ -8,7 +8,7 @@
 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
--- 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 @@
 	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;
 	}
--- a/lib/c/target/posix/objlst.mk
+++ b/lib/c/target/posix/objlst.mk
@@ -4,3 +4,6 @@
 
 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
--- 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 @@
 	movq	%rsp,%rbp
 	andq	$-16,%rsp
 	movq	16(%rbp),%rbx
-	movq	%rbx,environ
+	movq	%rbx,_environ
 	call	main
 	movl    %eax,%edi
 	jmp	exit