From 2860784b54835058ad0882ef87b13be52754342b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:05:39 -0300 Subject: [PATCH] fix(l1): keep `global_asm!` blocks from leaking their section state `keccak1600-x86_64.s` ends with a `.section .note.gnu.property` block for the CET flags and never switches back. Blocks emitted by `global_asm!` share the assembler's section state within a codegen unit, so whichever block rustc places next continues in that note section: on Rust 1.99-beta the blake2f AVX2 block lands there, putting `_blake2b_f` in a non-executable NOTE section. That the previous ordering worked was luck, not a compiler guarantee, so fix it on our side: wrap the note block in `.pushsection`/`.popsection`, and make each block declare `.text` up front instead of inheriting whatever section it starts in. The x86_64 keccak file already did the latter; the ARMv8 files and the blake2f file did not. Closes #7246 --- crates/common/crypto/blake2f/x86_64.s | 4 ++++ crates/common/crypto/keccak/README.md | 7 ++++++- crates/common/crypto/keccak/keccak1600-armv8-elf.s | 5 +++++ crates/common/crypto/keccak/keccak1600-armv8-macho.s | 5 +++++ crates/common/crypto/keccak/keccak1600-x86_64.s | 9 ++++++++- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/common/crypto/blake2f/x86_64.s b/crates/common/crypto/blake2f/x86_64.s index 448a0517ad5..49bbdab2f6c 100644 --- a/crates/common/crypto/blake2f/x86_64.s +++ b/crates/common/crypto/blake2f/x86_64.s @@ -35,6 +35,10 @@ .endm + # Be explicit about the section: `global_asm!` blocks inherit the assembler's + # current section from whatever block was emitted before them in this codegen + # unit. See issue #7246. + .text .global _blake2b_f .type _blake2b_f, @function _blake2b_f: diff --git a/crates/common/crypto/keccak/README.md b/crates/common/crypto/keccak/README.md index 6bb78ea1524..7212f7038dc 100644 --- a/crates/common/crypto/keccak/README.md +++ b/crates/common/crypto/keccak/README.md @@ -37,7 +37,12 @@ $ ./keccak1600-armv8.pl linux64 keccak1600-armv8.s $ cd ../x86_64 $ ./keccak1600-x86_64.pl linux64 keccak1600-x86_64.s ``` -- The x86 can be directly imported by the Rust compiler with the current options, but the ARM code requires a few changes, commented at the top of the `keccak1600-armv8.s` file. +- Both the x86 and the ARM code need a few changes before the Rust compiler can import them. Each file lists its + own changes in a `Modified:` comment at the top; the ARM code needs the most of them. +- One change applies to every file: each `global_asm!` block must both start in `.text` and leave `.text` + current when it ends. Blocks in the same codegen unit share the assembler's section state, so a block that + finishes in some other section makes the *next* block emit its functions there instead of in `.text`. + This is why the trailing `.note.gnu.property` block uses `.pushsection`/`.popsection` rather than `.section`. ## Copyright Notice diff --git a/crates/common/crypto/keccak/keccak1600-armv8-elf.s b/crates/common/crypto/keccak/keccak1600-armv8-elf.s index 98d2b828d06..22afb3b913a 100644 --- a/crates/common/crypto/keccak/keccak1600-armv8-elf.s +++ b/crates/common/crypto/keccak/keccak1600-armv8-elf.s @@ -6,10 +6,15 @@ // Reason: `.L` local labels are ELF-specific. // - Replaced instance of `adr x??,label` by `adrp x??,label` followed by // `add x??,x??,:lo12:label`. +// - Added an explicit `.text`. +// Reason: `global_asm!` blocks inherit the assembler's current section from +// whatever block was emitted before them in the same codegen unit. // // TODO: this is probably a matter of selecting the right parameter // for the translator. +.text + .align 8 // strategic alignment and padding that allows to use // address value as loop termination condition... .quad 0,0,0,0,0,0,0,0 diff --git a/crates/common/crypto/keccak/keccak1600-armv8-macho.s b/crates/common/crypto/keccak/keccak1600-armv8-macho.s index 0308c23f071..1ff1c81c584 100644 --- a/crates/common/crypto/keccak/keccak1600-armv8-macho.s +++ b/crates/common/crypto/keccak/keccak1600-armv8-macho.s @@ -6,10 +6,15 @@ // Reason: `.L` local labels are ELF-specific. // - Replaced instance of `adr x??,label` by `adrp x??,label@PAGE` followed by // `add x??,x??,label@PAGEOFF`. +// - Added an explicit `.text`. +// Reason: `global_asm!` blocks inherit the assembler's current section from +// whatever block was emitted before them in the same codegen unit. // // TODO: this is probably a matter of selecting the right parameter // for the translator. +.text + .align 8 // strategic alignment and padding that allows to use // address value as loop termination condition... .quad 0,0,0,0,0,0,0,0 diff --git a/crates/common/crypto/keccak/keccak1600-x86_64.s b/crates/common/crypto/keccak/keccak1600-x86_64.s index d7652991330..1d3413f7b1d 100644 --- a/crates/common/crypto/keccak/keccak1600-x86_64.s +++ b/crates/common/crypto/keccak/keccak1600-x86_64.s @@ -1,3 +1,9 @@ +# Modified: +# - Wrapped the trailing `.note.gnu.property` block in `.pushsection`/`.popsection`. +# Reason: `global_asm!` blocks share the assembler's section state within a codegen +# unit, so leaving the note section current made a *following* `global_asm!` emit its +# functions into `.note.gnu.property` instead of `.text`. See issue #7246. + .text .type __KeccakF1600,@function @@ -528,9 +534,10 @@ iotas: .size iotas,.-iotas .byte 75,101,99,99,97,107,45,49,54,48,48,32,97,98,115,111,114,98,32,97,110,100,32,115,113,117,101,101,122,101,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 -.section .note.gnu.property,"a",@note +.pushsection .note.gnu.property,"a",@note .long 4,2f-1f,5 .byte 0x47,0x4E,0x55,0 1: .long 0xc0000002,4,3 .align 8 2: +.popsection