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:
Jérôme Duval
2019-04-18 04:54:01 +00:00
committed by waddlesplash
parent 96e7ae6c4c
commit 3a75ef9ad1
2 changed files with 49 additions and 6 deletions
+6 -6
View File
@@ -228,6 +228,12 @@ init_dependencies(image_t *image, bool initHead)
image_t **initList;
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);
if (count <= 0)
return;
@@ -244,12 +250,6 @@ init_dependencies(image_t *image, bool initHead)
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;
if (find_symbol(image,
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