[PATCH] D151308: -fsanitize=function: fix alignment fault on Arm targets.

Peter Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 24 03:00:28 PDT 2023


peter.smith added a comment.

This looks good to me. Will be worth waiting for a day to give the US time zone time to leave any comments.

I note that this is also broken in -fsanitize=kcfi [*] (https://reviews.llvm.org/D135411) although fixing that is a separate patch. Would you be able to raise a github issue to cover that?

As an end-to-end example for:

  typedef int Fptr(void);
  
  // pf could be Arm (bit 0 clear) or Thumb (bit 0 set)
  int f(Fptr* pf) {
    return pf();
  }

This generates:

  f:
          .fnstart
  @ %bb.0:                                @ %entry
          push    {r4, lr}
          mov     r3, r0
          bic     r0, r0, #1
          movw    r2, #51966
          ldr     r1, [r0, #-8]
          movt    r2, #49413
          cmp     r1, r2
          bne     .LBB0_2
  @ %bb.1:                                @ %typecheck
          ldr     r0, [r0, #-4]
          movw    r1, #50598
          movt    r1, #14001
          cmp     r0, r1
          bne     .LBB0_3
  .LBB0_2:                                @ %cont1
          pop.w   {r4, lr}
          bx      r3

Which gets the address of the signature and type correct, while preserving the thumb bit on the register used for the indirect branch.

-fsanitize=kcfi output is not correct for a Thumb destination:

  f:
          .fnstart
          // r0 will have thumb bit set if destination thumb
          ldr     r1, [r0, #-4]
          movw    r2, #50598
          movt    r2, #14001
          cmp     r1, r2
          bne     .LBB0_2
          bx      r0
  .LBB0_2:
          .inst   0xe7ffdefe


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151308/new/

https://reviews.llvm.org/D151308



More information about the cfe-commits mailing list