gendwarfksyms: define __GENKSYMS__ when processing asm-protoypes.h
PATCH 1/1 gendwarfksyms: define __GENKSYMS__ when processing asm-protoypes.h
From: Ard Biesheuvel <[email protected]>
Ensure that __GENKSYMS__ is #define'd when passing asm/asm-prototypes.h through the compiler to capture the exported symbols. This ensures that exported symbols such as __ref_stack_chk_guard on x86, which is declared conditionally, is visible to the tool.
Otherwise, an error such as the below may be raised, breaking the build when CONFIG_GENDWARFKSYMS=y
<stdin>:4:15: error: use of undeclared identifier '__ref_stack_chk_guard'
--- scripts/Makefile.build | 1 + 1 file changed, 1 insertion(+)
scripts/Makefile.build +1 -0
@@ -305,6 +305,7 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE getasmexports = \ { echo "\#include <linux/kernel.h>" ; \ echo "\#include <linux/string.h>" ; \ + echo "\#define __GENKSYMS__" ; \ echo "\#include <asm/asm-prototypes.h>" ; \ $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Quoted 8 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Ensure that
__GENKSYMS__is #define'd when passingasm/asm-prototypes.hthrough the compiler to capture the exported symbols. This ensures that exported symbols such as__ref_stack_chk_guardon x86, which is declared conditionally, is visible to the tool.
Quoted 8 lines
Otherwise, an error such as the below may be raised, breaking the build when
CONFIG_GENDWARFKSYMS=y<stdin>:4:15: error: use of undeclared identifier '
__ref_stack_chk_guard'Cc Sami Tolvanen <[email protected]>Reported-by [email protected]Signed-off-by Ard Biesheuvel <[email protected]>
https://syzkaller.appspot.com/bug?extid=06fd1a3613c50d36129e
Quoted 19 lines
--- scripts/Makefile.build | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.build +1
-1@@ -305,6 +305,7 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE getasmexports = \ { echo "\#include <linux/kernel.h>" ; \ echo "\#include <linux/string.h>" ; \ + echo "\#define __GENKSYMS__" ; \ echo "\#include <asm/asm-prototypes.h>" ; \ $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; } --2.49.0.rc1.451.g8f38331e32-goog
[tip: x86/core] gendwarfksyms: Define __GENKSYMS__ when processing <asm/asm-protoypes.h>
In reply to Ard BiesheuvelThe following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: fb3135208f688c5cab7d05e3a0d229935ee7611a Gitweb: https://git.kernel.org/tip/fb3135208f688c5cab7d05e3a0d229935ee7611a Author: Ard Biesheuvel <[email protected]> AuthorDate: Thu, 20 Mar 2025 08:07:47 +01:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Thu, 20 Mar 2025 09:48:49 +01:00
gendwarfksyms: Define __GENKSYMS__ when processing <asm/asm-protoypes.h>
Ensure that __GENKSYMS__ is #define'd when passing <asm/asm-prototypes.h> through the compiler to capture the exported symbols. This ensures that exported symbols such as __ref_stack_chk_guard on x86, which is declared conditionally, is visible to the tool.
Otherwise the build might break when CONFIG_GENDWARFKSYMS=y:
<stdin>:4:15: error: use of undeclared identifier '__ref_stack_chk_guard'
--- scripts/Makefile.build | 1 + 1 file changed, 1 insertion(+)
scripts/Makefile.build +1 -0
@@ -305,6 +305,7 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE getasmexports = \ { echo "\#include <linux/kernel.h>" ; \ echo "\#include <linux/string.h>" ; \ + echo "\#define __GENKSYMS__" ; \ echo "\#include <asm/asm-prototypes.h>" ; \ $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }
Quoted 7 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Ensure that
__GENKSYMS__is #define'd when passingasm/asm-prototypes.hthrough the compiler to capture the exported symbols. This ensures that exported symbols such as__ref_stack_chk_guardon x86, which is declared conditionally, is visible to the tool.
Why don't you make it unconditional, then?
(quoted diff) +0 -0
b/arch/x86/include/asm/asm-prototypes.h
index 3674006e3974..9fc6f2be663c 100644
arch/x86/include/asm/asm-prototypes.h +0 -2
@@ -20,6 +20,4 @@extern void cmpxchg8b_emu (void );#endif -#if defined(__GENKSYMS__) && defined(CONFIG_STACKPROTECTOR )extern unsigned long __ref_stack_chk_guard; -#endif
Quoted 28 lines
Otherwise, an error such as the below may be raised, breaking the build when
CONFIG_GENDWARFKSYMS=y<stdin>:4:15: error: use of undeclared identifier '
__ref_stack_chk_guard'Cc Sami Tolvanen <[email protected]>Reported-by [email protected]Signed-off-by Ard Biesheuvel <[email protected]>--- scripts/Makefile.build | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.build +1
-1@@ -305,6 +305,7 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE getasmexports = \ { echo "\#include <linux/kernel.h>" ; \ echo "\#include <linux/string.h>" ; \ + echo "\#define __GENKSYMS__" ; \ echo "\#include <asm/asm-prototypes.h>" ; \ $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; } --2.49.0.rc1.451.g8f38331e32-goog
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 5 lines · Masahiro Yamada
Quoted 3 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Quoted 8 lines
Quoted 4 lines
Ensure that
__GENKSYMS__is #define'd when passingasm/asm-prototypes.hthrough the compiler to capture the exported symbols. This ensures that exported symbols such as__ref_stack_chk_guardon x86, which is declared conditionally, is visible to the tool.Why don't you make it unconditional, then?
Because this symbol is being hidden from the compiler.
Commit 577c134d311b9b has the details.
Hi Ard,
Quoted 25 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Ensure that
__GENKSYMS__is #define'd when passingasm/asm-prototypes.hthrough the compiler to capture the exported symbols. This ensures that exported symbols such as__ref_stack_chk_guardon x86, which is declared conditionally, is visible to the tool.Otherwise, an error such as the below may be raised, breaking the build when
CONFIG_GENDWARFKSYMS=y<stdin>:4:15: error: use of undeclared identifier '
__ref_stack_chk_guard'Cc Sami Tolvanen <[email protected]>Reported-by [email protected]Signed-off-by Ard Biesheuvel <[email protected]>--- scripts/Makefile.build | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.build +0
-0
scripts/Makefile.build $(obj)/%.rs: $(obj)/%.rs.S FORCE · line 310
Quoted 6 lines
scripts/Makefile.build +1
-0@@ -305,6 +305,7 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE getasmexports = \ { echo "\#include <linux/kernel.h>" ; \ echo "\#include <linux/string.h>" ; \ + echo "\#define __GENKSYMS__" ; \ echo "\#include <asm/asm-prototypes.h>" ; \ $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }
This works with gendwarfksyms since __GENKSYMS__ is defined after the EXPORT_SYMBOL() definition, but I'm now getting warnings with genksyms:
AS arch/x86/lib/clear_page_64.o
<stdin>:3:10: warning: "__GENKSYMS__" redefined <command-line>: note: this is the location of the previous definition
Sami
Quoted 40 lines · Sami Tolvanen
Hi Ard,
Quoted 25 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Ensure that
__GENKSYMS__is #define'd when passingasm/asm-prototypes.hthrough the compiler to capture the exported symbols. This ensures that exported symbols such as__ref_stack_chk_guardon x86, which is declared conditionally, is visible to the tool.Otherwise, an error such as the below may be raised, breaking the build when
CONFIG_GENDWARFKSYMS=y<stdin>:4:15: error: use of undeclared identifier '
__ref_stack_chk_guard'Cc Sami Tolvanen <[email protected]>Reported-by [email protected]Signed-off-by Ard Biesheuvel <[email protected]>--- scripts/Makefile.build | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.build +0
-0scripts/Makefile.build $(obj)/%.rs: $(obj)/%.rs.S FORCE · line 310
Quoted 6 lines
scripts/Makefile.build +1
-0@@ -305,6 +305,7 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE getasmexports = \ { echo "\#include <linux/kernel.h>" ; \ echo "\#include <linux/string.h>" ; \ + echo "\#define __GENKSYMS__" ; \ echo "\#include <asm/asm-prototypes.h>" ; \ $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }This works with gendwarfksyms since
__GENKSYMS__is defined after theEXPORT_SYMBOL()definition, but I'm now getting warnings with genksyms:
Quoted 4 lines
AS
arch/x86/lib/clear_page_64.o
<stdin>:3:10: warning: "__GENKSYMS__" redefined <command-line>: note: this is the location of the previous definition
Oops.
Do you think the fix below should be sufficient?
scripts/Makefile.build +1 -1
@@ -314,7 +314,7 @@ else cmd_gensymtypes_S = \ $(getasmexports) | \ - $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) + $(CPP) $(c_flags) -xc - | $(genksyms) endif # CONFIG_GENDWARFKSYMS quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
Quoted 54 lines · Ard Biesheuvel
Quoted 40 lines · Sami Tolvanen
Hi Ard,
Quoted 25 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Ensure that
__GENKSYMS__is #define'd when passingasm/asm-prototypes.hthrough the compiler to capture the exported symbols. This ensures that exported symbols such as__ref_stack_chk_guardon x86, which is declared conditionally, is visible to the tool.Otherwise, an error such as the below may be raised, breaking the build when
CONFIG_GENDWARFKSYMS=y<stdin>:4:15: error: use of undeclared identifier '
__ref_stack_chk_guard'Cc Sami Tolvanen <[email protected]>Reported-by [email protected]Signed-off-by Ard Biesheuvel <[email protected]>--- scripts/Makefile.build | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.build +0
-0scripts/Makefile.build $(obj)/%.rs: $(obj)/%.rs.S FORCE · line 310
Quoted 6 lines
scripts/Makefile.build +1
-0@@ -305,6 +305,7 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE getasmexports = \ { echo "\#include <linux/kernel.h>" ; \ echo "\#include <linux/string.h>" ; \ + echo "\#define __GENKSYMS__" ; \ echo "\#include <asm/asm-prototypes.h>" ; \ $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }This works with gendwarfksyms since
__GENKSYMS__is defined after theEXPORT_SYMBOL()definition, but I'm now getting warnings with genksyms:Quoted 4 lines
AS
arch/x86/lib/clear_page_64.o
<stdin>:3:10: warning: "__GENKSYMS__" redefined <command-line>: note: this is the location of the previous definitionOops.
Do you think the fix below should be sufficient?
scripts/Makefile.build line 320
Quoted 8 lines
scripts/Makefile.build +1
-1@@ -314,7 +314,7 @@ else cmd_gensymtypes_S = \ $(getasmexports) | \ - $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) + $(CPP) $(c_flags) -xc - | $(genksyms) endif # CONFIG_GENDWARFKSYMS quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
EXPORT_SYMBOL() has a different definition when __GENKSYMS__ is defined, so I think with genksyms we actually do need this on the command line. I suppose you could wrap the getasmexports definition in #ifndef __GENKSYMS__ to avoid the warning, or just use __GENDWARFKSYMS__ like you suggested earlier.
Sami
Quoted 63 lines · Sami Tolvanen
Quoted 61 lines · Ard Biesheuvel
Quoted 40 lines · Sami Tolvanen
Hi Ard,
Quoted 25 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Ensure that
__GENKSYMS__is #define'd when passingasm/asm-prototypes.hthrough the compiler to capture the exported symbols. This ensures that exported symbols such as__ref_stack_chk_guardon x86, which is declared conditionally, is visible to the tool.Otherwise, an error such as the below may be raised, breaking the build when
CONFIG_GENDWARFKSYMS=y<stdin>:4:15: error: use of undeclared identifier '
__ref_stack_chk_guard'Cc Sami Tolvanen <[email protected]>Reported-by [email protected]Signed-off-by Ard Biesheuvel <[email protected]>--- scripts/Makefile.build | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.build +0
-0scripts/Makefile.build $(obj)/%.rs: $(obj)/%.rs.S FORCE · line 310
Quoted 6 lines
scripts/Makefile.build +1
-0@@ -305,6 +305,7 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE getasmexports = \ { echo "\#include <linux/kernel.h>" ; \ echo "\#include <linux/string.h>" ; \ + echo "\#define __GENKSYMS__" ; \ echo "\#include <asm/asm-prototypes.h>" ; \ $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }This works with gendwarfksyms since
__GENKSYMS__is defined after theEXPORT_SYMBOL()definition, but I'm now getting warnings with genksyms:Quoted 4 lines
AS
arch/x86/lib/clear_page_64.o
<stdin>:3:10: warning: "__GENKSYMS__" redefined <command-line>: note: this is the location of the previous definitionOops.
Do you think the fix below should be sufficient?
scripts/Makefile.build +1
-1@@ -314,7 +314,7 @@ else cmd_gensymtypes_S = \ $(getasmexports) | \ - $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) + $(CPP) $(c_flags) -xc - | $(genksyms) endif # CONFIG_GENDWARFKSYMS
Quoted 8 lines
scripts/Makefile.build line 320
Quoted 1 line
scripts/Makefile.build +0
-0quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
EXPORT_SYMBOL()has a different definition when__GENKSYMS__is defined, so I think with genksyms we actually do need this on the command line. I suppose you could wrap the getasmexports definition in #ifndef__GENKSYMS__to avoid the warning, or just use__GENDWARFKSYMS__like you suggested earlier.
Yeah, on second thought, we could just do what Masahiro suggested, and drop the conditional from asm/asm-prototypes.h
The issue in question only affects definitions, not declarations, and so having the declaration visible shouldn't be a problem.
Ingo, mind dropping this patch again? We'll do the below instead (I'll send out the patch in a minute)
arch/x86/include/asm/asm-prototypes.h +1 -1
@@ -20,6 +20,6 @@extern void cmpxchg8b_emu (void );#endif -#if defined(__GENKSYMS__) && defined(CONFIG_STACKPROTECTOR ) +#ifdef CONFIG_STACKPROTECTOR extern unsigned long __ref_stack_chk_guard;#endif
Quoted 73 lines · Ard Biesheuvel
Quoted 63 lines · Sami Tolvanen
Quoted 61 lines · Ard Biesheuvel
Quoted 40 lines · Sami Tolvanen
Hi Ard,
Quoted 25 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Ensure that
__GENKSYMS__is #define'd when passingasm/asm-prototypes.hthrough the compiler to capture the exported symbols. This ensures that exported symbols such as__ref_stack_chk_guardon x86, which is declared conditionally, is visible to the tool.Otherwise, an error such as the below may be raised, breaking the build when
CONFIG_GENDWARFKSYMS=y<stdin>:4:15: error: use of undeclared identifier '
__ref_stack_chk_guard'Cc Sami Tolvanen <[email protected]>Reported-by [email protected]Signed-off-by Ard Biesheuvel <[email protected]>--- scripts/Makefile.build | 1 + 1 file changed, 1 insertion(+)scripts/Makefile.build +0
-0scripts/Makefile.build $(obj)/%.rs: $(obj)/%.rs.S FORCE · line 310
Quoted 6 lines
scripts/Makefile.build +1
-0@@ -305,6 +305,7 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE getasmexports = \ { echo "\#include <linux/kernel.h>" ; \ echo "\#include <linux/string.h>" ; \ + echo "\#define __GENKSYMS__" ; \ echo "\#include <asm/asm-prototypes.h>" ; \ $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }This works with gendwarfksyms since
__GENKSYMS__is defined after theEXPORT_SYMBOL()definition, but I'm now getting warnings with genksyms:Quoted 4 lines
AS
arch/x86/lib/clear_page_64.o
<stdin>:3:10: warning: "__GENKSYMS__" redefined <command-line>: note: this is the location of the previous definitionOops.
Do you think the fix below should be sufficient?
scripts/Makefile.build +1
-1@@ -314,7 +314,7 @@ else cmd_gensymtypes_S = \ $(getasmexports) | \ - $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) + $(CPP) $(c_flags) -xc - | $(genksyms) endif # CONFIG_GENDWARFKSYMSQuoted 8 lines
scripts/Makefile.build line 320
Quoted 1 line
scripts/Makefile.build +0
-0quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
EXPORT_SYMBOL()has a different definition when__GENKSYMS__is defined, so I think with genksyms we actually do need this on the command line. I suppose you could wrap the getasmexports definition in #ifndef__GENKSYMS__to avoid the warning, or just use__GENDWARFKSYMS__like you suggested earlier.
Quoted 8 lines
Yeah, on second thought, we could just do what Masahiro suggested, and drop the conditional from
asm/asm-prototypes.hThe issue in question only affects definitions, not declarations, and so having the declaration visible shouldn't be a problem.
Ingo, mind dropping this patch again? We'll do the below instead (I'll send out the patch in a minute)
Yeah, done & thanks!
Ingo