diff options
author | guenther <guenther@openbsd.org> | 2019-05-11 21:02:35 +0000 |
---|---|---|
committer | guenther <guenther@openbsd.org> | 2019-05-11 21:02:35 +0000 |
commit | 5c3b452cc2419d5e8b38f1b1a9f46bc8b2b8feed (patch) | |
tree | cbd4deaee423ca206638a72fbe7a508308677e7b /libexec | |
parent | Kill an unused done: label and the associated superfluous "return;" (diff) | |
download | wireguard-openbsd-5c3b452cc2419d5e8b38f1b1a9f46bc8b2b8feed.tar.xz wireguard-openbsd-5c3b452cc2419d5e8b38f1b1a9f46bc8b2b8feed.zip |
Prune visited leaves when walking dependencies to call init functions in
topological sort order, reducing it to O(n) from O(2^n) (ouch!)
diff from Nathanael Rensen (nathanael(at)list.polymorpheus.com)
Much testing and pleading by robert@ and ajacoutot@
ok drahn@ mpi@
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/ld.so/loader.c | 9 | ||||
-rw-r--r-- | libexec/ld.so/resolve.h | 21 |
2 files changed, 15 insertions, 15 deletions
diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index a597f0cbd72..4b4ddc755c9 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.178 2019/05/10 13:29:21 guenther Exp $ */ +/* $OpenBSD: loader.c,v 1.179 2019/05/11 21:02:35 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -789,17 +789,16 @@ void _dl_call_init_recurse(elf_object_t *object, int initfirst) { struct dep_node *n; + int visited_flag = initfirst ? STAT_VISIT_INITFIRST : STAT_VISIT_INIT; - object->status |= STAT_VISITED; + object->status |= visited_flag; TAILQ_FOREACH(n, &object->child_list, next_sib) { - if (n->data->status & STAT_VISITED) + if (n->data->status & visited_flag) continue; _dl_call_init_recurse(n->data, initfirst); } - object->status &= ~STAT_VISITED; - if (object->status & STAT_INIT_DONE) return; diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h index 1f313788a5b..82ac21b487b 100644 --- a/libexec/ld.so/resolve.h +++ b/libexec/ld.so/resolve.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.h,v 1.91 2019/05/10 13:29:21 guenther Exp $ */ +/* $OpenBSD: resolve.h,v 1.92 2019/05/11 21:02:35 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -132,15 +132,16 @@ struct elf_object { Elf_Addr relcount; /* DT_RELCOUNT */ int status; -#define STAT_RELOC_DONE 0x01 -#define STAT_GOT_DONE 0x02 -#define STAT_INIT_DONE 0x04 -#define STAT_FINI_DONE 0x08 -#define STAT_FINI_READY 0x10 -#define STAT_UNLOADED 0x20 -#define STAT_NODELETE 0x40 -#define STAT_VISITED 0x80 -#define STAT_GNU_HASH 0x100 +#define STAT_RELOC_DONE 0x001 +#define STAT_GOT_DONE 0x002 +#define STAT_INIT_DONE 0x004 +#define STAT_FINI_DONE 0x008 +#define STAT_FINI_READY 0x010 +#define STAT_UNLOADED 0x020 +#define STAT_NODELETE 0x040 +#define STAT_GNU_HASH 0x080 +#define STAT_VISIT_INITFIRST 0x100 +#define STAT_VISIT_INIT 0x200 Elf_Phdr *phdrp; int phdrc; |