Hi,

while working on OpenBSD/arm64 I stumbled upon the issue that the CTOR
and DTOR LIST was optimized away by clang.  Instead of the __ctors()
call it created an endless loop, doing nothing at all.  I don't know
why it does exactly that optimization.  Marking the lists as __used
prevents clang from opimizing those away and fixes my programs.

Comments?

Patrick

diff --git a/lib/csu/crtbegin.c b/lib/csu/crtbegin.c
index 534f4dfb4a1..67c91ef747a 100644
--- a/lib/csu/crtbegin.c
+++ b/lib/csu/crtbegin.c
@@ -84,9 +84,9 @@ __asm(".hidden  __dso_handle");
 long __guard_local __dso_hidden 
__attribute__((section(".openbsd.randomdata")));
 
 
-static init_f __CTOR_LIST__[1]
+static init_f __CTOR_LIST__[1] __used
     __attribute__((section(".ctors"))) = { (void *)-1 };       /* XXX */
-static init_f __DTOR_LIST__[1]
+static init_f __DTOR_LIST__[1] __used
     __attribute__((section(".dtors"))) = { (void *)-1 };       /* XXX */
 
 static void    __dtors(void) __used;
diff --git a/lib/csu/crtbeginS.c b/lib/csu/crtbeginS.c
index f97d30f22b0..d2732b458ab 100644
--- a/lib/csu/crtbeginS.c
+++ b/lib/csu/crtbeginS.c
@@ -95,9 +95,9 @@ pthread_atfork(void (*prep)(void), void (*parent)(void), void 
(*child)(void))
 asm(".hidden pthread_atfork\n .weak pthread_atfork");
 
 
-static init_f __CTOR_LIST__[1]
+static init_f __CTOR_LIST__[1] __used
     __attribute__((section(".ctors"))) = { (void *)-1 };       /* XXX */
-static init_f __DTOR_LIST__[1]
+static init_f __DTOR_LIST__[1] __used
     __attribute__((section(".dtors"))) = { (void *)-1 };       /* XXX */
 
 static void    __dtors(void) __used;

Reply via email to