Skip to content
Tcl Source Code Attachment Details
Login

Attachment Details

Overview

Artifact ID: 3c72114510dfe68019372beac9426eba98d8138f641619a67a0523b9ded37d0d
Ticket: 37108037b980ea6e705f56a9d983e05ee218dd0c
Date: 2022-08-12 23:21:45
User: jrtc27
Artifact Attached: 1b1aa6dc2e6e08994b20dcf56a2e17ce787cfca7ac583420edaa1ddffe2f40ea
Filename:0007-tclHash-Fix-strict-aliasing-violations-breaking-CHER.patch
Description:[PATCH 7/8] tclHash: Fix strict aliasing violations breaking CHERI support This is needed to support CHERI, and thus Arm's experimental Morello prototype, where pointers are implemented using unforgeable capabilities that include bounds and permissions metadata to provide fine-grained spatial and referential memory safety, as well as revocation by sweeping memory to provide heap temporal memory safety. The current tclHash implementation used int[] as the underlying storage for arbitrary objects. However, this violates strict aliasing, as int[] can only be used to store integers, and int * cannot alias non-integers. On most architectures this ends up being harmless (though with LTO may be less harmless as the translation unit boundary no longer exists to hide this violation from the compiler), but on CHERI copying pointers as an array of integers loses the set tag bit marking the capability as valid/not forged (unless using a non-inlined memcpy) since the capabilities used to represent those pointers must be copied as a single unit. This strict aliasing violation is perhaps also why Tcl_GetHashKey did not distinguish the string key case from the array key case, always using the string member; using the words member would have made the strict aliasing violation visible outside the translation unit and been at risk of breaking due to compiler optimisations. Fix this by using a char[] as the underlying storage instead, with memcpy and memcmp used to implement copying and comparing respectively. Since this is the same type as is already used for string we can unify the two union members into a single bytes member. This also simplifies the implementation. Note that for API compatibility keyType continues to be in units of sizeof(int) for that case rather than bytes.
Content:
(file is 0 bytes of binary data)