aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorSami Tolvanen <samitolvanen@google.com>2025-04-02 14:53:55 -0700
committerGitHub <noreply@github.com>2025-04-02 21:53:55 +0000
commitacc6bcdc504ad2e8c09a628dc18de0067f7344b8 (patch)
tree7db9e54e202b3cad638118545caa9c996cafae43 /clang/lib/CodeGen/CodeGenFunction.cpp
parent76fa9530c9ac7f81a49b840556f51f4838efbfe1 (diff)
downloadllvm-acc6bcdc504ad2e8c09a628dc18de0067f7344b8.zip
llvm-acc6bcdc504ad2e8c09a628dc18de0067f7344b8.tar.gz
llvm-acc6bcdc504ad2e8c09a628dc18de0067f7344b8.tar.bz2
Support alternative sections for patchable function entries (#131230)
With -fpatchable-function-entry (or the patchable_function_entry function attribute), we emit records of patchable entry locations to the __patchable_function_entries section. Add an additional parameter to the command line option that allows one to specify a different default section name for the records, and an identical parameter to the function attribute that allows one to override the section used. The main use case for this change is the Linux kernel using prefix NOPs for ftrace, and thus depending on__patchable_function_entries to locate traceable functions. Functions that are not traceable currently disable entry NOPs using the function attribute, but this creates a compatibility issue with -fsanitize=kcfi, which expects all indirectly callable functions to have a type hash prefix at the same offset from the function entry. Adding a section parameter would allow the kernel to distinguish between traceable and non-traceable functions by adding entry records to separate sections while maintaining a stable function prefix layout for all functions. LKML discussion: https://lore.kernel.org/lkml/Y1QEzk%2FA41PKLEPe@hirez.programming.kicks-ass.net/
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index dcf523f..b55003b 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -965,18 +965,24 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
}
unsigned Count, Offset;
+ StringRef Section;
if (const auto *Attr =
D ? D->getAttr<PatchableFunctionEntryAttr>() : nullptr) {
Count = Attr->getCount();
Offset = Attr->getOffset();
+ Section = Attr->getSection();
} else {
Count = CGM.getCodeGenOpts().PatchableFunctionEntryCount;
Offset = CGM.getCodeGenOpts().PatchableFunctionEntryOffset;
}
+ if (Section.empty())
+ Section = CGM.getCodeGenOpts().PatchableFunctionEntrySection;
if (Count && Offset <= Count) {
Fn->addFnAttr("patchable-function-entry", std::to_string(Count - Offset));
if (Offset)
Fn->addFnAttr("patchable-function-prefix", std::to_string(Offset));
+ if (!Section.empty())
+ Fn->addFnAttr("patchable-function-entry-section", Section);
}
// Instruct that functions for COFF/CodeView targets should start with a
// patchable instruction, but only on x86/x64. Don't forward this to ARM/ARM64