[PATCH] [OCaml] introduce link_gc_components

Ramkumar Ramachandra artagnon at gmail.com
Wed Dec 24 17:38:26 PST 2014


Hi whitequark,

For some reason, set_gc (Some "shadow-stack") f works fine in a
program that doesn't call link_gc_components. The initialization is
done without us asking for it. What's happening?

http://reviews.llvm.org/D6779

Files:
  bindings/ocaml/llvm/llvm.ml
  bindings/ocaml/llvm/llvm.mli
  bindings/ocaml/llvm/llvm_ocaml.c
  include/llvm-c/Core.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/LinkGCComponents.cpp

Index: bindings/ocaml/llvm/llvm.ml
===================================================================
--- bindings/ocaml/llvm/llvm.ml
+++ bindings/ocaml/llvm/llvm.ml
@@ -683,6 +683,7 @@
 external function_call_conv : llvalue -> int = "llvm_function_call_conv"
 external set_function_call_conv : int -> llvalue -> unit
                                 = "llvm_set_function_call_conv"
+external link_gc_components : unit -> unit = "llvm_link_gc_components"
 external gc : llvalue -> string option = "llvm_gc"
 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
 external function_begin : llmodule -> (llmodule, llvalue) llpos
Index: bindings/ocaml/llvm/llvm.mli
===================================================================
--- bindings/ocaml/llvm/llvm.mli
+++ bindings/ocaml/llvm/llvm.mli
@@ -1498,6 +1498,12 @@
     See the method [llvm::Function::setCallingConv]. *)
 val set_function_call_conv : int -> llvalue -> unit
 
+(** [link_gc_components] links up up CodeGen and AsmWriter components
+    related to GC. After a call to this function, ErlangGC, OCamlGC,
+    and ShadowStackGC will be accessible. See the method
+    [LLVMLinkGCComponents]. *)
+val link_gc_components : unit -> unit
+
 (** [gc f] returns [Some name] if the function [f] has a garbage
     collection algorithm specified and [None] otherwise.
     See the method [llvm::Function::getGC]. *)
Index: bindings/ocaml/llvm/llvm_ocaml.c
===================================================================
--- bindings/ocaml/llvm/llvm_ocaml.c
+++ bindings/ocaml/llvm/llvm_ocaml.c
@@ -1235,6 +1235,12 @@
   }
 }
 
+/* unit -> unit */
+CAMLprim value llvm_link_gc_components(value Unit) {
+  LLVMLinkGCComponents();
+  return Val_unit;
+}
+
 /* string option -> llvalue -> unit */
 CAMLprim value llvm_set_gc(value GC, LLVMValueRef Fn) {
   LLVMSetGC(Fn, GC == Val_int(0)? 0 : String_val(Field(GC, 0)));
Index: include/llvm-c/Core.h
===================================================================
--- include/llvm-c/Core.h
+++ include/llvm-c/Core.h
@@ -1906,6 +1906,14 @@
 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
 
 /**
+ * Link the Codegen and AsmWriter components related to GC. After a
+ * call to this function, ErlangGC, OCamlGC and ShadowStackGC will be
+ * accessible.
+ *
+ */
+void LLVMLinkGCComponents(void);
+
+/**
  * Obtain the name of the garbage collector to use during code
  * generation.
  *
Index: lib/CodeGen/CMakeLists.txt
===================================================================
--- lib/CodeGen/CMakeLists.txt
+++ lib/CodeGen/CMakeLists.txt
@@ -32,6 +32,7 @@
   LLVMTargetMachine.cpp
   LatencyPriorityQueue.cpp
   LexicalScopes.cpp
+  LinkComponents.cpp
   LiveDebugVariables.cpp
   LiveInterval.cpp
   LiveIntervalAnalysis.cpp
Index: lib/CodeGen/LinkGCComponents.cpp
===================================================================
--- /dev/null
+++ lib/CodeGen/LinkGCComponents.cpp
@@ -0,0 +1,4 @@
+#include "llvm/CodeGen/LinkAllCodegenComponents.h"
+#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
+
+void LLVMLinkGCComponents(void) {}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6779.17629.patch
Type: text/x-patch
Size: 3095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141225/d546bcf2/attachment.bin>


More information about the llvm-commits mailing list