Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-22
17:19 • Ticket [37108037b9] Code cleanups to support CHERI status still Closed with ... artifact: 062eca0ac8 user: serhiy.storchaka
2026-10-15
11:29 • Closed ticket [37108037b9]. artifact: 23ad5c5bf1 user: serhiy.storchaka
2023-11-30
09:58 • Ticket [37108037b9]: 3 changes artifact: 5296db0b85 user: gahr
2023-03-28
10:41 • Ticket [37108037b9]: 3 changes artifact: 66bf6e7637 user: jrtc27
09:35 • Ticket [37108037b9]: 3 changes artifact: 094b1c1b3f user: chrstphrchvz
2022-09-01
07:27 • Ticket [37108037b9]: 3 changes artifact: 46ad076856 user: chrstphrchvz
2022-08-31
11:08 • Pending ticket [37108037b9]. artifact: 7e322d8b1e user: jan.nijtmans
2022-08-30
23:02
Apply patch 0006 from [37108037b9]: Code cleanups to support CHERI check-in: 5fcc28ca35 user: jan.nijtmans tags: core-8-branch
22:30
More code cleanup, inspired by [37108037b9] check-in: 949071abc3 user: jan.nijtmans tags: core-8-branch
2022-08-29
22:48
[37108037b9], patch 0004 check-in: cf777f69bb user: jan.nijtmans tags: core-8-branch
2022-08-26
23:11
[37108037b9]: Apply patch 0005 for CHERI check-in: a9db66657b user: jan.nijtmans tags: core-8-branch
20:23
[37108037b9]: Code cleanups to support CHERI: Apply patch 0007 (modified) check-in: cee192b957 user: jan.nijtmans tags: core-8-branch
2022-08-25
20:36
[37108037b9]: Code cleanups to support CHERI. Apply patch 0001 and 0003 (and a few more potential al... check-in: ffa62b189d user: jan.nijtmans tags: core-8-branch
09:46 • Ticket [37108037b9] Code cleanups to support CHERI status still Open with 4 ... artifact: d843135d95 user: jan.nijtmans
2022-08-23
07:27
Patch (8) from [37108037b9]: Code cleanups to support CHERI check-in: 6b6bf25797 user: jan.nijtmans tags: core-8-6-branch
2022-08-12
23:21 • Add attachment [/artifact/7b31eaf6341d5f93|0008-Silence-harmless-warnings-on-CHERI-by-using-INT2PTR-... artifact: d5dde281fe user: jrtc27
23:21 • Add attachment [/artifact/1b1aa6dc2e6e0899|0007-tclHash-Fix-strict-aliasing-violations-breaking-CHER... artifact: 3c72114510 user: jrtc27
23:21 • Add attachment [/artifact/973b763342c6343c|0006-tclExecute-Fix-for-CHERI-by-not-violating-object-all... artifact: 4316977d28 user: jrtc27
23:21 • Add attachment [/artifact/e858d625f2a570a4|0005-testcmdtoken-Don-t-rely-on-round-tripping-pointers-t... artifact: 8dce5b4348 user: jrtc27
23:20 • Add attachment [/artifact/90c8e607b4b43da4|0004-tclExecute-Fix-for-CHERI-by-not-assuming-ptrdiff_t-i... artifact: d74723a6be user: jrtc27
23:20 • Add attachment [/artifact/aeff479a5cd2481a|0003-tclInt-Fix-TCL_ALIGN-for-CHERI-by-not-hard-coding-8-... artifact: 9364860f07 user: jrtc27
23:20 • Add attachment 0002-tclInt-Fix-U-INT2PTR-PTR2-U-INT-for-CHERI.patch to ... artifact: 807726f0c7 user: jrtc27
23:19 • Add attachment [/artifact/c1bd6a1a4ef09490|0001-tclCompile-Be-more-careful-about-alignment-in-TclIni... artifact: 3fed471882 user: jrtc27
23:15 • New ticket [37108037b9] Code cleanups to support CHERI. artifact: 5a618e1fea user: jrtc27

Code cleanups to support CHERI

Closed / Fixed37108037b980ea6e705f56a9d983e05ee218dd0cCreated 4 years agoUpdated 42 days ago
Descriptionplain2022-08-12 23:15:26
The attached patch series contains a number of code cleanups needed
(with the exception of patches 1 and 8 which aren't needed but I
believe are a good idea to have and discovered during this porting) to
support CHERI, and thus Arm's Morello prototype[1]. With these changes
there are no regressions when running make check on Morello CheriBSD
compared with plain AArch64 CheriBSD (for some reason both fail to run
the chanio tests with "kevent: Operation not supported by device"; I
don't know if that's a Tcl bug, a FreeBSD bug, a CheriBSD bug or an
issue with my environment, but the result is the same for both and
pre-existing on AArch64 so it's not a bug in porting Tcl to CHERI).

[1] https://www.arm.com/architecture/cpu/morello
Referenced by7
jan.nijtmanswiki2022-08-25 09:46:29

Thank you for those patches! The 008_* patch has already been applied to core-8-6-branch and up. I will have a look at the other ones as well.

One remark: the PTR2INT/INT2PTR macro's only guarantee round-trip from size_t -> pointer -> size_t (in Tcl 8.6 it was int -> pointer -> int), not pointer -> size_t -> pointer, since size(size_t) might be smaller than sizeof(void *). So, whenever size_t is insufficient to store what the code wants, use a pointer. I don't think the PTR2INT/INT2PTR should be modified. In stead the code should be modified not to use size_t/ptrdiff_t in the places where it is problematic.

Anyway, Thanks! I will have a further look.

jan.nijtmanswiki2022-08-31 11:08:32

All provide patches, except 0002, now found their way into core-8-branch and trunk. Assuming CHERI now works, this ticket can be closed. Please confirm.

If any other issues with CHERI arise, feel free to provide a new ticket or re-open this one.

chrstphrchvzmarkdown2022-09-01 07:27:13

Bigger picture comment: I wonder if CHERI’s effectiveness is limited by how software such as Tcl internally wrap malloc() by default for small allocations (for performance, at least back when this functionality was implemented 20 or so years ago, and possibly debugging). External memory error checking software (e.g. Valgrind, AddressSanitizer) already require that this internal wrapper/allocator be disabled to allow complete error detection and reporting.

chrstphrchvzwiki2023-03-28 09:35:36

Usage of __LP64__ in Tcl/Tk (e.g. for detecting 64-bit long) likely also requires auditing, as CHERI does not define this macro. See slide 6 of https://soft-dev.org/events/cheritech22/slides/Richardson.pdf which suggests checking __SIZEOF_LONG__ == 8 instead.

jrtc27plain2023-03-28 10:41:19
Not sure how I missed these comments from last August and only saw today's follow-up, but here's my response:

It's been long enough that I don't recall whether patch 2 is needed for correctness. However, we do emit a warning on pointer<->integer casts that don't go through (u)intptr_t because there's a high chance the code is wrong (and it's quite hard to tell statically for certain), so even if none of the users need to be able to do pointer->integer->pointer losslessly it's going to warn as-is, which is a warning we often like to make an error so we can catch all such potentially-problematic cases. If what you say is true then the way we'd express it would be `((void *)(intptr_t)(ptrdiff_t)(p))` and `((ptrdiff_t)(intptr_t)(p))`, which are semantically equivalent to the original code, but use a redundant intermediary cast to express to the compiler that your intent is indeed to be using just a plain integer. Would you accept such a patch instead? Either way I'll need to test that there is indeed nothing trying to use these for actual pointers.

Re custom/wrapping allocators, yes, those are a nuisance to deal with and these days are often a bad idea for performance anyway (though maybe still with some allocators). You can either make your allocator use the necessary intrinsics to apply bounds (and be able to cope with the reduced bounds on free) or turn it off; which is the right option depends on the use case. Our porting of most software of late has been focused on just getting it working without extensively auditing it for things like custom memory allocators where adaptation is needed to avoid slight holes in the security story.

Re __LP64__ I don't think I spotted such usage, but it may well be there are cases not exercised by the test suite where stupid things end up happening because it thinks it's 32-bit. There only seem to be 16 results between the tcl and tk repos (at least according to GitHub search, which can be a bit dodgy) though so perhaps not, and it wouldn't take long to audit them.
gahrplain2023-11-30 09:58:18
For the issue related to the chan-io test failing, see https://sourceforge.net/p/tcl/mailman/message/57263727/
serhiy.storchakawiki2026-10-15 11:29:07

Closing: fixed, see above.

serhiy.storchaka Ticket [37108037b9]: 3 changes [History diff]2026-10-22 17:19:26
Log in (anonymous is fine) to add a comment.