Skip to content

Commit 794a26c

Browse files
committed
Make loading fail if it detects a buildid collision
1 parent 57a1d3a commit 794a26c

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

src/julia_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ void push_edge(jl_array_t *list, jl_value_t *invokesig, jl_code_instance_t *call
756756
void jl_mi_done_backedges(jl_method_instance_t *mi JL_PROPAGATES_ROOT, uint8_t old_flags);
757757

758758
JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_t* root);
759-
void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots);
759+
int jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots);
760760
int get_root_reference(rle_reference *rr, jl_method_t *m, size_t i) JL_NOTSAFEPOINT;
761761
jl_value_t *lookup_root(jl_method_t *m, uint64_t key, int index) JL_NOTSAFEPOINT;
762762
int nroots_with_key(jl_method_t *m, uint64_t key) JL_NOTSAFEPOINT;

src/method.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,14 +1521,22 @@ static uint64_t current_root_id(jl_array_t *root_blocks)
15211521
}
15221522

15231523
// Add a new block of `len` roots with key `modid` (module id)
1524-
static void add_root_block(jl_array_t *root_blocks, uint64_t modid, size_t len)
1524+
static int add_root_block(jl_array_t *root_blocks, uint64_t modid, size_t len)
15251525
{
15261526
assert(jl_is_array(root_blocks));
15271527
jl_array_grow_end(root_blocks, 2);
15281528
uint64_t *blocks = jl_array_data(root_blocks, uint64_t);
15291529
int nx2 = jl_array_nrows(root_blocks);
1530+
int failed = 0;
1531+
for (size_t i = 0; i < nx2; i+=2) {
1532+
if (blocks[i] == modid) {
1533+
// found duplicate block
1534+
failed = -1;
1535+
}
1536+
}
15301537
blocks[nx2-2] = modid;
15311538
blocks[nx2-1] = len;
1539+
return failed;
15321540
}
15331541

15341542
// Allocate storage for roots
@@ -1555,22 +1563,26 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_
15551563
}
15561564
assert(jl_is_method(m));
15571565
prepare_method_for_roots(m, modid);
1558-
if (current_root_id(m->root_blocks) != modid)
1559-
add_root_block(m->root_blocks, modid, jl_array_nrows(m->roots));
1566+
if (current_root_id(m->root_blocks) != modid) {
1567+
int failed = add_root_block(m->root_blocks, modid, jl_array_nrows(m->roots));
1568+
assert(failed == 0);
1569+
(void)failed;
1570+
}
15601571
jl_array_ptr_1d_push(m->roots, root);
15611572
JL_GC_POP();
15621573
}
15631574

15641575
// Add a list of roots with key `modid` to a method
1565-
void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots)
1576+
int jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots)
15661577
{
15671578
JL_GC_PUSH2(&m, &roots);
15681579
assert(jl_is_method(m));
15691580
assert(jl_is_array(roots));
15701581
prepare_method_for_roots(m, modid);
1571-
add_root_block(m->root_blocks, modid, jl_array_nrows(m->roots));
1582+
int failed = add_root_block(m->root_blocks, modid, jl_array_nrows(m->roots));
15721583
jl_array_ptr_1d_append(m->roots, roots);
15731584
JL_GC_POP();
1585+
return failed;
15741586
}
15751587

15761588
// given the absolute index i of a root, retrieve its relocatable reference

src/staticdata.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4410,7 +4410,11 @@ static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *im
44104410
JL_SIGATOMIC_END();
44114411

44124412
// Add roots to methods
4413-
jl_copy_roots(method_roots_list, jl_worklist_key((jl_array_t*)restored));
4413+
int failed = jl_copy_roots(method_roots_list, jl_worklist_key((jl_array_t*)restored));
4414+
if (failed != 0) {
4415+
jl_printf(JL_STDERR, "Error copying roots to methods from Module: %s\n", pkgname);
4416+
abort();
4417+
}
44144418
// Insert method extensions and handle edges
44154419
int new_methods = jl_array_nrows(extext_methods) > 0;
44164420
if (!new_methods) {

src/staticdata_utils.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,17 +736,19 @@ static void jl_activate_methods(jl_array_t *external, jl_array_t *internal, size
736736
}
737737
}
738738

739-
static void jl_copy_roots(jl_array_t *method_roots_list, uint64_t key)
739+
static int jl_copy_roots(jl_array_t *method_roots_list, uint64_t key)
740740
{
741741
size_t i, l = jl_array_nrows(method_roots_list);
742+
int failed = 0;
742743
for (i = 0; i < l; i+=2) {
743744
jl_method_t *m = (jl_method_t*)jl_array_ptr_ref(method_roots_list, i);
744745
jl_array_t *roots = (jl_array_t*)jl_array_ptr_ref(method_roots_list, i+1);
745746
if (roots) {
746747
assert(jl_is_array(roots));
747-
jl_append_method_roots(m, key, roots);
748+
failed -= jl_append_method_roots(m, key, roots);
748749
}
749750
}
751+
return failed;
750752
}
751753

752754
static jl_value_t *read_verify_mod_list(ios_t *s, jl_array_t *depmods)

0 commit comments

Comments
 (0)