On 26.02.2024 19:55, Herman ten Brugge via Tinycc-devel wrote:
I commited a change to lib/runmain.c to silence a warning from gcc.
After that testcase 112 did not work any more on 64 bits windows (tested with 
wine).

I can fix this with fix1 (see below) or fix2 (see below).
I do not know enough about windows to make the correct fix.
Both fix1/fix2 look not correct to me.

Hi Herman,

well, first we'd need to know what problem we want to fix.  Maybe
the problem is not in tinycc at all.

Also, the obvious to avoid that gcc warning IMO would be using:

    __attribute__((noreturn)) void __rt_exit(rt_frame *, int);

Also, while at it:

    # ifdef _WIN32
    #   define CONFIG_RUNMEM_RO 0
    # else
    #   define CONFIG_RUNMEM_RO 1
    # endif

would suggest a special case needed for windows.  However that is not
the case.  Whereas according to your comment, the exception is APPLE
actually.  So we'd better say #ifdef __APPLE__ or just use '1' for all
and leave a comment that it's needed for APPLE.

Although tests on github actions did not show such problem, at least
not on macos-11.  Note that CONFIG_RUNMEM_RO was first introduced with
.rodata sections in commit 72f1dea5372ed551d203311e4f2ab769a54de9bd
from 2021-02,  and it seems that tcc already did work on MacOS even
before that commit.  If those previous commits still work then the
problem now might be elsewhere.

Anyway, we cannot disable the runtime-function-unwind table because
without it longjmp() would crash on (a real) _WIN64.

Also obviously, if __rt_exit doesn't return, then any code after it
cannot have any effect:

      __rt_exit(&f, code);
+    abort (); // avoid noreturn warning

I'd assume something weird going on with set/longjmp of WINE and/or
the mingw-gcc that you use.  In any case it is important that
setjmp/longjmp/jmp_buf implementations do match each other.

Which is why I made it so that tcc_setjmp records the longjmp
function pointer too because otherwise it could end up using the
longjmp from libtcc.dll/so and the setjmp from the application
that links to it, with possibly different concepts each. (Not
sure if/where it really can happen though).

-- grischka


     Herman

fix1:
diff --git a/lib/runmain.c b/lib/runmain.c
index 1cbf6dd..307bf45 100644
--- a/lib/runmain.c
+++ b/lib/runmain.c
@@ -60,6 +60,7 @@ typedef struct rt_frame {
  } rt_frame;

  void __rt_exit(rt_frame *, int);
+void abort(void);

  void exit(int code)
  {
@@ -69,7 +70,7 @@ void exit(int code)
      f.fp = 0;
      f.ip = exit;
      __rt_exit(&f, code);
-    for (;;); // avoid noreturn warning
+    abort (); // avoid noreturn warning

  }

  #ifndef _WIN32

fix2:
diff --git a/tccrun.c b/tccrun.c
index b27ccc5..5ea271e 100644
--- a/tccrun.c
+++ b/tccrun.c
@@ -456,7 +456,7 @@ static int protect_pages(void *ptr, unsigned long length, 
int mode)
  static void *win64_add_function_table(TCCState *s1)
  {
      void *p = NULL;
-    if (s1->uw_pdata) {
+    if (0&&s1->uw_pdata) {
          p = (void*)s1->uw_pdata->sh_addr;
          RtlAddFunctionTable(
              (RUNTIME_FUNCTION*)p,


_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to