Created attachment 7169 [details] git diff of an idea of a fix It looks like the INITFIRST flag is read by ld.so only for the init order and not during sorting the fini order. For instance, if I build a first library (lib1) with -z initfirst and a second one without, link an executable with these two libraries, and finally run it with LD_DEBUG, I have: 26457: calling init: ../lib1/lib1.so 26457: calling init: /lib64/ld-linux-x86-64.so.2 26457: calling init: /lib64/libc.so.6 26457: calling init: ../lib2/lib2.so 26457: calling fini: ./test [0] 26457: calling fini: ../lib1/lib1.so [0] 26457: calling fini: ../lib2/lib2.so [0] According to https://sourceware.org/binutils/docs/ld/Options.html the fini order should be the reverse order of the init order... Having a closer look to elf/dl-fini.c it seems that there is no check of the initfirst flag. Find attached an idea of a fix.
I believe bug 30785 fixes this as well. Would you please re-check using your test case?