Skip to contentSkip to conversation

x86/alternative: fix undefined reference to __ibt_endbr_seal[_end]

PATCH Applied Miaohe Lin 3 participants 6 messages Oct 11, 2022 – Dec 5, 2022 x86

lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH v2 1/1 x86/alternative: fix undefined reference to __ibt_endbr_seal[_end]

Due to the explicit 'noinline' GCC-7.3 is not able to optimize away the argument setup of:

	apply_ibt_endbr(__ibt_endbr_seal, __ibt_enbr_seal_end);

even when X86_KERNEL_IBT=n and the function is an empty stub which leads to link errors due to missing __ibt_endbr_seal* symbols like below:

ld: arch/x86/kernel/alternative.o: in function `alternative_instructions':
alternative.c:(.init.text+0x15d): undefined reference to `__ibt_endbr_seal_end'
ld: alternative.c:(.init.text+0x164): undefined reference to `__ibt_endbr_seal'

Remove explicit 'noinline' to help gcc optimize them away. [Thanks Peter Zijlstra for tweaking the commit log.]

---
 arch/x86/kernel/alternative.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/alternative.c +1 -1
index 5cadcea035e0..beaf9fc44e2f 100644
@@ -624,7 +624,7 @@ void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end)
 
 #else
 
-void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end) { }
+void __init_or_module apply_ibt_endbr(s32 *start, s32 *end) { }
 
 #endif /* CONFIG_X86_KERNEL_IBT */
 
Signature · 1 line
2.23.0
author
#1 lore raw
Quoted 15 lines · Miaohe Lin

Due to the explicit 'noinline' GCC-7.3 is not able to optimize away the argument setup of:

	apply_ibt_endbr(__ibt_endbr_seal, __ibt_enbr_seal_end);

even when X86_KERNEL_IBT=n and the function is an empty stub which leads to link errors due to missing __ibt_endbr_seal* symbols like below:

ld: arch/x86/kernel/alternative.o: in function `alternative_instructions':
alternative.c:(.init.text+0x15d): undefined reference to `__ibt_endbr_seal_end'
ld: alternative.c:(.init.text+0x164): undefined reference to `__ibt_endbr_seal'

Quoted 4 lines

Remove explicit 'noinline' to help gcc optimize them away. [Thanks Peter Zijlstra for tweaking the commit log.]

Add cc Peter Zijlstra.

Change log for v2:
Tweak the commit log per Peter Zijlstra. Thanks!

I should have done this in previous thread. Sorry for make noise.

Thanks,
Miaohe Lin

Quoted 18 lines
---
 arch/x86/kernel/alternative.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/alternative.c +1 -1
index 5cadcea035e0..beaf9fc44e2f 100644
@@ -624,7 +624,7 @@ void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end)
 
 #else
 
-void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end) { }
+void __init_or_module apply_ibt_endbr(s32 *start, s32 *end) { }
 
 #endif /* CONFIG_X86_KERNEL_IBT */
 
author
#2 lore raw
In reply to Miaohe Lin

Friendly ping ;)

Quoted 37 lines · Miaohe Lin

Due to the explicit 'noinline' GCC-7.3 is not able to optimize away the argument setup of:

	apply_ibt_endbr(__ibt_endbr_seal, __ibt_enbr_seal_end);

even when X86_KERNEL_IBT=n and the function is an empty stub which leads to link errors due to missing __ibt_endbr_seal* symbols like below:

ld: arch/x86/kernel/alternative.o: in function `alternative_instructions':
alternative.c:(.init.text+0x15d): undefined reference to `__ibt_endbr_seal_end'
ld: alternative.c:(.init.text+0x164): undefined reference to `__ibt_endbr_seal'

Remove explicit 'noinline' to help gcc optimize them away. [Thanks Peter Zijlstra for tweaking the commit log.]

---
 arch/x86/kernel/alternative.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/alternative.c +1 -1
index 5cadcea035e0..beaf9fc44e2f 100644
@@ -624,7 +624,7 @@ void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end)
 
 #else
 
-void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end) { }
+void __init_or_module apply_ibt_endbr(s32 *start, s32 *end) { }
 
 #endif /* CONFIG_X86_KERNEL_IBT */
 
#3 lore raw
In reply to Miaohe Lin
Quoted 8 lines · Miaohe Lin

Due to the explicit 'noinline' GCC-7.3 is not able to optimize away the argument setup of:

	apply_ibt_endbr(__ibt_endbr_seal, __ibt_enbr_seal_end);

even when X86_KERNEL_IBT=n and the function is an empty stub which leads to link errors due to missing __ibt_endbr_seal* symbols like below:

Quoted 6 lines

ld: arch/x86/kernel/alternative.o: in function `alternative_instructions':
alternative.c:(.init.text+0x15d): undefined reference to `__ibt_endbr_seal_end'
ld: alternative.c:(.init.text+0x164): undefined reference to `__ibt_endbr_seal'

This is incomplete because the noinline is only visible within alternative.c, but there is another caller in module.c

This needs an inline stub in the header to be correct.

Thanks,

tglx

author
#4 lore raw
Quoted 16 lines · Thomas Gleixner
Quoted 8 lines · Miaohe Lin

Due to the explicit 'noinline' GCC-7.3 is not able to optimize away the argument setup of:

	apply_ibt_endbr(__ibt_endbr_seal, __ibt_enbr_seal_end);

even when X86_KERNEL_IBT=n and the function is an empty stub which leads to link errors due to missing __ibt_endbr_seal* symbols like below:

Quoted 6 lines

ld: arch/x86/kernel/alternative.o: in function `alternative_instructions':
alternative.c:(.init.text+0x15d): undefined reference to `__ibt_endbr_seal_end'
ld: alternative.c:(.init.text+0x164): undefined reference to `__ibt_endbr_seal'

Quoted 5 lines

This is incomplete because the noinline is only visible within alternative.c, but there is another caller in module.c

This needs an inline stub in the header to be correct.

I see. I think I should update my gcc instead :) Thanks for your reply.

Thanks,
Miaohe Lin

merge bot Applied
#5 lore raw

[tip: x86/urgent] x86/alternative: Remove noinline from __ibt_endbr_seal[_end]() stubs

In reply to Miaohe Lin
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     023e59d4cee91dd3ca811eb01db2c5fb9f783dc2
Gitweb:        https://git.kernel.org/tip/023e59d4cee91dd3ca811eb01db2c5fb9f783dc2
Author:        Miaohe Lin <[email protected]>
AuthorDate:    Tue, 11 Oct 2022 19:38:03 +08:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Fri, 02 Dec 2022 12:54:43 +01:00

x86/alternative: Remove noinline from __ibt_endbr_seal[_end]() stubs

Due to the explicit 'noinline' GCC-7.3 is not able to optimize away the argument setup of:

	apply_ibt_endbr(__ibt_endbr_seal, __ibt_enbr_seal_end);

even when X86_KERNEL_IBT=n and the function is an empty stub, which leads to link errors due to missing __ibt_endbr_seal* symbols:

ld: arch/x86/kernel/alternative.o: in function `alternative_instructions':
alternative.c:(.init.text+0x15d): undefined reference to `__ibt_endbr_seal_end'
ld: alternative.c:(.init.text+0x164): undefined reference to `__ibt_endbr_seal'

Remove the explicit 'noinline' to help gcc optimize them away.

---
 arch/x86/kernel/alternative.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/alternative.c +1 -1
index 5cadcea..beaf9fc 100644
@@ -624,7 +624,7 @@ void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end)
 
 #else
 
-void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end) { }
+void __init_or_module apply_ibt_endbr(s32 *start, s32 *end) { }
 
 #endif /* CONFIG_X86_KERNEL_IBT */