diff options
author | Florian Weimer <fweimer@redhat.com> | 2020-05-18 15:21:04 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-05-18 15:30:09 +0200 |
commit | 7b5bfe77836442b9aeb75cc520f0d1eb7f82be67 (patch) | |
tree | 042242b904ee724c8beab0f6f0a816f095fcd09f /elf | |
parent | aa70d0563256b8ea053203177f756bca33b5cf37 (diff) | |
download | glibc-7b5bfe77836442b9aeb75cc520f0d1eb7f82be67.zip glibc-7b5bfe77836442b9aeb75cc520f0d1eb7f82be67.tar.gz glibc-7b5bfe77836442b9aeb75cc520f0d1eb7f82be67.tar.bz2 |
elf: Assert that objects are relocated before their constructors run
If we try to run constructors before relocation, this is always
a dynamic linker bug. An assert is easier to notice than a call
via an invalid function pointer (which may not even produce a valid
call stack).
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'elf')
-rw-r--r-- | elf/dl-init.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/elf/dl-init.c b/elf/dl-init.c index 1234611..518824e 100644 --- a/elf/dl-init.c +++ b/elf/dl-init.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see <https://www.gnu.org/licenses/>. */ +#include <assert.h> #include <stddef.h> #include <ldsodefs.h> #include <elf-initfini.h> @@ -28,6 +29,11 @@ typedef void (*init_t) (int, char **, char **); static void call_init (struct link_map *l, int argc, char **argv, char **env) { + /* If the object has not been relocated, this is a bug. The + function pointers are invalid in this case. (Executables do not + need relocation, and neither do proxy objects.) */ + assert (l->l_real->l_relocated || l->l_real->l_type == lt_executable); + if (l->l_init_called) /* This object is all done. */ return; |