[libcxx-commits] [libcxx] [libc++] Make __start___lcxx_override/__stop___lcxx_override weak (PR #79347)

Fangrui Song via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 24 11:03:53 PST 2024


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/79347

After #69498, when `_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE`
functions are absent (possibly after ld --gc-sections), there will no
output section `__lcxx_override`. The linker will report an error like

```
ld: error: undefined symbol: __start___lcxx_override
>>> referenced by overridable_function.h:108 (libcxx/src/include/overridable_function.h:108)
```

Fix this by making the references weak.


>From 0614e113009d833067fa5ad05e12cc6c43967108 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Wed, 24 Jan 2024 11:00:47 -0800
Subject: [PATCH] [libc++] Make __start___lcxx_override/__stop___lcxx_override
 weak

After #69498, when `_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE`
functions are absent (possibly after ld --gc-sections), there will no
output section `__lcxx_override`. The linker will report an error like

```
ld: error: undefined symbol: __start___lcxx_override
>>> referenced by overridable_function.h:108 (libcxx/src/include/overridable_function.h:108)
```

Fix this by making the references weak.
---
 libcxx/src/include/overridable_function.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/src/include/overridable_function.h b/libcxx/src/include/overridable_function.h
index 7b0fba10f47d4aa..e871411021f0fc6 100644
--- a/libcxx/src/include/overridable_function.h
+++ b/libcxx/src/include/overridable_function.h
@@ -95,8 +95,8 @@ _LIBCPP_END_NAMESPACE_STD
 // variables with those names corresponding to the start and the end of the section.
 //
 // See https://stackoverflow.com/questions/16552710/how-do-you-get-the-start-and-end-addresses-of-a-custom-elf-section
-extern char __start___lcxx_override;
-extern char __stop___lcxx_override;
+_LIBCPP_WEAK extern char __start___lcxx_override;
+_LIBCPP_WEAK extern char __stop___lcxx_override;
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 template <class _Ret, class... _Args>



More information about the libcxx-commits mailing list