Skip to content

Commit 2d48c83

Browse files
committed
fix: 弱声明不能有内部链接
初始化数组的四个符号放在匿名 namespace 里了 —— clang 直接拒绝: weak declaration cannot have internal linkage。移到外面。
1 parent b17d0e5 commit 2d48c83

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/start.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ int main(int, char**, char**);
4545

4646
}
4747

48-
namespace {
49-
5048
using initialiser = void (*)(int, char**, char**);
5149

50+
// ⚠️ NOT in an anonymous namespace, and that is the compiler's rule rather than
51+
// a preference: internal linkage and a weak declaration are contradictory, and
52+
// clang says so in as many words. The linker script defines these, and a
53+
// program built without one gets the null range the weak declaration is for.
5254
[[gnu::weak]] extern initialiser __preinit_array_start[];
5355
[[gnu::weak]] extern initialiser __preinit_array_end[];
5456
[[gnu::weak]] extern initialiser __init_array_start[];
5557
[[gnu::weak]] extern initialiser __init_array_end[];
5658

59+
namespace {
60+
5761
void run_initialisers() {
5862
// ⚠️ Only when no C library took the hand-over. One that did runs these
5963
// itself, and running them twice constructs every static object twice.

0 commit comments

Comments
 (0)