int max_got_offset;
/* For AOT */
+ MonoAssembly *assembly;
+ char *global_prefix;
MonoAotFileInfo aot_info;
const char *jit_got_symbol;
const char *eh_frame_symbol;
LLVMValueRef code_start, code_end;
gboolean has_jitted_code;
+ gboolean static_link;
} MonoLLVMModule;
/*
}
void
-mono_llvm_create_aot_module (const char *global_prefix, gboolean emit_dwarf)
+mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix, gboolean emit_dwarf, gboolean static_link)
{
/* Delete previous module */
if (aot_module.plt_entries)
memset (&aot_module, 0, sizeof (aot_module));
aot_module.module = LLVMModuleCreateWithName ("aot");
+ aot_module.assembly = assembly;
+ aot_module.global_prefix = g_strdup (global_prefix);
aot_module.got_symbol = g_strdup_printf ("%s_llvm_got", global_prefix);
aot_module.eh_frame_symbol = g_strdup_printf ("%s_eh_frame", global_prefix);
aot_module.external_symbols = TRUE;
aot_module.emit_dwarf = emit_dwarf;
+ aot_module.static_link = static_link;
/* The first few entries are reserved */
aot_module.max_got_offset = 16;
type = LLVMArrayType (LLVMInt8Type (), data_len);
d = LLVMAddGlobal (lmodule->module, type, symbol);
+ LLVMSetVisibility (d, LLVMHiddenVisibility);
+ LLVMSetLinkage (d, LLVMInternalLinkage);
LLVMSetInitializer (d, mono_llvm_create_constant_data_array (data, data_len));
mono_llvm_set_is_constant (d);
}
+/* Add a reference to a global defined in JITted code */
+static LLVMValueRef
+AddJitGlobal (MonoLLVMModule *lmodule, LLVMTypeRef type, const char *name)
+{
+ char *s;
+ LLVMValueRef v;
+
+ s = g_strdup_printf ("%s%s", lmodule->global_prefix, name);
+ v = LLVMAddGlobal (lmodule->module, type, s);
+ g_free (s);
+ return v;
+}
+
static void
emit_aot_file_info (MonoLLVMModule *lmodule)
{
LLVMStructSetBody (file_info_type, eltypes, nfields, FALSE);
info_var = LLVMAddGlobal (aot_module.module, file_info_type, "mono_aot_file_info");
+ if (lmodule->static_link) {
+ LLVMSetVisibility (info_var, LLVMHiddenVisibility);
+ LLVMSetLinkage (info_var, LLVMInternalLinkage);
+ }
fields = g_new (LLVMValueRef, nfields);
tindex = 0;
fields [tindex ++] = LLVMConstInt (LLVMInt32Type (), info->version, FALSE);
* for symbols defined in the .s file emitted by the aot compiler.
*/
eltype = eltypes [tindex];
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "jit_got");
- fields [tindex ++] = aot_module.got_var;
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "jit_got");
+ fields [tindex ++] = lmodule->got_var;
/* llc defines this directly */
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, aot_module.eh_frame_symbol);
- if (TRUE || aot_module.has_jitted_code) {
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "jit_code_start");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "jit_code_end");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "method_addresses");
+ fields [tindex ++] = LLVMAddGlobal (lmodule->module, eltype, lmodule->eh_frame_symbol);
+ if (TRUE || lmodule->has_jitted_code) {
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "jit_code_start");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "jit_code_end");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "method_addresses");
} else {
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMGetNamedGlobal (aot_module.module, "assembly_guid");
fields [tindex ++] = LLVMGetNamedGlobal (aot_module.module, "runtime_version");
if (info->trampoline_size [0]) {
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "specific_trampolines");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "static_rgctx_trampolines");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "imt_thunks");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "gsharedvt_arg_trampolines");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "specific_trampolines");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "static_rgctx_trampolines");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "imt_thunks");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "gsharedvt_arg_trampolines");
} else {
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
}
- // FIXME:
- fields [tindex ++] = LLVMConstNull (eltype);
+ if (lmodule->static_link)
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "globals");
+ else
+ fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMGetNamedGlobal (aot_module.module, "assembly_name");
if (TRUE || aot_module.has_jitted_code) {
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "plt");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "plt_end");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "unwind_info");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "unbox_trampolines");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "unbox_trampolines_end");
- fields [tindex ++] = LLVMAddGlobal (aot_module.module, eltype, "unbox_trampoline_addresses");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "plt");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "plt_end");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "unwind_info");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "unbox_trampolines");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "unbox_trampolines_end");
+ fields [tindex ++] = AddJitGlobal (lmodule, eltype, "unbox_trampoline_addresses");
} else {
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
g_assert (tindex == nfields);
LLVMSetInitializer (info_var, LLVMConstNamedStruct (file_info_type, fields, nfields));
+
+ if (lmodule->static_link) {
+ char *s, *p;
+ LLVMValueRef var;
+
+ s = g_strdup_printf ("mono_aot_module_%s_info", lmodule->assembly->aname.name);
+ /* Get rid of characters which cannot occur in symbols */
+ p = s;
+ for (p = s; *p; ++p) {
+ if (!(isalnum (*p) || *p == '_'))
+ *p = '_';
+ }
+ var = LLVMAddGlobal (lmodule->module, LLVMPointerType (LLVMInt8Type (), 0), s);
+ g_free (s);
+ LLVMSetInitializer (var, LLVMConstBitCast (LLVMGetNamedGlobal (aot_module.module, "mono_aot_file_info"), LLVMPointerType (LLVMInt8Type (), 0)));
+ LLVMSetLinkage (var, LLVMExternalLinkage);
+ }
}
/*