Skip to content

Commit 7d5f744

Browse files
committed
rtld: Check for -1 as an-end-of-section marker instead of 1
rtld calls functions in the .init_array section one at a time, until it finds a distinguished sentinel value. The C runtime does the same thing (in crtend.c). However, that checks for the sentinel -1 and not 1. If one is using a linker that unifies .ctors and .init_array, then rtld will miss the sentinel value. I believe the author of this code intended to write -1 instead of 1. Indeed, changing the branch to check for -1 prevents rtld from attempting to call a non-existent function. The same is true of .dtors and .fini_array. Signed-off-by: Daniel Levin <daniellevin2607@gmail.com>
1 parent 6d53619 commit 7d5f744

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

libexec/rtld-elf/rtld.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,7 +3166,7 @@ objlist_call_fini(Objlist *list, Obj_Entry *root, RtldLockState *lockstate)
31663166
for (index = elm->obj->fini_array_num - 1;
31673167
index >= 0; index--) {
31683168
if (fini_addr[index] != 0 &&
3169-
fini_addr[index] != 1) {
3169+
fini_addr[index] != (Elf_Addr)-1) {
31703170
dbg("calling fini function for %s at %p",
31713171
elm->obj->path,
31723172
(void *)fini_addr[index]);
@@ -3272,7 +3272,7 @@ objlist_call_init(Objlist *list, RtldLockState *lockstate)
32723272
for (index = 0; index < elm->obj->init_array_num;
32733273
index++) {
32743274
if (init_addr[index] != 0 &&
3275-
init_addr[index] != 1) {
3275+
init_addr[index] != (Elf_Addr)-1) {
32763276
dbg("calling init function for %s at %p",
32773277
elm->obj->path,
32783278
(void *)init_addr[index]);

0 commit comments

Comments
 (0)