[libc-commits] [libc] [libc] Keep the preinit_array entry in the init/fini test under LTO (PR #239978)
Mike Lothian via libc-commits
libc-commits at lists.llvm.org
Sat Nov 7 06:45:08 PST 2026
https://github.com/FireBurn created https://github.com/llvm/llvm-project/pull/239978
Nothing refers to the entry, so LTO treated it as dead and the pre-init
function never ran.
Assisted-by: Claude
>From 0a373d1cd965858913d596de8b1e6bde8acdd808 Mon Sep 17 00:00:00 2001
From: Mike Lothian <mike at fireburn.co.uk>
Date: Tue, 29 Sep 2026 19:09:53 +0100
Subject: [PATCH] [libc] Keep the preinit_array entry in the init/fini test
under LTO
Nothing refers to the entry, so LTO treated it as dead and the pre-init
function never ran.
Assisted-by: Claude
---
libc/test/integration/startup/linux/init_fini_array_test.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/test/integration/startup/linux/init_fini_array_test.cpp b/libc/test/integration/startup/linux/init_fini_array_test.cpp
index ed14e03a60c05e..ada64332857147 100644
--- a/libc/test/integration/startup/linux/init_fini_array_test.cpp
+++ b/libc/test/integration/startup/linux/init_fini_array_test.cpp
@@ -52,8 +52,9 @@ __attribute__((destructor(2))) void reset_preinitval() {
preinitval = 0;
}
+// Nothing refers to the entry, so LTO drops it unless it is marked as used.
using PreInitFunc = void();
-__attribute__((section(".preinit_array"))) PreInitFunc *preinit_func_ptr =
+__attribute__((section(".preinit_array"), used)) PreInitFunc *preinit_func_ptr =
&set_preinitval;
TEST_MAIN() {
More information about the libc-commits
mailing list