Bug 15903 - INITFIRST flag does not change fini order
Summary: INITFIRST flag does not change fini order
Status: WAITING
Alias: None
Product: glibc
Classification: Unclassified
Component: dynamic-link (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: Guillaume
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-27 19:49 UTC by Guillaume
Modified: 2023-09-11 20:04 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
git diff of an idea of a fix (732 bytes, patch)
2013-08-27 19:49 UTC, Guillaume
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Guillaume 2013-08-27 19:49:29 UTC
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.
Comment 1 Florian Weimer 2023-09-11 07:26:00 UTC
I believe bug 30785 fixes this as well. Would you please re-check using your test case?