Skip to content

[PAC] arm64e platform does not set ptrauth attributes properly #167781

@asl

Description

@asl

Consider the following code:

int f() {
  thread_local int j = 0;
  j++;
  return j;
}

Running clang++ tls.cpp -S -O1 -target arm64e-apple-darwin yields:

Lloh0:
        adrp    x0, __ZZ1fvE1j@TLVPPAGE
Lloh1:
        ldr     x0, [x0, __ZZ1fvE1j@TLVPPAGEOFF]
        ldr     x8, [x0]
        blr     x8
        ldr     w8, [x0]
        add     w8, w8, #1
        str     w8, [x0]
        mov     x0, x8
        ldp     x29, x30, [sp], #16             ; 16-byte Folded Reload
        ret
        .loh AdrpLdr    Lloh0, Lloh1
        .cfi_endproc

Note that TLS resolver call is not signed.

And indeed, there are no ptrauth-calls attribute:

define noundef range(i32 -2147483647, -2147483648) i32 @_Z1fv() local_unnamed_addr #0 {
entry:
  %0 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @_ZZ1fvE1j)
  %1 = load i32, ptr %0, align 4, !tbaa !5
  %inc = add nsw i32 %1, 1
  store i32 %inc, ptr %0, align 4, !tbaa !5
  ret i32 %inc
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind ssp willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable(sync) "aarch64-jump-table-hardening" "frame-pointer"="non-leaf" "no-tr
apping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+altnzcv,+ccdp,+ccidx,+complxnum,+crc,+dit,+dotprod,+flagm,+fp-armv8,+fp16fml,+fptoint,+fullfp16,+jsconv,+lse,
+neon,+pauth,+perfmon,+predres,+ras,+rcpc,+rdm,+sb,+sha2,+sha3,+specrestrict,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a,+zcm,+zcz" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

Explicit options seems to be not accepted by driver:

clang++ tls.cpp -S  -O1 -target arm64e-apple-darwin -S -fptrauth-calls
clang++: error: unsupported option '-fptrauth-calls' for target 'arm64e-apple-darwin'

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:driver'clang' and 'clang++' user-facing binaries. Not 'clang-cl'invalidResolved as invalid, i.e. not a bugplatform:macos

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions