[all-commits] [llvm/llvm-project] afd205: MachineFunction: -fsanitize={function, kcfi}: ensur...

Fangrui Song via All-commits all-commits at lists.llvm.org
Fri Jun 30 09:13:34 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: afd20587f9952654a9a9ec427052220b5e3a6982
      https://github.com/llvm/llvm-project/commit/afd20587f9952654a9a9ec427052220b5e3a6982
  Author: Fangrui Song <i at maskray.me>
  Date:   2023-06-30 (Fri, 30 Jun 2023)

  Changed paths:
    M llvm/lib/CodeGen/MachineFunction.cpp
    A llvm/test/CodeGen/ARM/func-sanitizer.ll
    A llvm/test/CodeGen/ARM/kcfi.ll
    M llvm/test/CodeGen/RISCV/kcfi-patchable-function-prefix.ll

  Log Message:
  -----------
  MachineFunction: -fsanitize={function,kcfi}: ensure 4-byte alignment

Fix https://github.com/llvm/llvm-project/issues/63579
```
% cat a.c
void foo() {}
% clang --target=arm-none-eabi -mthumb -mno-unaligned-access -fsanitize=kcfi a.c -S -o - | grep p2align
        .p2align        1
% clang --target=armv6m-none-eabi -fsanitize=function a.c -S -o - | grep p2align
        .p2align        1
```

Ensure that -fsanitize={function,kcfi} instrumented functions are aligned by at
least 4, so that loading the type hash before the function label will not cause
a misaligned access. This is especially important for -mno-unaligned-access
configurations that don't set `setMinFunctionAlignment` to 4 or greater.

With this patch, the generated assembly for the examples above will contain `.p2align 2`
before the type hash.

If `__attribute__((aligned(N)))` or `-falign-functions=N` is specified, the
larger alignment will be used.

Reviewed By: simon_tatham, samitolvanen

Differential Revision: https://reviews.llvm.org/D154125




More information about the All-commits mailing list