scc-patches

scc patches
Log | Files | Refs | README

commit 5ba7b286bae6ad27e001827073758ec5ad5542f9
Author: zerous Naveen Narayanan <zerous@nocebo.space>
Date:   Sat,  2 Nov 2019 08:28:32 +0100

Initial commit

Diffstat:
A0001-include-Add-setjmp.h-for-i386.patch | 20++++++++++++++++++++
A0002-lib-c-Update-Linux-write-syscall-for-i386.patch | 46++++++++++++++++++++++++++++++++++++++++++++++
A0003-lib-c-Update-setjmp.s.patch | 45+++++++++++++++++++++++++++++++++++++++++++++
A0004-lib-c-Update-longjmp.s.patch | 47+++++++++++++++++++++++++++++++++++++++++++++++
A0005-lib-c-Add-umoddi3.s-for-i386-linux.patch | 44++++++++++++++++++++++++++++++++++++++++++++
A0006-lib-c-Add-udivdi3.s-for-i386-linux.patch | 43+++++++++++++++++++++++++++++++++++++++++++
A0007-lib-c-Add-_cerrno.s-for-i386-linux.patch | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A0008-lib-c-Update-gensys.sh-for-i386-linux.patch | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A0009-Set-up-toolchain-and-scripts-for-i386.patch | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A0010-lib-c-Update-crt-posix.s-for-i386-linux.patch | 40++++++++++++++++++++++++++++++++++++++++
A0011-tests-Temp-fix.patch | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 files changed, 646 insertions(+), 0 deletions(-)

diff --git a/0001-include-Add-setjmp.h-for-i386.patch b/0001-include-Add-setjmp.h-for-i386.patch @@ -0,0 +1,20 @@ +From e2ffaf8138b59ac4943d38383af79e88b1a752be Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Thu, 31 Oct 2019 09:05:03 +0100 +Subject: [PATCH 01/11] [include] Add setjmp.h for i386 + +--- + include/bits/i386/arch/setjmp.h | 1 + + 1 file changed, 1 insertion(+) + create mode 100644 include/bits/i386/arch/setjmp.h + +diff --git a/include/bits/i386/arch/setjmp.h b/include/bits/i386/arch/setjmp.h +new file mode 100644 +index 00000000..a1f485a9 +--- /dev/null ++++ b/include/bits/i386/arch/setjmp.h +@@ -0,0 +1 @@ ++typedef unsigned long long jmp_buf[8]; +-- +2.23.0 + diff --git a/0002-lib-c-Update-Linux-write-syscall-for-i386.patch b/0002-lib-c-Update-Linux-write-syscall-for-i386.patch @@ -0,0 +1,46 @@ +From be8d9439485a8d774bd9b5cafc7a81ff482e163e Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Thu, 31 Oct 2019 13:59:21 +0100 +Subject: [PATCH 02/11] [lib/c] Update Linux write syscall for i386 + +Pass args using appropriate registers for _write syscall +Remove _write from syscall.lst as it doesn't conform to the generic template +--- + src/libc/arch/i386/linux/_write.s | 13 +++++++++++++ + src/libc/arch/i386/linux/syscall.lst | 1 - + 2 files changed, 13 insertions(+), 1 deletion(-) + create mode 100644 src/libc/arch/i386/linux/_write.s + +diff --git a/src/libc/arch/i386/linux/_write.s b/src/libc/arch/i386/linux/_write.s +new file mode 100644 +index 00000000..2c30050f +--- /dev/null ++++ b/src/libc/arch/i386/linux/_write.s +@@ -0,0 +1,13 @@ ++ .file "_write.s" ++ ++ .globl _write ++_write: ++ pushl %ebp ++ movl %esp,%ebp ++ movl 8(%ebp),%ebx ++ movl 12(%ebp),%ecx ++ movl 16(%ebp),%edx ++ movl $4,%eax ++ int $0x80 ++ popl %ebp ++ jmp _cerrno +diff --git a/src/libc/arch/i386/linux/syscall.lst b/src/libc/arch/i386/linux/syscall.lst +index 71a811f4..743bf682 100644 +--- a/src/libc/arch/i386/linux/syscall.lst ++++ b/src/libc/arch/i386/linux/syscall.lst +@@ -1,6 +1,5 @@ + #number name + 3 _read +-4 _write + 5 _open + 6 _close + 19 _lseek +-- +2.23.0 + diff --git a/0003-lib-c-Update-setjmp.s.patch b/0003-lib-c-Update-setjmp.s.patch @@ -0,0 +1,45 @@ +From 8b41ce621d3a4b5215001046846c1c4562264d4c Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Fri, 1 Nov 2019 15:21:34 +0100 +Subject: [PATCH 03/11] [lib/c] Update setjmp.s + +--- + src/libc/arch/i386/setjmp.s | 23 ++++++++++++----------- + 1 file changed, 12 insertions(+), 11 deletions(-) + +diff --git a/src/libc/arch/i386/setjmp.s b/src/libc/arch/i386/setjmp.s +index 008f2fa9..39397d1d 100644 +--- a/src/libc/arch/i386/setjmp.s ++++ b/src/libc/arch/i386/setjmp.s +@@ -1,16 +1,17 @@ + .file "setjmp.s" + + .text +- .globl _setjmp ++ .globl setjmp,_setjmp + _setjmp: +- mov 4(%esp),%eax +- mov %ebx,(%eax) +- mov %esi,4(%eax) +- mov %edi,8(%eax) +- mov %ebp,12(%eax) +- lea 4(%esp),%ecx +- mov %ecx,16(%eax) +- mov (%esp),%ecx +- mov %ecx,20(%eax) +- xor %eax,%eax ++setjmp: ++ movl 4(%esp),%eax ++ movl %ebx,(%eax) ++ movl %ecx,4(%eax) ++ movl %esi,8(%eax) ++ movl %edi,12(%eax) ++ movl %ebp,16(%eax) ++ movl %esp,20(%eax) ++ pushl (%esp) ++ popl 24(%eax) ++ xor %eax,%eax + ret +-- +2.23.0 + diff --git a/0004-lib-c-Update-longjmp.s.patch b/0004-lib-c-Update-longjmp.s.patch @@ -0,0 +1,47 @@ +From f0fcc2a26a3c47ee265622d96426bb730cd13be9 Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Fri, 1 Nov 2019 15:21:47 +0100 +Subject: [PATCH 04/11] [lib/c] Update longjmp.s + +--- + src/libc/arch/i386/longjmp.s | 20 +++++++++++--------- + 1 file changed, 11 insertions(+), 9 deletions(-) + +diff --git a/src/libc/arch/i386/longjmp.s b/src/libc/arch/i386/longjmp.s +index 7dd062c5..77c7f412 100644 +--- a/src/libc/arch/i386/longjmp.s ++++ b/src/libc/arch/i386/longjmp.s +@@ -1,19 +1,21 @@ + .file "longjmp.s" + + .text +- .globl _longjmp ++ .globl longjmp,_longjmp + _longjmp: ++longjmp: + mov 4(%esp),%edx + mov 8(%esp),%eax + test %eax,%eax + jnz 1f + inc %eax + 1: +- mov (%edx),%ebx +- mov 4(%edx),%esi +- mov 8(%edx),%edi +- mov 12(%edx),%ebp +- mov 16(%edx),%ecx +- mov %ecx,%esp +- mov 20(%edx),%ecx +- jmp *%ecx ++ movl (%edx),%ebx ++ movl 4(%edx),%ecx ++ movl 8(%edx),%esi ++ movl 12(%edx),%edi ++ movl 16(%edx),%ebp ++ movl 20(%edx),%esp ++ pushl 24(%edx) ++ popl %edx ++ jmp *%edx +-- +2.23.0 + diff --git a/0005-lib-c-Add-umoddi3.s-for-i386-linux.patch b/0005-lib-c-Add-umoddi3.s-for-i386-linux.patch @@ -0,0 +1,44 @@ +From 53056612a51c8f52173ad8578216f895a5ce54bd Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Fri, 1 Nov 2019 15:23:20 +0100 +Subject: [PATCH 05/11] [lib/c] Add umoddi3.s for i386/linux + +--- + src/libc/arch/i386/linux/umoddi3.s | 25 +++++++++++++++++++++++++ + 1 file changed, 25 insertions(+) + create mode 100644 src/libc/arch/i386/linux/umoddi3.s + +diff --git a/src/libc/arch/i386/linux/umoddi3.s b/src/libc/arch/i386/linux/umoddi3.s +new file mode 100644 +index 00000000..404a4f30 +--- /dev/null ++++ b/src/libc/arch/i386/linux/umoddi3.s +@@ -0,0 +1,25 @@ ++ .file "umoddi3.s" ++ .section .rodata ++errmsg: ++ .string "floating point exception\n" ++ .equ msgsz,.-errmsg-1 ++ ++ .text ++ .globl __umoddi3 ++ .type __umoddi3,@function ++__umoddi3: ++ pushl %ebp ++ movl %esp,%ebp ++ addl $-16,%esp ++ ++ movl 8(%ebp),%ecx ++ movl %ecx,-16(%ebp) ++ movl 16(%ebp),%ecx ++ movl %ecx,-8(%ebp) ++ movl -16(%ebp),%eax ++ xor %edx,%edx ++ divl -8(%ebp) ++ movl %edx,%eax ++ movl %ebp,%esp ++ popl %ebp ++ ret +-- +2.23.0 + diff --git a/0006-lib-c-Add-udivdi3.s-for-i386-linux.patch b/0006-lib-c-Add-udivdi3.s-for-i386-linux.patch @@ -0,0 +1,43 @@ +From 63b5ac1215f43bb29a74490bc1765aed3fa48439 Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Fri, 1 Nov 2019 15:23:58 +0100 +Subject: [PATCH 06/11] [lib/c] Add udivdi3.s for i386/linux + +--- + src/libc/arch/i386/linux/udivdi3.s | 24 ++++++++++++++++++++++++ + 1 file changed, 24 insertions(+) + create mode 100644 src/libc/arch/i386/linux/udivdi3.s + +diff --git a/src/libc/arch/i386/linux/udivdi3.s b/src/libc/arch/i386/linux/udivdi3.s +new file mode 100644 +index 00000000..588d7124 +--- /dev/null ++++ b/src/libc/arch/i386/linux/udivdi3.s +@@ -0,0 +1,24 @@ ++ .file "umoddi3.s" ++ .section .rodata ++errmsg: ++ .string "floating point exception\n" ++ .equ msgsz,.-errmsg-1 ++ ++ .text ++ .globl __udivdi3 ++ .type __udivdi3,@function ++__udivdi3: ++ pushl %ebp ++ movl %esp,%ebp ++ addl $-16,%esp ++ ++ movl 8(%ebp),%ecx ++ movl %ecx,-16(%ebp) ++ movl 16(%ebp),%ecx ++ movl %ecx,-8(%ebp) ++ movl -16(%ebp),%eax ++ xor %edx,%edx ++ divl -8(%ebp) ++ movl %ebp,%esp ++ popl %ebp ++ ret +-- +2.23.0 + diff --git a/0007-lib-c-Add-_cerrno.s-for-i386-linux.patch b/0007-lib-c-Add-_cerrno.s-for-i386-linux.patch @@ -0,0 +1,92 @@ +From 3458863cfb5aa290cda1b143323fdc2650160212 Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Fri, 1 Nov 2019 15:24:43 +0100 +Subject: [PATCH 07/11] [lib/c] Add _cerrno.s for i386/linux + +Update Makefile +Remove unused strings from umoddi3.s and udivdi3.s +--- + src/libc/arch/i386/linux/Makefile | 7 +++++++ + src/libc/arch/i386/linux/_cerrno.s | 13 +++++++++++++ + src/libc/arch/i386/linux/udivdi3.s | 8 ++------ + src/libc/arch/i386/linux/umoddi3.s | 4 ---- + 4 files changed, 22 insertions(+), 10 deletions(-) + create mode 100644 src/libc/arch/i386/linux/_cerrno.s + +diff --git a/src/libc/arch/i386/linux/Makefile b/src/libc/arch/i386/linux/Makefile +index 03ab52ec..3c8e18d0 100644 +--- a/src/libc/arch/i386/linux/Makefile ++++ b/src/libc/arch/i386/linux/Makefile +@@ -15,7 +15,12 @@ OBJS =\ + _getpid.o\ + _Exit.o\ + _kill.o\ ++ _getheap.o\ + crt.o\ ++ _cerrno.o\ ++ umoddi3.o\ ++ udivdi3.o\ ++ raise.o\ + + all: syscall + $(MAKE) objs +@@ -24,6 +29,8 @@ objs: $(OBJS) + + crt.o: ../crt-posix.s + ++_getheap.o: ../../posix/_getheap.c ++ + syscall: syscall.lst + gensys.sh syscall.lst + touch syscall +diff --git a/src/libc/arch/i386/linux/_cerrno.s b/src/libc/arch/i386/linux/_cerrno.s +new file mode 100644 +index 00000000..51c61b71 +--- /dev/null ++++ b/src/libc/arch/i386/linux/_cerrno.s +@@ -0,0 +1,13 @@ ++ .file "_cerrno.s" ++ .globl _cerrno ++ ++_cerrno: ++ cmpl $0,%eax ++ js 1f ++ ret ++ ++1: neg %eax ++ mov %eax,(errno) ++ mov $-1,%eax ++ ret ++ +diff --git a/src/libc/arch/i386/linux/udivdi3.s b/src/libc/arch/i386/linux/udivdi3.s +index 588d7124..45a0f289 100644 +--- a/src/libc/arch/i386/linux/udivdi3.s ++++ b/src/libc/arch/i386/linux/udivdi3.s +@@ -1,9 +1,5 @@ +- .file "umoddi3.s" +- .section .rodata +-errmsg: +- .string "floating point exception\n" +- .equ msgsz,.-errmsg-1 +- ++ .file "umoddi3.s" ++ + .text + .globl __udivdi3 + .type __udivdi3,@function +diff --git a/src/libc/arch/i386/linux/umoddi3.s b/src/libc/arch/i386/linux/umoddi3.s +index 404a4f30..dc39c665 100644 +--- a/src/libc/arch/i386/linux/umoddi3.s ++++ b/src/libc/arch/i386/linux/umoddi3.s +@@ -1,8 +1,4 @@ + .file "umoddi3.s" +- .section .rodata +-errmsg: +- .string "floating point exception\n" +- .equ msgsz,.-errmsg-1 + + .text + .globl __umoddi3 +-- +2.23.0 + diff --git a/0008-lib-c-Update-gensys.sh-for-i386-linux.patch b/0008-lib-c-Update-gensys.sh-for-i386-linux.patch @@ -0,0 +1,111 @@ +From 54c5eea3ef22e2cea52b4422eda17a4523dec8a9 Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Fri, 1 Nov 2019 17:50:14 +0100 +Subject: [PATCH 08/11] [lib/c] Update gensys.sh for i386/linux + +--- + src/libc/arch/i386/linux/gensys.sh | 53 ++++++++++++++++++++++++---- + src/libc/arch/i386/linux/syscall.lst | 21 +++++------ + 2 files changed, 58 insertions(+), 16 deletions(-) + +diff --git a/src/libc/arch/i386/linux/gensys.sh b/src/libc/arch/i386/linux/gensys.sh +index 35ab4752..c1d9711b 100755 +--- a/src/libc/arch/i386/linux/gensys.sh ++++ b/src/libc/arch/i386/linux/gensys.sh +@@ -1,20 +1,61 @@ + #!/bin/sh +-# +-# This job is very easy because app and kernel ABI are identical +-# until the 4th parameter, so we only have to set the syscall +-# number in eax + + sed 's/[ ]*#.*// + /^$/d' syscall.lst | +-while read num name ++while read num name noper + do + cat <<EOF > $name.s + .file "$name.s" + + .globl $name + $name: ++EOF ++ ++if test $noper -eq 0 ++then ++cat <<EOF >> $name.s + movl \$$num,%eax +- syscall ++ int \$0x80 ++EOF ++ ++elif test $noper -eq 1 ++then ++cat <<EOF >> $name.s ++ pushl %ebp ++ movl %esp,%ebp ++ movl 8(%ebp),%ebx ++ movl \$$num,%eax ++ int \$0x80 ++ popl %ebp ++EOF ++ ++elif test $noper -eq 2 ++then ++cat <<EOF >> $name.s ++ pushl %ebp ++ movl %esp,%ebp ++ movl 8(%ebp),%ebx ++ movl 12(%ebp),%ecx ++ movl \$$num,%eax ++ int \$0x80 ++ popl %ebp ++EOF ++ ++elif test $noper -eq 3 ++then ++cat <<EOF >> $name.s ++ pushl %ebp ++ movl %esp,%ebp ++ movl 8(%ebp),%ebx ++ movl 12(%ebp),%ecx ++ movl 16(%ebp),%edx ++ movl \$$num,%eax ++ int \$0x80 ++ popl %ebp ++EOF ++fi ++cat <<EOF >> $name.s + jmp _cerrno + EOF + done ++ +diff --git a/src/libc/arch/i386/linux/syscall.lst b/src/libc/arch/i386/linux/syscall.lst +index 743bf682..b3152e1e 100644 +--- a/src/libc/arch/i386/linux/syscall.lst ++++ b/src/libc/arch/i386/linux/syscall.lst +@@ -1,10 +1,11 @@ +-#number name +-3 _read +-5 _open +-6 _close +-19 _lseek +-45 _brk +-67 _sigaction +-20 _getpid +-1 _Exit +-37 _kill ++#number name num_of_op ++4 _write 3 ++3 _read 3 ++5 _open 2 ++6 _close 1 ++19 _lseek 3 ++45 _brk 1 ++67 _sigaction 3 ++20 _getpid 0 ++1 _Exit 1 ++37 _kill 2 +-- +2.23.0 + diff --git a/0009-Set-up-toolchain-and-scripts-for-i386.patch b/0009-Set-up-toolchain-and-scripts-for-i386.patch @@ -0,0 +1,63 @@ +From 5087af9c6a9708c53f7455d33ed1c0a54a034119 Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Fri, 1 Nov 2019 20:43:25 +0100 +Subject: [PATCH 09/11] Set up toolchain and scripts for i386 + +--- + config/toolchain/gnu.mk | 9 ++++----- + scripts/rules.mk | 7 ++++--- + 2 files changed, 8 insertions(+), 8 deletions(-) + +diff --git a/config/toolchain/gnu.mk b/config/toolchain/gnu.mk +index 8f193c6e..6d157df0 100644 +--- a/config/toolchain/gnu.mk ++++ b/config/toolchain/gnu.mk +@@ -1,5 +1,3 @@ +-TOOLCFLAGS = -std=c99 +- + COMP = gcc + ASM = as + LINKER = ld +@@ -7,6 +5,7 @@ RANLIB = ranlib + ARCHIVE = ar + + ARCHIVEFLAGS = -U +-NOPIE_CFLAGS = -nopie +-NOPIE_LDFLAGS = -nopie +-TOOLCFLAGS = -std=c99 ++NOPIE_CFLAGS = -no-pie ++NOPIE_LDFLAGS = -no-pie ++TOOLCFLAGS = -std=c99 -fno-stack-protector -no-pie ++ +diff --git a/scripts/rules.mk b/scripts/rules.mk +index 29c71446..99cef334 100644 +--- a/scripts/rules.mk ++++ b/scripts/rules.mk +@@ -1,5 +1,5 @@ +-CONF=amd64-linux +-TOOL=unix ++CONF=i386-linux ++TOOL=gnu + HOST=unix + include $(PROJECTDIR)/config/config/$(CONF).mk + include $(PROJECTDIR)/config/toolchain/$(TOOL).mk +@@ -31,6 +31,7 @@ SCC_CFLAGS =\ + $(SYSCFLAGS)\ + $(INCLUDE)\ + -g\ ++ -O0\ + $(CFLAGS) + + SCC_LDFLAGS =\ +@@ -64,7 +65,7 @@ FORALL = +@set -e ;\ + $(CC) $(SCC_LDFLAGS) -o $@ $< $(LIBS) + + .s.o: +- $(AS) $(SCC_ASFLAGS) $< -o $@ ++ $(AS) $(SCC_ASFLAGS) -g $< -o $@ + + .c.o: + $(CC) $(SCC_CFLAGS) -o $@ -c $< +-- +2.23.0 + diff --git a/0010-lib-c-Update-crt-posix.s-for-i386-linux.patch b/0010-lib-c-Update-crt-posix.s-for-i386-linux.patch @@ -0,0 +1,40 @@ +From 23db947ac18d9b19329400985605b180041f00bd Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Fri, 1 Nov 2019 20:46:51 +0100 +Subject: [PATCH 10/11] [lib/c] Update crt-posix.s for i386/linux + +--- + src/libc/arch/i386/crt-posix.s | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +diff --git a/src/libc/arch/i386/crt-posix.s b/src/libc/arch/i386/crt-posix.s +index 88013697..ca0c7f1e 100644 +--- a/src/libc/arch/i386/crt-posix.s ++++ b/src/libc/arch/i386/crt-posix.s +@@ -2,16 +2,19 @@ + .globl _environ + _environ: + .long 0 +- ++ + .text +- .global start ++ .globl _start + _start: + movl %esp,%ebp + +- movl (%ebp),%edi +- leal 8(%ebp),%esi + leal 16(%ebp,%edi,8),%edx + movl %edx,_environ ++ pushl %edx ++ leal 8(%ebp),%esi ++ pushl %esi ++ movl (%ebp),%edi ++ pushl %edi + + call main + movl %eax,%edi +-- +2.23.0 + diff --git a/0011-tests-Temp-fix.patch b/0011-tests-Temp-fix.patch @@ -0,0 +1,95 @@ +From dd5e3daf78fd6c0938bc3d5c45107da84d4666ef Mon Sep 17 00:00:00 2001 +From: zerous Naveen Narayanan <zerous@nocebo.space> +Date: Fri, 1 Nov 2019 20:50:33 +0100 +Subject: [PATCH 11/11] [tests] Temp fix + +--- + tests/libc/execute/Makefile | 4 ++-- + tests/libc/execute/cc.sh | 18 ++++++++++-------- + tests/libc/execute/chktest.sh | 4 ++-- + 3 files changed, 14 insertions(+), 12 deletions(-) + +diff --git a/tests/libc/execute/Makefile b/tests/libc/execute/Makefile +index 00595eaa..8f81322c 100644 +--- a/tests/libc/execute/Makefile ++++ b/tests/libc/execute/Makefile +@@ -1,6 +1,6 @@ + .POSIX: + +-ROOT = ../../../root ++ROOT = ../../.. + CFLAGS = + CC = SCCPREFIX=$(ROOT) ./cc.sh + +@@ -10,7 +10,7 @@ CC = SCCPREFIX=$(ROOT) ./cc.sh + all: tests + + tests: +- @CFLAGS='' SCCPREFIX=$(ROOT) chktest.sh libc-tests.lst ++ @CFLAGS='' SCCPREFIX=$(ROOT) ./chktest.sh libc-tests.lst + + clean: + rm -f *.o *core a.out test.log +diff --git a/tests/libc/execute/cc.sh b/tests/libc/execute/cc.sh +index 1b2460c3..cfa1a264 100755 +--- a/tests/libc/execute/cc.sh ++++ b/tests/libc/execute/cc.sh +@@ -1,6 +1,7 @@ + #!/bin/sh + + set -e ++set -x + + for i + do +@@ -29,22 +30,23 @@ do + done + + sys=${sys:-`uname | tr 'A-Z' 'a-z'`} +-abi=${abi:-amd64-sysv} ++abi=${abi:-i386} + out=${out:-a.out} + root=${root:-$SCCPREFIX} +-inc=$root/include/scc +-arch_inc=$root/include/scc/bits/$abi +-sys_inc=$root/include/scc/bits/$sys ++inc=$root/include ++arch_inc=$inc/bits/$abi ++sys_inc=$inc/bits/$sys + lib=$root/lib/scc/${abi}-${sys} + obj=${1%.c}.o + + includes="-nostdinc -I$inc -I$arch_inc -I$sys_inc" + flags="-std=c99 -g -w -fno-stack-protector --freestanding -static" + +-if ! gcc -nopie 2>&1 | grep unrecogn >/dev/null ++# TODO: find a better way to handle CROSS_COMPILE ++if ! i686-pc-linux-gnu-gcc -nopie 2>&1 | grep unrecogn >/dev/null + then +- pie=-nopie ++ pie=-no-pie + fi + +-gcc $flags $pie $includes -c $1 +-ld -g $pie -z nodefaultlib -static -L$lib $lib/crt.o $obj -lc -o $out ++i686-pc-linux-gnu-gcc $flags $pie $includes -c $1 ++i686-pc-linux-gnu-ld -g -z nodefaultlib -static -L$lib $lib/crt.o $obj -lc -o $out +diff --git a/tests/libc/execute/chktest.sh b/tests/libc/execute/chktest.sh +index ffafe66d..cbbf8d10 100755 +--- a/tests/libc/execute/chktest.sh ++++ b/tests/libc/execute/chktest.sh +@@ -13,9 +13,9 @@ do + rm -f a.out *.o $tmp1 $tmp2 + + (echo $i +- ./cc.sh $CFLAGS $i.c ++ ./cc.sh $CFLAGS -o $i $i.c + echo '/^output:$/+;/^end:$/-'w $tmp1 | ed -s $i.c +- ./a.out > $tmp2 ++ ./$i > $tmp2 + diff -u $tmp1 $tmp2) >> test.log 2>&1 && + printf '[PASS]' || printf '[FAIL]' + printf "$state\t%s\n" $i +-- +2.23.0 +