From c42c5d94b8944e19cd17a5b540e4c70013c62b92 Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 17 Feb 2022 21:33:21 -0500 Subject: fixed += bug with non-char pointers tcc 0.9.25 can't compile musl (or any libc, probably). will probably need to write libc for tcc, then compile gcc or a later version of tcc with it --- 05/codegen.b | 9 +++++++-- 05/main.c | 12 ++++++------ 05/stdc_common.h | 1 + 05/tcc-0.9.25/stdc_common.h | 1 + 4 files changed, 15 insertions(+), 8 deletions(-) (limited to '05') diff --git a/05/codegen.b b/05/codegen.b index 4d2ca1b..4a22399 100644 --- a/05/codegen.b +++ b/05/codegen.b @@ -1566,6 +1566,7 @@ function generate_push_expression local addr1 local addr2 local type + local type2 type = expr + 4 type = *4type @@ -1721,6 +1722,8 @@ function generate_push_expression :generate_assign_add expr += 8 p = expression_get_end(expr) + type2 = p + 4 + type2 = *4type2 p = generate_push_expression_casted(statement, p, type) generate_push_address_of_expression(statement, expr) expr = p @@ -1729,7 +1732,7 @@ function generate_push_expression generate_stack_dereference(statement, type) emit_mov_rax_qword_rsp_plus_imm32(16) ; mov rax, [rsp+16] (addend) emit_push_rax() ; push rax - generate_stack_add(statement, type, type, type) + generate_stack_add(statement, type, type2, type) emit_mov_rax_qword_rsp_plus_imm32(8) ; mov rax, [rsp+8] (address) emit_push_rax() ; push rax generate_stack_assign(statement, type) @@ -1740,6 +1743,8 @@ function generate_push_expression :generate_assign_sub expr += 8 p = expression_get_end(expr) + type2 = p + 4 + type2 = *4type2 p = generate_push_expression_casted(statement, p, type) generate_push_address_of_expression(statement, expr) expr = p @@ -1748,7 +1753,7 @@ function generate_push_expression generate_stack_dereference(statement, type) emit_mov_rax_qword_rsp_plus_imm32(16) ; mov rax, [rsp+16] (2nd operand) emit_push_rax() ; push rax - generate_stack_sub(statement, type, type, type) + generate_stack_sub(statement, type, type2, type) emit_mov_rax_qword_rsp_plus_imm32(8) ; mov rax, [rsp+8] (address) emit_push_rax() ; push rax generate_stack_assign(statement, type) diff --git a/05/main.c b/05/main.c index 0eee651..3c989d9 100644 --- a/05/main.c +++ b/05/main.c @@ -1,6 +1,6 @@ /* #define _STDLIB_DEBUG */ /* #include */ -/* #include */ +#include /* #include */ /* #include */ /* #include */ @@ -9,10 +9,10 @@ /* #include */ /* */ -char *p = "a"; -char s[] = "hello\0there"; - -int _main(int argc, char **argv) { - return s; +int main(int argc, char **argv) { + int *p = 0x100; + p += 1; + printf("%p\n",p); + return 0; } diff --git a/05/stdc_common.h b/05/stdc_common.h index 1540f19..b9ffd9d 100644 --- a/05/stdc_common.h +++ b/05/stdc_common.h @@ -264,6 +264,7 @@ int wait4(int pid, int *status, int options, struct rusage *rusage) { #define SIGSEGV 11 #define SIGTERM 15 #define SIGBUS 7 +#define SIGTRAP 5 void abort(void) { kill(getpid(), SIGABRT); } diff --git a/05/tcc-0.9.25/stdc_common.h b/05/tcc-0.9.25/stdc_common.h index 1540f19..b9ffd9d 100644 --- a/05/tcc-0.9.25/stdc_common.h +++ b/05/tcc-0.9.25/stdc_common.h @@ -264,6 +264,7 @@ int wait4(int pid, int *status, int options, struct rusage *rusage) { #define SIGSEGV 11 #define SIGTERM 15 #define SIGBUS 7 +#define SIGTRAP 5 void abort(void) { kill(getpid(), SIGABRT); } -- cgit v1.2.3