From f15008da05ec694cf7eb661925741e683be7fefa Mon Sep 17 00:00:00 2001 From: "Jonathan M. Wilbur" Date: Wed, 31 Jul 2024 04:15:45 -0400 Subject: [PATCH] fix: previous two commits --- tccasm.c | 9 +++++---- tccpp.c | 14 -------------- .../133_exec_section_in_asm.c} | 0 tests/tests2/133_exec_section_in_asm.expect | 1 + .../134_exec_section_in_c.c} | 6 +++++- tests/tests2/134_exec_section_in_c.expect | 1 + tests/undef_func_macro.c | 13 ------------- 7 files changed, 12 insertions(+), 32 deletions(-) rename tests/{exec_section_in_asm.c => tests2/133_exec_section_in_asm.c} (100%) create mode 100644 tests/tests2/133_exec_section_in_asm.expect rename tests/{exec_section_in_c.c => tests2/134_exec_section_in_c.c} (86%) create mode 100644 tests/tests2/134_exec_section_in_c.expect delete mode 100644 tests/undef_func_macro.c diff --git a/tccasm.c b/tccasm.c index a75661e4..e52872b5 100644 --- a/tccasm.c +++ b/tccasm.c @@ -883,8 +883,12 @@ static void asm_parse_directive(TCCState *s1, int global) } } last_text_section = cur_text_section; - if (tok1 == TOK_ASMDIR_section) + if (tok1 == TOK_ASMDIR_section) { use_section(s1, sname); + /* The section directive supports flags, but they are unsupported. + For now, just assume any section contains code. */ + cur_text_section->sh_flags |= SHF_EXECINSTR; + } else push_section(s1, sname); /* If we just allocated a new section reset its alignment to @@ -893,9 +897,6 @@ static void asm_parse_directive(TCCState *s1, int global) if (old_nb_section != s1->nb_sections) cur_text_section->sh_addralign = 1; } - /* The section directive supports flags, but they are unsupported. - For now, just assume any section contains code. */ - cur_text_section->sh_flags |= SHF_EXECINSTR; break; case TOK_ASMDIR_previous: { diff --git a/tccpp.c b/tccpp.c index a59ba814..6f2bc173 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1506,20 +1506,6 @@ static int expr_preprocess(TCCState *s1) tokc.i = c; } else { /* if undefined macro, replace with zero */ - next_nomacro(); - // If the undefined macro is followed by parens, just skip them. - if (tok == '(') { - int bracket_depth = 1; - while (bracket_depth > 0) { - next(); - if (tok == '(') - bracket_depth++; - else if (tok == ')') - bracket_depth--; - } - } else { - unget_tok(tok); // Is this actually the function I want? - } tok = TOK_CINT; tokc.i = 0; } diff --git a/tests/exec_section_in_asm.c b/tests/tests2/133_exec_section_in_asm.c similarity index 100% rename from tests/exec_section_in_asm.c rename to tests/tests2/133_exec_section_in_asm.c diff --git a/tests/tests2/133_exec_section_in_asm.expect b/tests/tests2/133_exec_section_in_asm.expect new file mode 100644 index 00000000..ff342b0e --- /dev/null +++ b/tests/tests2/133_exec_section_in_asm.expect @@ -0,0 +1 @@ +AAAAAAAAA diff --git a/tests/exec_section_in_c.c b/tests/tests2/134_exec_section_in_c.c similarity index 86% rename from tests/exec_section_in_c.c rename to tests/tests2/134_exec_section_in_c.c index 8a6fbac3..fea8e2f9 100644 --- a/tests/exec_section_in_c.c +++ b/tests/tests2/134_exec_section_in_c.c @@ -1,3 +1,5 @@ +#include + /* Previously in TinyCC, ELF sections defined in attributes would always have the execute bit not set, so you would get segmentation faults when code in these sections was exectuted. This file is a minimal example of a file that will put @@ -9,5 +11,7 @@ int wumbo (int arg) { } int main () { - return wumbo(2); + wumbo(2); + puts("hi"); + return 0; } diff --git a/tests/tests2/134_exec_section_in_c.expect b/tests/tests2/134_exec_section_in_c.expect new file mode 100644 index 00000000..45b983be --- /dev/null +++ b/tests/tests2/134_exec_section_in_c.expect @@ -0,0 +1 @@ +hi diff --git a/tests/undef_func_macro.c b/tests/undef_func_macro.c deleted file mode 100644 index 00db8ad0..00000000 --- a/tests/undef_func_macro.c +++ /dev/null @@ -1,13 +0,0 @@ -int main () { -// This used to evaluate to 0 (0), which is invalid. -// Now it should evaluate to 0. -#if WUMBOED(WUMBO) -#endif - -// Just trying a more complicated test case. -#if WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY - return 0; -#elif WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY - return 1; -#endif -} -- 2.11.4.GIT