[PATCH] D15215: Emit function alias to data as a function symbol

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 3 15:49:00 PST 2015


eugenis created this revision.
eugenis added reviewers: pcc, dblaikie.
eugenis added a subscriber: llvm-commits.
eugenis set the repository for this revision to rL LLVM.

SFI emits jump slots for indirect functions as a byte array constant, and declares function-typed aliases to these constants.
This change fixes AsmPrinter to emit these aliases as function symbols, and not data symbols.

It does it by looking at the pointee type of the alias, which feels like the wrong thing to do. Does anyone have any better ideas?


Repository:
  rL LLVM

http://reviews.llvm.org/D15215

Files:
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  test/CodeGen/Generic/function-alias.ll

Index: test/CodeGen/Generic/function-alias.ll
===================================================================
--- /dev/null
+++ test/CodeGen/Generic/function-alias.ll
@@ -0,0 +1,12 @@
+; RUN: llc < %s | FileCheck
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; "data" constant
+ at 0 = private constant <{ i8, i8 }> <{i8 15, i8 11}>, section ".text"
+
+; function-typed alias
+ at ud2 = alias void (), bitcast (<{ i8, i8 }>* @0 to void ()*)
+
+; Check that "ud2" is emitted as a function symbol.
+; CHECK: .type{{.*}}ud2, at function
Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1187,6 +1187,13 @@
     else
       assert(Alias.hasLocalLinkage() && "Invalid alias linkage");
 
+    // If the alias has a function type and the aliasee is not a function,
+    // explicitly switch the symbol type to function.
+    if (Alias.getType()->isPointerTy() &&
+        Alias.getType()->getPointerElementType()->isFunctionTy() &&
+        !isa<Function>(Alias.getAliasee()))
+      OutStreamer->EmitSymbolAttribute(Name, MCSA_ELF_TypeFunction);
+
     EmitVisibility(Name, Alias.getVisibility());
 
     // Emit the directives as assignments aka .set:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15215.41814.patch
Type: text/x-patch
Size: 1355 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151203/730c9064/attachment.bin>


More information about the llvm-commits mailing list