Index: bindings/ocaml/CMakeLists.txt =================================================================== --- bindings/ocaml/CMakeLists.txt +++ bindings/ocaml/CMakeLists.txt @@ -4,6 +4,7 @@ add_subdirectory(backends) add_subdirectory(bitreader) add_subdirectory(bitwriter) +add_subdirectory(gc) add_subdirectory(irreader) add_subdirectory(linker) add_subdirectory(target) Index: bindings/ocaml/Makefile =================================================================== --- bindings/ocaml/Makefile +++ bindings/ocaml/Makefile @@ -9,7 +9,7 @@ LEVEL := ../.. DIRS = llvm bitreader bitwriter irreader analysis target executionengine \ - transforms linker backends all_backends + transforms linker backends all_backends gc ExtraMakefiles = $(PROJ_OBJ_DIR)/Makefile.ocaml ocamldoc: Index: bindings/ocaml/gc/CMakeLists.txt =================================================================== --- /dev/null +++ bindings/ocaml/gc/CMakeLists.txt @@ -0,0 +1,5 @@ +add_ocaml_library(llvm_gc + OCAML llvm_gc + OCAMLDEP llvm + C gc_ocaml + LLVM codegen) Index: bindings/ocaml/gc/Makefile =================================================================== --- /dev/null +++ bindings/ocaml/gc/Makefile @@ -0,0 +1,15 @@ +##===- bindings/ocaml/gc/Makefile --------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL := ../../.. +LIBRARYNAME := llvm_gc +UsedComponents := codegen +UsedOcamlInterfaces := llvm + +include ../Makefile.ocaml Index: bindings/ocaml/gc/gc_ocaml.c =================================================================== --- /dev/null +++ bindings/ocaml/gc/gc_ocaml.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include "llvm-c/Core.h" +#include "caml/alloc.h" +#include "caml/custom.h" +#include "caml/fail.h" +#include "caml/memory.h" +#include "caml/callback.h" + +/* unit -> unit */ +CAMLprim value llvm_link_gc_components(value Unit) { + LLVMLinkGCComponents(); + return Val_unit; +} Index: bindings/ocaml/gc/llvm_gc.ml =================================================================== --- /dev/null +++ bindings/ocaml/gc/llvm_gc.ml @@ -0,0 +1 @@ +external link_gc_components : unit -> unit = "llvm_link_gc_components" Index: bindings/ocaml/gc/llvm_gc.mli =================================================================== --- /dev/null +++ bindings/ocaml/gc/llvm_gc.mli @@ -0,0 +1,5 @@ +(** [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 Index: bindings/ocaml/llvm/META.llvm.in =================================================================== --- bindings/ocaml/llvm/META.llvm.in +++ bindings/ocaml/llvm/META.llvm.in @@ -37,6 +37,14 @@ archive(native) = "llvm_executionengine.cmxa" ) +package "gc" ( + requires = "llvm" + version = "@PACKAGE_VERSION@" + description = "GC support for LLVM JIT" + archive(byte) = "llvm_gc.cma" + archive(native) = "llvm_gc.cmxa" +) + package "ipo" ( requires = "llvm" version = "@PACKAGE_VERSION@" 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 + LinkGCComponents.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" + +extern "C" void LLVMLinkGCComponents() {}