Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2022-01-15
13:26 • Ticket [26f1328a86] sizeof(int) < sizeof(void*) -> Crash status still ... artifact: e7f9725d9f user: anonymous
2022-01-14
22:52 • Closed ticket [26f1328a86]. artifact: bfd50a2dae user: jan.nijtmans
2022-01-13
13:20
Fix for [26f1328a86]: sizeof(int) < sizeof(void*) -> Crash check-in: 967fa256db user: jan.nijtmans tags: core-8-6-branch
2022-01-12
14:21 • Pending ticket [26f1328a86]: sizeof(int) < sizeof(void*) -> Crash plus... artifact: 652010c131 user: jan.nijtmans
14:19
Proposed fix for [26f1328a86]: sizeof(int) < sizeof(void*) -> Crash closed check-in: 7178b3b439 user: jan.nijtmans tags: bug-26f1328a86
13:07 • Ticket [26f1328a86] sizeof(int) < sizeof(void*) -> Crash status still ... artifact: fbc02301e9 user: anonymous
13:01 • Add attachment test-signed-tcl.c to ticket [26f1328a86863216|26f1328a86... artifact: d3564d3320 user: anonymous
13:00 • Ticket [26f1328a86] sizeof(int) < sizeof(void*) -> Crash status still ... artifact: 6fa2573931 user: anonymous
2022-01-07
16:14 • Add attachment [/artifact/9aa859a6b6335d0c|0001-generic-tclCompile.h-TclGet-Int-AtPtr-Fix-casts.patc... artifact: 70ee304936 user: anonymous
16:13 • New ticket [26f1328a86] sizeof(int) < sizeof(void*) -> Crash. artifact: 4a1768d3de user: anonymous

sizeof(int) < sizeof(void*) -> Crash

Closed / Fixed26f1328a86863216c8fae28f55ff0e09135d5d35Created 5 years agoUpdated 5 years ago
Descriptionplain2022-01-07 16:13:04
I'm having fun trying to port Tcl to Plan 9 at the moment.

One early problem was that Tcl crashed as soon as I was executing
anything, like "parray env".  Debugging the problem, it turns out that
there is a problem in the bytecode interpreter.  This is quite similar
to #2796438 on AIX, it might be the same issue.

The bytecode interpreter uses the macro TclGetInt1AtPtr to read an
offset from the bytecode.  These offsets can be negative Problem is
that the result of that macro is an unsigned int, despite the name.
Adding a huge unsigned number to a pointer instead of a small negative
signed is of course not healthy unless you can count on wrap-around.
But on Plan9/amd64, sizeof(int) == 4 and sizeof(void*) == 8.

The attached path fixes this.  Sorry that this patch is made against
the Git mirror, I hope that is ok.
Referenced by2
anonymous (claiming to be [email protected])plain2022-01-12 13:00:35
Some more information:

The problem originates in JUMP_PEEPHOLE_F (tclExecute.c:317), where
TclGetInt4AtPtr(pc+1)) is calculated and than added to pc in
NEXT_INST_F (tclExecute.c:246).  The bytes at the incoming pc+1 are
0xFF,0xFF,0xFD,0xBC, which is supposed to mean -580.

The attached test program exercises this.  The result on Linux/amd64
is

    $ gcc -o ts test-signed-tcl.c && ./ts
    12 -> U:0
    12U -> U:1
    -12 -> U:0
    int(bytes): -580 U:0
    ptr: 0x55c79ab8f135 + int(bytes) -> 0x55c79ab8eef1 (diff:-580)

The result on Plan 9 (9front/amd64) is:

    term% pcc -o tsp test-signed-tcl.c && tsp
    12 -> U:0
    12U -> U:1
    -12 -> U:0
    int(bytes): -580 U:1
    ptr: 0x200028 + int(bytes) -> 0x1001FFDE4 (diff:4294966716)
anonymous (claiming to be [email protected])plain2022-01-12 13:07:07
> result of that macro is an unsigned int, [...]
> But on Plan9/amd64, sizeof(int) == 4 and sizeof(void*) == 8.

Actually, my initial analysis was wrong regarding the reason for this.
The sizeofs are the same on Linux/amd64.  Still the macro returns an
int on Linux, but an unsigned int on Plan 9, and that *is* actually
the underlying problem.
jan.nijtmanswiki2022-01-12 14:21:13

Proposed fix committed [here]. Looks good, but first let's see what Github ACTIONS thinks of it.

Thanks for the report and the patch!

jan.nijtmans Closed ticket [26f1328a86]. [History diff]2022-01-14 22:52:58
anonymousplain2022-01-15 13:26:03
Thanks, Jan.
Log in (anonymous is fine) to add a comment.