mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 08:56:07 +00:00

Functions created with createWithDefaultAttr() need to have the correct target-{cpu,features} attributes to avoid miscompilations such as using the wrong relocation type to access globals (missing tagged-globals feature), clobbering registers specified via -ffixed-* (missing reserve-* feature), and so on. There's already a number of attributes copied from the module flags onto functions created by createWithDefaultAttr(). I don't think module flags are the right choice for the target attributes because we don't need the conflict resolution logic between modules with different target attributes, nor does it seem sensible to add it: there's no unambiguously "correct" set of target attributes when merging two modules with different attributes, and nor should there be; it's perfectly valid for two modules to be compiled with different target attributes, that's the whole reason why they are per-function. This also implies that it's unnecessary to serialize the attributes in bitcode, which implies that they shouldn't be stored on the module. We can also observe that for the most part, createWithDefaultAttr() is called from compiler passes such as sanitizers, coverage and profiling passes that are part of the compile time pipeline, not the LTO pipeline. This hints at a solution: we need to store the attributes in a non-serialized location associated with the ambient compilation context. Therefore in this patch I elected to store the attributes on the LLVMContext. There are calls to createWithDefaultAttr() in the NVPTX and AMDGPU backends, and those calls would happen at LTO time. For those callers, the bug still potentially exists and it would be necessary to refactor them to create the functions at compile time if this issue is relevant on those platforms. Fixes #93633. Reviewers: fmayer, MaskRay, eugenis Reviewed By: MaskRay Pull Request: https://github.com/llvm/llvm-project/pull/96721
20 lines
1.1 KiB
C++
20 lines
1.1 KiB
C++
/// -mframe-pointer=none sets the module flag "frame-pointer" (merge behavior: max).
|
|
/// asan synthesized ctor/dtor get the "frame-pointer" function attribute if not zero (default).
|
|
// RUN: %clang_cc1 -emit-llvm -fsanitize=address -mframe-pointer=none %s -o - | FileCheck %s --check-prefix=NONE
|
|
// RUN: %clang_cc1 -emit-llvm -fsanitize=address -mframe-pointer=non-leaf %s -o - | FileCheck %s --check-prefix=NONLEAF
|
|
// RUN: %clang_cc1 -emit-llvm -fsanitize=address -mframe-pointer=all %s -o - | FileCheck %s --check-prefix=ALL
|
|
|
|
int global;
|
|
|
|
// NONE: define internal void @asan.module_ctor() #[[#ATTR:]] {
|
|
// NONE: define internal void @asan.module_dtor() #[[#ATTR]] {
|
|
// NONE: attributes #[[#ATTR]] = { nounwind
|
|
|
|
// NONLEAF: define internal void @asan.module_ctor() #[[#ATTR:]] {
|
|
// NONLEAF: define internal void @asan.module_dtor() #[[#ATTR]] {
|
|
// NONLEAF: attributes #[[#ATTR]] = { nounwind "frame-pointer"="non-leaf"
|
|
|
|
// ALL: define internal void @asan.module_ctor() #[[#ATTR:]] {
|
|
// ALL: define internal void @asan.module_dtor() #[[#ATTR]] {
|
|
// ALL: attributes #[[#ATTR]] = { nounwind "frame-pointer"="all"
|