Skip to contentSkip to conversation

export.h: fix section name for CONFIG_TRIM_UNUSED_KSYMS for Clang

PATCH Applied Nick Desaulniers 4 participants 4 messages Sep 29, 2020 – Sep 30, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 export.h: fix section name for CONFIG_TRIM_UNUSED_KSYMS for Clang

When enabling CONFIG_TRIM_UNUSED_KSYMS, the linker will warn about the orphan sections:
(".discard.ksym") is being placed in '".discard.ksym"' repeatedly when linking vmlinux. This is because the stringification operator, #, in the preprocessor escapes strings. GCC and Clang differ in how they treat section names that contain \".

The portable solution is to not use a string literal with the preprocessor stringification operator.

Fixes commit bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")
---
 include/linux/export.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/export.h +1 -1
index fceb5e855717..8933ff6ad23a 100644
@@ -130,7 +130,7 @@ struct kernel_symbol {
  * discarded in the final link stage.
  */
 #define __ksym_marker(sym)	\
-	static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
+	static int __ksym_marker_##sym[0] __section(.discard.ksym) __used
 
 #define __EXPORT_SYMBOL(sym, sec, ns)					\
 	__ksym_marker(sym);						\
Signature · 1 line
2.28.0.709.gb0816b6eb0-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Nick Desaulniers

When enabling CONFIG_TRIM_UNUSED_KSYMS, the linker will warn about the orphan sections:
(".discard.ksym") is being placed in '".discard.ksym"' repeatedly when linking vmlinux. This is because the stringification operator, #, in the preprocessor escapes strings. GCC and Clang differ in how they treat section names that contain \".

The portable solution is to not use a string literal with the preprocessor stringification operator.

Quoted 6 lines
Fixes commit bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")

Do these other cases need fixing too?

arch/arm64/mm/mmu.c:u64 __section(".mmuoff.data.write") vabits_actual;
include/linux/srcutree.h: __section("___srcu_struct_ptrs") = &name

-Kees

Quoted 20 lines
---
 include/linux/export.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/export.h +1 -1
index fceb5e855717..8933ff6ad23a 100644
@@ -130,7 +130,7 @@ struct kernel_symbol {
  * discarded in the final link stage.
  */
 #define __ksym_marker(sym)	\
-	static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
+	static int __ksym_marker_##sym[0] __section(.discard.ksym) __used
 
 #define __EXPORT_SYMBOL(sym, sec, ns)					\
 	__ksym_marker(sym);						\
Signature · 1 line
2.28.0.709.gb0816b6eb0-goog
Signature · 1 line
Kees Cook
Reviewed-by on v1 1/1
#2 lore raw
In reply to Nick Desaulniers
Quoted 10 lines · Nick Desaulniers

When enabling CONFIG_TRIM_UNUSED_KSYMS, the linker will warn about the orphan sections:
(".discard.ksym") is being placed in '".discard.ksym"' repeatedly when linking vmlinux. This is because the stringification operator, #, in the preprocessor escapes strings. GCC and Clang differ in how they treat section names that contain \".

The portable solution is to not use a string literal with the preprocessor stringification operator.

Quoted 6 lines
Fixes commit bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")
Quoted 20 lines
---
 include/linux/export.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/export.h +1 -1
index fceb5e855717..8933ff6ad23a 100644
@@ -130,7 +130,7 @@ struct kernel_symbol {
  * discarded in the final link stage.
  */
 #define __ksym_marker(sym)	\
-	static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
+	static int __ksym_marker_##sym[0] __section(.discard.ksym) __used
 
 #define __EXPORT_SYMBOL(sym, sec, ns)					\
 	__ksym_marker(sym);						\
Signature · 1 line
2.28.0.709.gb0816b6eb0-goog
Reviewed-by on v1 1/1
#3 lore raw
In reply to Nick Desaulniers
Quoted 11 lines · Nick Desaulniers' via Clang Built Linux

When enabling CONFIG_TRIM_UNUSED_KSYMS, the linker will warn about the orphan sections:
(".discard.ksym") is being placed in '".discard.ksym"' repeatedly when linking vmlinux. This is because the stringification operator, #, in the preprocessor escapes strings. GCC and Clang differ in how they treat section names that contain \".

The portable solution is to not use a string literal with the preprocessor stringification operator.

Quoted 6 lines
Fixes commit bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")

"The return of escaped section names" - soon in your cinema?

Thanks Nick for catching this.

- Sedat -

Quoted 24 lines
---
 include/linux/export.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/export.h +1 -2
index fceb5e855717..8933ff6ad23a 100644
@@ -130,7 +130,7 @@ struct kernel_symbol {
  * discarded in the final link stage.
  */
 #define __ksym_marker(sym)     \
-       static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
+       static int __ksym_marker_##sym[0] __section(.discard.ksym) __used
 
 #define __EXPORT_SYMBOL(sym, sec, ns)                                  \
        __ksym_marker(sym);                                             \
--

2.28.0.709.gb0816b6eb0-goog

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200929190701.398762-1-ndesaulniers%40google.com.