From 4e9edd234fa63b7311de4fca03241275090658bf Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Tue, 4 Jun 2024 12:45:00 -0700 Subject: [PATCH] Fix missing apps section issue on clang Clang linker would remove apps section even though variable insied it are marked as "used". Per clang doc, we need to add "retain" attribute to prevent section gc. Bug: 294283461 Test: th Change-Id: I5fc0aee885a419f314de811a2cf92b77af230c0c --- top/include/lk/compiler.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/top/include/lk/compiler.h b/top/include/lk/compiler.h index d00104b0..8bdb49c8 100644 --- a/top/include/lk/compiler.h +++ b/top/include/lk/compiler.h @@ -20,7 +20,10 @@ #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #define __UNUSED __attribute__((__unused__)) -#define __USED __attribute__((__used__)) +// Per https://clang.llvm.org/docs/AttributeReference.html#used +// __used__ does not prevent linkers from removing unused sections +// (if --gc-sections is passed). Need to specify "retain" as well. +#define __USED __attribute__((__used__, retain)) #define __PACKED __attribute__((packed)) #define __ALIGNED(x) __attribute__((aligned(x))) #define __PRINTFLIKE(__fmt,__varargs) __attribute__((__format__ (__printf__, __fmt, __varargs)))