Skip to content

optee-utee-build: fix generated TA header symbol ABI - #337

Merged
ivila merged 2 commits into
apache:mainfrom
ivila:fix/user-ta-header-abi
Nov 9, 2026
Merged

ivila merged 2 commits into
apache:mainfrom
ivila:fix/user-ta-header-abi

Conversation

@ivila

@ivila ivila commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

The generated TA header exported two symbols whose layout did not match the
C declarations used by OP-TEE:

  • trace_ext_prefix was emitted as pub static trace_ext_prefix: &[u8].
    With #[unsafe(no_mangle)], that exports a fat pointer (data pointer plus
    length), while C declares extern const char trace_ext_prefix[]. OP-TEE
    therefore read the pointer bytes instead of the prefix. Emit a sized byte
    array instead, with a length that includes the trailing NUL.
  • ta_heap is handed to OP-TEE's allocator, which writes into the buffer even
    though generated TA code never accesses it directly. Emit it as static mut
    so the generated Rust records that the memory is mutated outside Rust.

Update the golden header fixture accordingly and fix the optee-utee-systest
C link stub to define both symbols with their C types.

ivila added 2 commits November 9, 2026 14:38
Emit trace_ext_prefix as a sized byte array instead of a slice. A
#[no_mangle] slice static exports a fat pointer, while C declares the
symbol as `extern const char trace_ext_prefix[]`. OP-TEE read the
pointer bytes instead of the prefix, so the TA trace prefix was wrong.

Add a regression test that checks the generated static is an array whose
length includes the trailing NUL, and fix the optee-utee-systest link
stub to define the symbol with its C type.
OP-TEE passes ta_heap to malloc_add_pool(), which writes into the
buffer, even though generated TA code never accesses it directly.
Declare the exported static as `static mut` so the generated code
records that the memory is mutated outside Rust.

Also fix the optee-utee-systest link stub so ta_heap is an array rather
than a void pointer.
@ivila ivila added the bug Something isn't working label Nov 9, 2026
@ivila ivila changed the title Fix/user ta header abi optee-utee-build: fix generated TA header symbol ABI Nov 9, 2026
@ivila
ivila merged commit 89ba88d into apache:main Nov 9, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant