[all-commits] [llvm/llvm-project] 148d90: [CodeGen] Set attributes on resolvers emitted afte...

Fangrui Song via All-commits all-commits at lists.llvm.org
Mon Jul 15 11:27:23 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 148d90729e9fa132f170ba0627bcfb9ee90a0f38
      https://github.com/llvm/llvm-project/commit/148d90729e9fa132f170ba0627bcfb9ee90a0f38
  Author: Fangrui Song <i at maskray.me>
  Date:   2024-07-15 (Mon, 15 Jul 2024)

  Changed paths:
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/test/CodeGen/ifunc.c
    M clang/test/CodeGen/kcfi.c

  Log Message:
  -----------
  [CodeGen] Set attributes on resolvers emitted after ifuncs

Visiting the ifunc calls `GetOrCreateLLVMFunction` with
`NotForDefinition` while visiting the resolver calls
`GetOrCreateLLVMFunction` with `ForDefinition`.

When an ifunc is emitted before its resolver, the `ForDefinition` call
does not call `SetFunctionAttributes`, because the function prematurely
returns due to `(Entry->getValueType() == Ty)` and
`llvm::GlobalIFunc::getResolverFunctionType(DeclTy)`.

This leads to missing `!kcfi_type` with -fsanitize=kcfi.

```
extern void ifunc0(void) __attribute__ ((ifunc("resolver0")));
void *resolver0(void) { return 0; } // SetFunctionAttributes not called

extern void ifunc1(void) __attribute__ ((ifunc("resolver1")));
static void *resolver1(void) { return 0; } // SetFunctionAttributes not called

extern void ifunc2(void) __attribute__ ((ifunc("resolver2")));
static void *resolver2(void*) { return 0; }
```

Ensure `SetFunctionAttributes` is called by calling
`GetOrCreateLLVMFunction` with a dummy non-function type. Now that the
`F->takeName(Entry)` code path may be taken, the
`DisableSanitizerInstrumentation` code
(https://reviews.llvm.org/D150262) should be moved to `checkAliases`,
when the resolver function is finalized.

Pull Request: https://github.com/llvm/llvm-project/pull/98832



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list