Files
totk-pc-recomp/tools/hactool/mbedtls-asm-clobbers.patch
T
Wellington Dias 89b5126da0 Declare the clobbers mbedtls's x86-64 multiply asm lacks, so a clang-built hactool verifies signatures.
hactool's bundled mbedtls 2.6.1 adds into memory and changes the flags in its MULADDC asm without saying so. gcc builds
happen to work; clang, the Linux release's compiler, keeps values in registers across it at -O1 and above, so every RSA
check failed (NCA header, NPDM, ACID) and the AppImage's setup stopped at the update merge. Found by installing from the
mounted AppImage; a bisection of the mbedtls objects pointed at bignum.o, and the memory and cc clobbers (as later
mbedtls releases have them) fix it. With the patch the full install from the AppImage completes and the game runs.
2026-10-30 14:28:35 -03:00

21 lines
1.0 KiB
Diff

Applied by tools/build_hactool.py to SciresM/hactool (ISC) at 1d64a83450e025622f3468c28fc4164dad2c5ef6, ours.
The x86-64 multiply-accumulate asm of hactool's bundled mbedtls 2.6.1 (MULADDC in bn_mul.h) adds into memory through
rdi and changes the flags without saying so. gcc happens to keep that code correct; clang (the Linux release's
toolchain) keeps memory values in registers across it at -O1 and above, the RSA arithmetic goes wrong, and every
signature check fails (NCA header, NPDM, ACID), which stops the merge of the update. Later mbedtls releases name the
same two clobbers.
diff --git a/mbedtls/include/mbedtls/bn_mul.h b/mbedtls/include/mbedtls/bn_mul.h
index cac3f14..c787b0a 100644
--- a/mbedtls/include/mbedtls/bn_mul.h
+++ b/mbedtls/include/mbedtls/bn_mul.h
@@ -179,7 +179,7 @@
#define MULADDC_STOP \
: "+c" (c), "+D" (d), "+S" (s) \
: "b" (b) \
- : "rax", "rdx", "r8" \
+ : "rax", "rdx", "r8", "memory", "cc" \
);
#endif /* AMD64 */