[PATCH v1 03/14] compiler: add unique __SECTION_NAME()

Yuan Tan tanyuan at tinylab.org
Fri Nov 3 08:58:59 PDT 2023


From: Zhangjin Wu <falcon at tinylab.org>

The new section helper is added for LD_DEAD_CODE_DATA_ELIMINATION to
generate unique section name (strigified).

Signed-off-by: Zhangjin Wu <falcon at tinylab.org>
Signed-off-by: Yuan Tan <tanyuan at tinylab.org>
---
 include/linux/compiler.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 405b19cf6cf3..5a9cc3209b12 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -227,11 +227,25 @@ static inline void *offset_to_ptr(const int *off)
 
 #endif /* __ASSEMBLY__ */
 
+/* Import __stringify. */
+#ifndef __stringify
+#include <linux/stringify.h>
+#endif
+
 /* Quite-unique ID. */
 #ifndef __QUITE_UNIQUE_ID
 # define __QUITE_UNIQUE_ID(prefix) __PASTE(__PASTE(prefix, __LINE__), __COUNTER__)
 #endif
 
+/* Quite-unique Section NAME. */
+#ifndef __SECTION_NAME
+#ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
+# define __SECTION_NAME(prefix) __stringify(__QUITE_UNIQUE_ID(prefix.))
+#else
+# define __SECTION_NAME(prefix) __stringify(prefix)
+#endif
+#endif
+
 /* &a[0] degrades to a pointer: a different type from an array */
 #define __must_be_array(a)	BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
 
-- 
2.34.1




More information about the linux-riscv mailing list