summaryrefslogtreecommitdiff
path: root/mjit_worker.c
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-12 15:00:03 (GMT)
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-12 15:00:03 (GMT)
commit7e478ba366d268eb1324e8f894f195b317538b00 (patch)
treeef28639c564c86bdf5f65f63b3358c1fe9c4339b /mjit_worker.c
parentbd789fa5909a64eede6dbf33798a41849e96722c (diff)
mjit_worker.c: lazily delete so file
on ELF. I need symbol name and line number to lazily create program counter for optimization on ELF binary. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'mjit_worker.c')
-rw-r--r--mjit_worker.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/mjit_worker.c b/mjit_worker.c
index fb46df7..6a550e7 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -133,7 +133,7 @@ struct rb_mjit_unit {
/* This value is always set for `compact_all_jit_code`. Also used for lazy deletion. */
char *o_file;
#endif
-#ifdef _WIN32
+#if defined(_WIN32) || defined(USE_ELF)
/* DLL cannot be removed while loaded on Windows. If this is set, it'll be lazily deleted. */
char *so_file;
#endif
@@ -399,7 +399,7 @@ clean_object_files(struct rb_mjit_unit *unit)
}
#endif
-#ifdef _WIN32
+#if defined(_WIN32) || defined(USE_ELF)
if (unit->so_file) {
char *so_file = unit->so_file;
@@ -671,6 +671,20 @@ exec_process(const char *path, char *const argv[])
return exit_code;
}
+static void
+remove_so_file(const char *so_file, struct rb_mjit_unit *unit)
+{
+#if defined(_WIN32) || defined(USE_ELF)
+ /* Windows can't remove files while it's used. With USE_ELF, we use it to get a line
+ number and symbol name on addr2line for debugging and future optimization. */
+ unit->so_file = strdup(so_file); /* lazily delete on `clean_object_files()` */
+ if (unit->so_file == NULL)
+ mjit_warning("failed to allocate memory to lazily remove '%s': %s", so_file, strerror(errno));
+#else
+ remove_file(so_file);
+#endif
+}
+
#define append_str2(p, str, len) ((char *)memcpy((p), str, (len))+(len))
#define append_str(p, str) append_str2(p, str, sizeof(str)-1)
#define append_lit(p, str) append_str2(p, str, rb_strlen_lit(str))
@@ -893,15 +907,8 @@ compact_all_jit_code(void)
node->unit = unit;
add_to_list(node, &compact_units);
- if (!mjit_opts.save_temps) {
-# ifdef _WIN32
- unit->so_file = strdup(so_file); /* lazily delete on `clean_object_files()` */
- if (unit->so_file == NULL)
- mjit_warning("failed to allocate memory to lazily remove '%s': %s", so_file, strerror(errno));
-# else
- remove_file(so_file);
-# endif
- }
+ if (!mjit_opts.save_temps)
+ remove_so_file(so_file, unit);
CRITICAL_SECTION_START(3, "in compact_all_jit_code to read list");
for (node = active_units.head; node != NULL; node = node->next) {
@@ -1114,15 +1121,8 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
}
func = load_func_from_so(so_file, funcname, unit);
- if (!mjit_opts.save_temps) {
-#ifdef _WIN32
- unit->so_file = strdup(so_file); /* lazily delete on `clean_object_files()` */
- if (unit->so_file == NULL)
- mjit_warning("failed to allocate memory to lazily remove '%s': %s", so_file, strerror(errno));
-#else
- remove_file(so_file);
-#endif
- }
+ if (!mjit_opts.save_temps)
+ remove_so_file(so_file, unit);
if ((uintptr_t)func > (uintptr_t)LAST_JIT_ISEQ_FUNC) {
struct rb_mjit_unit_node *node = create_list_node(unit);