runtime_loader: call preinit_array before initializing dependencies.
Change-Id: Ieed1af8ede83692d583d8e84bae92b1be29ddd1e Reviewed-on: https://review.haiku-os.org/c/1187 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
96e7ae6c4c
commit
3a75ef9ad1
@@ -228,6 +228,12 @@ init_dependencies(image_t *image, bool initHead)
|
|||||||
image_t **initList;
|
image_t **initList;
|
||||||
ssize_t count, i;
|
ssize_t count, i;
|
||||||
|
|
||||||
|
if (initHead && image->preinit_array) {
|
||||||
|
uint count_preinit = image->preinit_array_len / sizeof(addr_t);
|
||||||
|
for (uint j = 0; j < count_preinit; j++)
|
||||||
|
((initfini_array_function)image->preinit_array[j])();
|
||||||
|
}
|
||||||
|
|
||||||
count = get_sorted_image_list(image, &initList, RFLAG_INITIALIZED);
|
count = get_sorted_image_list(image, &initList, RFLAG_INITIALIZED);
|
||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
return;
|
return;
|
||||||
@@ -244,12 +250,6 @@ init_dependencies(image_t *image, bool initHead)
|
|||||||
|
|
||||||
TRACE(("%ld: init: %s\n", find_thread(NULL), image->name));
|
TRACE(("%ld: init: %s\n", find_thread(NULL), image->name));
|
||||||
|
|
||||||
if (image->preinit_array) {
|
|
||||||
uint count_preinit = image->preinit_array_len / sizeof(addr_t);
|
|
||||||
for (uint j = 0; j < count_preinit; j++)
|
|
||||||
((initfini_array_function)image->preinit_array[j])();
|
|
||||||
}
|
|
||||||
|
|
||||||
init_term_function before;
|
init_term_function before;
|
||||||
if (find_symbol(image,
|
if (find_symbol(image,
|
||||||
SymbolLookupInfo(B_INIT_BEFORE_FUNCTION_NAME, B_SYMBOL_TYPE_TEXT),
|
SymbolLookupInfo(B_INIT_BEFORE_FUNCTION_NAME, B_SYMBOL_TYPE_TEXT),
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# program
|
||||||
|
# <- liba.so
|
||||||
|
# Expected: preinit function in program runs before constructor in liba.so.
|
||||||
|
|
||||||
|
|
||||||
|
. ./test_setup
|
||||||
|
|
||||||
|
|
||||||
|
# create liba.so
|
||||||
|
cat > liba.c << EOI
|
||||||
|
extern int i;
|
||||||
|
void __attribute__((constructor)) a() { i = 2 * i + 1; }
|
||||||
|
EOI
|
||||||
|
|
||||||
|
# build
|
||||||
|
compile_lib -o liba.so liba.c
|
||||||
|
|
||||||
|
# create program
|
||||||
|
cat > program.c << EOI
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
void b() { i = 4 * i + 1; }
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((section(".preinit_array"), used))
|
||||||
|
void (*__local_b_preinit)(void) = b;
|
||||||
|
|
||||||
|
EOI
|
||||||
|
|
||||||
|
# build
|
||||||
|
compile_program -o program program.c ./liba.so -pie
|
||||||
|
|
||||||
|
# run
|
||||||
|
test_run_ok ./program 11
|
||||||
|
|
||||||
Reference in New Issue
Block a user