[llvm] fdd0d53 - cmse: emit `__acle_se_` symbol for aliases to entry functions (#162109)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 8 09:26:25 PST 2025


Author: Folkert de Vries
Date: 2025-12-08T17:26:21Z
New Revision: fdd0d53430e87b6ee792735ee714e756235978ba

URL: https://github.com/llvm/llvm-project/commit/fdd0d53430e87b6ee792735ee714e756235978ba
DIFF: https://github.com/llvm/llvm-project/commit/fdd0d53430e87b6ee792735ee714e756235978ba.diff

LOG: cmse: emit `__acle_se_` symbol for aliases to entry functions (#162109)

Emitting the symbol in `emitGlobalAlias` seemed most efficient,
otherwise I think you'd have to traverse all aliases. I have verified
that the additional symbol is picked up by `arm-none-eabi-ld` and
correctly generates an entry in `veneers.o`.

Fixes #162084

Added: 
    llvm/test/CodeGen/ARM/cmse-entry-alias.ll

Modified: 
    llvm/lib/Target/ARM/ARMAsmPrinter.cpp
    llvm/lib/Target/ARM/ARMAsmPrinter.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index c1dd2e5066b6d..458a3f0ced070 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -103,6 +103,35 @@ void ARMAsmPrinter::emitXXStructor(const DataLayout &DL, const Constant *CV) {
   OutStreamer->emitValue(E, Size);
 }
 
+// An alias to a cmse entry function should also emit a `__acle_se_` symbol.
+void ARMAsmPrinter::emitCMSEVeneerAlias(const GlobalAlias &GA) {
+  const Function *BaseFn = dyn_cast_or_null<Function>(GA.getAliaseeObject());
+  if (!BaseFn || !BaseFn->hasFnAttribute("cmse_nonsecure_entry"))
+    return;
+
+  MCSymbol *AliasSym = getSymbol(&GA);
+  MCSymbol *FnSym = getSymbol(BaseFn);
+
+  MCSymbol *SEAliasSym =
+      OutContext.getOrCreateSymbol(Twine("__acle_se_") + AliasSym->getName());
+  MCSymbol *SEBaseSym =
+      OutContext.getOrCreateSymbol(Twine("__acle_se_") + FnSym->getName());
+
+  // Mirror alias linkage/visibility onto the veneer-alias symbol.
+  emitLinkage(&GA, SEAliasSym);
+  OutStreamer->emitSymbolAttribute(SEAliasSym, MCSA_ELF_TypeFunction);
+  emitVisibility(SEAliasSym, GA.getVisibility());
+
+  // emit "__acle_se_<alias> = __acle_se_<aliasee>"
+  const MCExpr *SEExpr = MCSymbolRefExpr::create(SEBaseSym, OutContext);
+  OutStreamer->emitAssignment(SEAliasSym, SEExpr);
+}
+
+void ARMAsmPrinter::emitGlobalAlias(const Module &M, const GlobalAlias &GA) {
+  AsmPrinter::emitGlobalAlias(M, GA);
+  emitCMSEVeneerAlias(GA);
+}
+
 void ARMAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
   if (PromotedGlobals.count(GV))
     // The global was promoted into a constant pool. It should not be emitted.

diff  --git a/llvm/lib/Target/ARM/ARMAsmPrinter.h b/llvm/lib/Target/ARM/ARMAsmPrinter.h
index b9cd3c2613bc8..12e20d758e415 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.h
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.h
@@ -104,6 +104,7 @@ class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
   void emitEndOfAsmFile(Module &M) override;
   void emitXXStructor(const DataLayout &DL, const Constant *CV) override;
   void emitGlobalVariable(const GlobalVariable *GV) override;
+  void emitGlobalAlias(const Module &M, const GlobalAlias &GA) override;
 
   MCSymbol *GetCPISymbol(unsigned CPID) const override;
 
@@ -159,6 +160,8 @@ class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
 
   MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
 
+  void emitCMSEVeneerAlias(const GlobalAlias &GA);
+
 public:
   /// EmitMachineConstantPoolValue - Print a machine constantpool value to
   /// the .s file.

diff  --git a/llvm/test/CodeGen/ARM/cmse-entry-alias.ll b/llvm/test/CodeGen/ARM/cmse-entry-alias.ll
new file mode 100644
index 0000000000000..2949f1e21a4b4
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/cmse-entry-alias.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=thumbv8.1m.main %s -o - | FileCheck %s
+
+ at foo = unnamed_addr alias void (), ptr @bar
+
+; CHECK: .globl bar 
+; CHECK: .globl __acle_se_bar @ @bar 
+; CHECK: .globl foo 
+; CHECK: foo = bar
+; CHECK: __acle_se_foo = __acle_se_bar
+
+define dso_local void @bar() unnamed_addr #0 {
+start:
+  ret void
+}
+
+attributes #0 = { nounwind "cmse_nonsecure_entry" }
+


        


More information about the llvm-commits mailing list