From: kettenis Date: Mon, 22 Jul 2024 22:06:27 +0000 (+0000) Subject: Specify a priority for _libc_preinit() to make sure it runs before other X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=17423a06aac5f7ca8e40b9b2f3341b9b9f9255c6;p=openbsd Specify a priority for _libc_preinit() to make sure it runs before other constructors (such as the constructor for libcompiler_rt). ok guenther@ --- diff --git a/lib/libc/dlfcn/init.c b/lib/libc/dlfcn/init.c index c7b8fd2bc37..dd2cd9f4045 100644 --- a/lib/libc/dlfcn/init.c +++ b/lib/libc/dlfcn/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.23 2024/07/14 09:48:48 jca Exp $ */ +/* $OpenBSD: init.c,v 1.24 2024/07/22 22:06:27 kettenis Exp $ */ /* * Copyright (c) 2014,2015 Philip Guenther * @@ -189,14 +189,16 @@ _libc_preinit(int argc, char **argv, char **envp, dl_cb_cb *cb) # endif #endif -#define ADD_TO_ARRAY(func, which) \ - __asm( " .section ."#which",\"a\","TYPE#which"\n " \ - VALUE_ALIGN"\n "VALUE_DIRECTIVE" "#func"\n .previous") - #ifdef PIC -ADD_TO_ARRAY(_libc_preinit, init_array); +/* + * Set a priority so _libc_preinit gets called before the constructor + * on libcompiler_rt that may use elf_aux_info(3). + */ +__asm(" .section .init_array.50,\"a\","TYPE"init_array\n " \ + VALUE_ALIGN"\n "VALUE_DIRECTIVE" _libc_preinit\n .previous"); #else -ADD_TO_ARRAY(_libc_preinit, preinit_array); +__asm(" .section .preinit_array,\"a\","TYPE"preinit_array\n " \ + VALUE_ALIGN"\n "VALUE_DIRECTIVE" _libc_preinit\n .previous"); #endif /*