[PATCH] Expose llvm::linkShadowStackGC() via C bindings

Mukul Sabharwal mjsabby at gmail.com
Wed Apr 1 15:31:03 PDT 2015


Hi reames,

An LLVMSharp user filed a bug report (https://github.com/mjsabby/LLVMSharp/issues/3) that using the library they were unable to call SetGC("shadow-stack") on a function and then subsequently ask MCJIT to finalize the object containing the function.

They also created an LLVM bug report (https://llvm.org/bugs/show_bug.cgi?id=23095) that demonstrates the problem.

I have investigated the root cause for this and it is because LLVMSharp and other C binding users do not have access to llvm::linkShadowStackGC (in addition to other GCs defined in llvm/include/llvm/CodeGen/GCs.h) which GC clients of the C++ API would need to call in order to successfully complete this scenario.

I'm proposing to expose LLVMLinkShadowStackGC via the C bindings. The ShadowStackGC is very useful functionality that is referenced in the official documentation and likely to be beneficial to many users.

I'm consciously choosing not to link other GCs, but maybe I should? Let me know as part of the review feedback if I should also expose other GCs (currently StatepointExample, Erlang, and Ocaml)

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D8788

Files:
  include/llvm-c/Core.h
  lib/IR/Core.cpp

Index: include/llvm-c/Core.h
===================================================================
--- include/llvm-c/Core.h
+++ include/llvm-c/Core.h
@@ -1921,6 +1921,13 @@
 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
 
 /**
+* Link the Shadow Stack GC
+*
+* @see llvm::linkShadowStackGC()
+*/
+void LLVMLinkShadowStackGC();
+
+/**
  * Add an attribute to a function.
  *
  * @see llvm::Function::addAttribute()
Index: lib/IR/Core.cpp
===================================================================
--- lib/IR/Core.cpp
+++ lib/IR/Core.cpp
@@ -14,6 +14,7 @@
 
 #include "llvm-c/Core.h"
 #include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/CodeGen/GCs.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/CallSite.h"
 #include "llvm/IR/Constants.h"
@@ -1709,6 +1710,10 @@
     F->clearGC();
 }
 
+void LLVMLinkShadowStackGC() {
+  llvm::linkShadowStackGC();
+}
+
 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
   Function *Func = unwrap<Function>(Fn);
   const AttributeSet PAL = Func->getAttributes();

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8788.23092.patch
Type: text/x-patch
Size: 1032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150401/2a455bdc/attachment.bin>


More information about the llvm-commits mailing list