Try attached patch.

I found some more bugs on other targets as well.

    Herman

On 12/20/25 19:51, Eric Raible wrote:
The "tcc -run" is irrelevant - I shouldn't have mentioned that.
The intent was to make the test case easy to reproduce.

The bug I'm trying to report seems to be libtcc-specific.
I see the same thing when compiling to executable:

tcc tcc-libtcc-address-bug.c -ltcc && ./a.out
clang tcc-libtcc-address-bug.c -ltcc && ./a.out
gcc tcc-libtcc-address-bug.c -ltcc && ./a.out

In all cases test1() works but test2() dereference random values
(run-to-run return value is usually different and sometimes it crashes).

For the record, I build  in a subdirectory, after: ../configure --source-path=/home/raible/tinycc BTW this is not blocking me in any way but I did find it so I thought I'd report it.

Thanks - Eric


On Sat, Dec 20, 2025 at 12:55 AM Herman ten Brugge via Tinycc-devel <[email protected]> wrote:

    On 12/19/25 22:29, Eric Raible wrote:
    This is a libtcc issue: gcc and clang behave the same way.
    // libtcc mangles casts of hard-coded pointer values
    // Run with: tcc -run tcc-libtcc-address-bug.c
    // The 2nd call to 'test()' produces incorrect results, and often
    crashes with SIGSEGV.
    //
    // tcc version 0.9.28rc 2025-12-15 mob@85694274 (AArch64 Linux)
    // uname -a => Linux penguin 6.6.88-08646-g082267a5c5ac #1 SMP
    PREEMPT Fri, 29 Aug 2025 06:42:16 -0700 aarch64 GNU/Linux

    Did you configure tcc with '--disable-static'?
    Without this you will overwrite the tcc_new() of the current code.

        Herman
    _______________________________________________
    Tinycc-devel mailing list
    [email protected]
    https://lists.nongnu.org/mailman/listinfo/tinycc-devel

diff --git a/arm64-gen.c b/arm64-gen.c
index 03ae56c..01ea390 100644
--- a/arm64-gen.c
+++ b/arm64-gen.c
@@ -503,17 +503,19 @@ ST_FUNC void load(int r, SValue *sv)
     }
 
     if (svr == (VT_CONST | VT_LVAL)) {
+       uint64_t i = sv->c.i;
+
        if (sv->sym)
             arm64_sym(30, sv->sym, // use x30 for address
-                     arm64_check_offset(0, arm64_type_size(svtt), sv->c.i));
+                     arm64_check_offset(0, arm64_type_size(svtt), i));
        else
-           arm64_movimm (30, sv->c.i);
+           arm64_movimm (30, i), i = 0;
         if (IS_FREG(r))
             arm64_ldrv(arm64_type_size(svtt), fltr(r), 30,
-                      arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
+                      arm64_check_offset(1, arm64_type_size(svtt), i));
         else
             arm64_ldrx(!(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(r), 30,
-                      arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
+                      arm64_check_offset(1, arm64_type_size(svtt), i));
         return;
     }
 
@@ -621,17 +623,19 @@ ST_FUNC void store(int r, SValue *sv)
     }
 
     if (svr == (VT_CONST | VT_LVAL)) {
+       uint64_t i = sv->c.i;
+
        if (sv->sym)
             arm64_sym(30, sv->sym, // use x30 for address
-                     arm64_check_offset(0, arm64_type_size(svtt), sv->c.i));
+                     arm64_check_offset(0, arm64_type_size(svtt), i));
        else
-           arm64_movimm (30, sv->c.i);
+           arm64_movimm (30, i), i = 0;
         if (IS_FREG(r))
             arm64_strv(arm64_type_size(svtt), fltr(r), 30,
-                      arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
+                      arm64_check_offset(1, arm64_type_size(svtt), i));
         else
             arm64_strx(arm64_type_size(svtt), intr(r), 30,
-                      arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
+                      arm64_check_offset(1, arm64_type_size(svtt), i));
         return;
     }
 
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to