Skip to content

Commit 5bf399b

Browse files
authored
[libc] Move preinit/init/fini arrays to namespace (#158746)
In change #146863 we moved definitions of preinit/init/fini arrays to header but unintentionally moved outside of the namespace. Since the namespace also controls the visibility (through LIBC_NAMESPACE_DECL), as a consequence these symbols no longer have the hidden visibility which changes the codegen from: ``` 4: 4c11 ldr r4, [pc, #0x44] @ 0x4c <__libc_init_array+0x4c> 6: 4812 ldr r0, [pc, #0x48] @ 0x50 <__libc_init_array+0x50> 8: 447c add r4, pc a: 4478 add r0, pc c: 1b00 subs r0, r0, r4 ``` to: ``` 4: 4813 ldr r0, [pc, #0x4c] @ 0x54 <__libc_init_array+0x54> 6: 4914 ldr r1, [pc, #0x50] @ 0x58 <__libc_init_array+0x58> 8: 4478 add r0, pc a: 4479 add r1, pc c: 6804 ldr r4, [r0] e: 6808 ldr r0, [r1] 10: 1b00 subs r0, r0, r4 ``` The `ldr` will trigger a fault in case where these symbols aren't pointing to a valid memory location which is sometimes the case when the array is empty.
1 parent 008f9f3 commit 5bf399b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

libc/startup/baremetal/fini.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "hdr/stdint_proxy.h"
10+
#include "src/__support/macros/config.h"
11+
12+
// NOTE: The namespace is necessary here to set the correct symbol visibility.
13+
namespace LIBC_NAMESPACE_DECL {
1014

1115
extern "C" {
1216
extern uintptr_t __fini_array_start[];
1317
extern uintptr_t __fini_array_end[];
1418

1519
void __libc_fini_array(void);
1620
} // extern "C"
21+
22+
} // namespace LIBC_NAMESPACE_DECL

libc/startup/baremetal/init.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "hdr/stdint_proxy.h"
10+
#include "src/__support/macros/config.h"
11+
12+
// NOTE: The namespace is necessary here to set the correct symbol visibility.
13+
namespace LIBC_NAMESPACE_DECL {
1014

1115
extern "C" {
1216
extern uintptr_t __preinit_array_start[];
@@ -16,3 +20,5 @@ extern uintptr_t __init_array_end[];
1620

1721
void __libc_init_array(void);
1822
} // extern "C"
23+
24+
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)