Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions llvm/lib/Target/ARM/ARMAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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);
ARMAsmPrinter::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.
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/ARM/ARMAsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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;

Expand Down Expand Up @@ -152,6 +153,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.
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/ARM/cmse-entry-alias.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; RUN: llc -mtriple=thumbv8.1m.main %s -o - | FileCheck %s

@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" }