Skip to content

Commit 3434a21

Browse files
habermancopybara-github
authored andcommitted
Fixed LTO-only linker error in upb linker arrays.
Also removed a sanitizer warning on non-Clang compilers. Fixes: #21021 PiperOrigin-RevId: 748395156
1 parent e4b2628 commit 3434a21

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

upb/mini_table/extension_registry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ upb_ExtensionRegistryStatus upb_ExtensionRegistry_AddArray(
8282

8383
#ifdef UPB_LINKARR_DECLARE
8484

85-
UPB_LINKARR_DECLARE(upb_AllExts, upb_MiniTableExtension);
85+
UPB_LINKARR_DECLARE(upb_AllExts, const upb_MiniTableExtension);
8686

8787
bool upb_ExtensionRegistry_AddAllLinkedExtensions(upb_ExtensionRegistry* r) {
8888
const upb_MiniTableExtension* start = UPB_LINKARR_START(upb_AllExts);

upb/port/def.inc

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ Error, UINTPTR_MAX is undefined
467467

468468
#undef UPB_IS_GOOGLE3
469469

470+
#ifdef __clang__
471+
#define UPB_NO_SANITIZE_ADDRESS __attribute__((no_sanitize("address")))
472+
#else
473+
#define UPB_NO_SANITIZE_ADDRESS
474+
#endif
475+
470476
// Linker arrays combine elements from multiple translation units into a single
471477
// array that can be iterated over at runtime.
472478
//
@@ -493,28 +499,28 @@ Error, UINTPTR_MAX is undefined
493499

494500
#if defined(__ELF__) || defined(__wasm__)
495501

496-
#define UPB_LINKARR_APPEND(name) \
497-
__attribute__((retain, used, section("linkarr_" #name), \
498-
no_sanitize("address")))
499-
#define UPB_LINKARR_DECLARE(name, type) \
500-
extern type const __start_linkarr_##name; \
501-
extern type const __stop_linkarr_##name; \
502+
#define UPB_LINKARR_APPEND(name) \
503+
__attribute__((retain, used, \
504+
section("linkarr_" #name))) UPB_NO_SANITIZE_ADDRESS
505+
#define UPB_LINKARR_DECLARE(name, type) \
506+
extern type __start_linkarr_##name; \
507+
extern type __stop_linkarr_##name; \
502508
UPB_LINKARR_APPEND(name) type UPB_linkarr_internal_empty_##name[1]
503509
#define UPB_LINKARR_START(name) (&__start_linkarr_##name)
504510
#define UPB_LINKARR_STOP(name) (&__stop_linkarr_##name)
505511

506512
#elif defined(__MACH__)
507513

508514
/* As described in: https://stackoverflow.com/a/22366882 */
509-
#define UPB_LINKARR_APPEND(name) \
510-
__attribute__((retain, used, section("__DATA,__la_" #name), \
511-
no_sanitize("address")))
512-
#define UPB_LINKARR_DECLARE(name, type) \
513-
extern type const __start_linkarr_##name __asm( \
514-
"section$start$__DATA$__la_" #name); \
515-
extern type const __stop_linkarr_##name __asm( \
516-
"section$end$__DATA$" \
517-
"__la_" #name); \
515+
#define UPB_LINKARR_APPEND(name) \
516+
__attribute__((retain, used, \
517+
section("__DATA,__la_" #name))) UPB_NO_SANITIZE_ADDRESS
518+
#define UPB_LINKARR_DECLARE(name, type) \
519+
extern type __start_linkarr_##name __asm( \
520+
"section$start$__DATA$__la_" #name); \
521+
extern type __stop_linkarr_##name __asm( \
522+
"section$end$__DATA$" \
523+
"__la_" #name); \
518524
UPB_LINKARR_APPEND(name) type UPB_linkarr_internal_empty_##name[1]
519525
#define UPB_LINKARR_START(name) (&__start_linkarr_##name)
520526
#define UPB_LINKARR_STOP(name) (&__stop_linkarr_##name)
@@ -530,7 +536,7 @@ Error, UINTPTR_MAX is undefined
530536
// not work on MSVC.
531537
#define UPB_LINKARR_APPEND(name) \
532538
__declspec(allocate("la_" #name "$j")) \
533-
__attribute__((retain, used, no_sanitize("address")))
539+
__attribute__((retain, used)) UPB_NO_SANITIZE_ADDRESS
534540
#define UPB_LINKARR_DECLARE(name, type) \
535541
__declspec(allocate("la_" #name "$a")) type __start_linkarr_##name; \
536542
__declspec(allocate("la_" #name "$z")) type __stop_linkarr_##name; \

0 commit comments

Comments
 (0)