Commit 9e669d9871 for aom
commit 9e669d98719127c674a1d48f17690bb209adaa43
Author: Abhishek Sharma <abhishekcs@utexas.edu>
Date: Thu Nov 19 15:19:54 2026 -0600
x86_64: Add CET SHSTK ELF note for asm files
Automatically mark all x86-64 asm object files as SHSTK-compatible.
Shadow Stack (SHSTK) is an x86-64 hardware feature part of Control-Flow
Enforcement Technology (CET). It protects the integrity of return addresses
by pushing them to a separate shadow stack. 'call' instructions push the
return address to both the regular and shadow stack. 'ret' instructions
pop from both stacks and check that they match.
For code that is well-behaved this should just work transparently when
enabled. Since the linker adds the ELF note only if all object files have
it, this is needed for all users of libaom to be marked SHSTK compatible.
The change in third_party/x86inc/x86inc.asm is adapted from upstream x264.
Bug: 42302476
Change-Id: Iba4b9610208f1b51e3cc5ac5fef633b032ab023a
diff --git a/aom_ports/x86_abi_support.asm b/aom_ports/x86_abi_support.asm
index a65e760a80..23b9ef8e58 100644
--- a/aom_ports/x86_abi_support.asm
+++ b/aom_ports/x86_abi_support.asm
@@ -409,6 +409,20 @@ section .note.GNU-stack noalloc noexec nowrite progbits
section .text
%elifidn __OUTPUT_FORMAT__,elf64
section .note.GNU-stack noalloc noexec nowrite progbits
+%ifdef __NASM_VERSION_ID__
+%if __NASM_VERSION_ID__ >= 0x020e0300 ; 2.14.03
+; Control-flow Enforcement Technology (CET) properties.
+section .note.gnu.property alloc noexec nowrite note align=8
+ dd 0x00000004 ; n_namesz
+ dd 0x00000010 ; n_descsz
+ dd 0x00000005 ; n_type = NT_GNU_PROPERTY_TYPE_0
+ db "GNU",0 ; n_name
+ dd 0xc0000002 ; pr_type = GNU_PROPERTY_X86_FEATURE_1_AND
+ dd 0x00000004 ; pr_datasz
+ dd 0x00000002 ; pr_data = GNU_PROPERTY_X86_FEATURE_1_SHSTK
+ dd 0x00000000 ; pr_padding
+%endif
+%endif
section .text
%elifidn __OUTPUT_FORMAT__,elfx32
section .note.GNU-stack noalloc noexec nowrite progbits
diff --git a/third_party/x86inc/README.libaom b/third_party/x86inc/README.libaom
index d6f89011f6..dca059c003 100644
--- a/third_party/x86inc/README.libaom
+++ b/third_party/x86inc/README.libaom
@@ -22,3 +22,4 @@ Use .text instead of .rodata on macho to avoid broken tables in PIC mode.
Use .text with no alignment for aout.
Only use 'hidden' visibility with Chromium.
Prefix ARCH_* with AOM_.
+cherry-pick: 12426f5f x86inc: Add support for ELF CET properties
diff --git a/third_party/x86inc/x86inc.asm b/third_party/x86inc/x86inc.asm
index b0421f51fa..546072ef29 100644
--- a/third_party/x86inc/x86inc.asm
+++ b/third_party/x86inc/x86inc.asm
@@ -913,6 +913,23 @@ BRANCH_INSTR jz, je, jnz, jne, jl, jle, jnl, jnle, jg, jge, jng, jnge, ja, jae,
; This is needed for ELF, otherwise the GNU linker assumes the stack is executable by default.
%if FORMAT_ELF
[SECTION .note.GNU-stack noalloc noexec nowrite progbits]
+
+ %ifdef __NASM_VERSION_ID__
+ %if __NASM_VERSION_ID__ >= 0x020e0300 ; 2.14.03
+ %if AOM_ARCH_X86_64
+ ; Control-flow Enforcement Technology (CET) properties.
+ [SECTION .note.gnu.property alloc noexec nowrite note align=gprsize]
+ dd 0x00000004 ; n_namesz
+ dd gprsize + 8 ; n_descsz
+ dd 0x00000005 ; n_type = NT_GNU_PROPERTY_TYPE_0
+ db "GNU",0 ; n_name
+ dd 0xc0000002 ; pr_type = GNU_PROPERTY_X86_FEATURE_1_AND
+ dd 0x00000004 ; pr_datasz
+ dd 0x00000002 ; pr_data = GNU_PROPERTY_X86_FEATURE_1_SHSTK
+ dd 0x00000000 ; pr_padding
+ %endif
+ %endif
+ %endif
%endif
; Tell debuggers how large the function was.