Skip to contentSkip to conversation

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

PATCH Superseded Miaohe Lin 2 participants 5 messages Oct 9, 2022 – Oct 11, 2022 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

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

When I compile the kernel bzImage, there are several compile errors:

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'

It's because __ibt_endbr_seal and __ibt_endbr_seal_end are not optimized away when CONFIG_X86_KERNEL_IBT isn't enabled. Remove noinline attribute 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 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
#1 lore raw
Quoted 23 lines · Miaohe Lin

When I compile the kernel bzImage, there are several compile errors:

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'

It's because __ibt_endbr_seal and __ibt_endbr_seal_end are not optimized away when CONFIG_X86_KERNEL_IBT isn't enabled. Remove noinline attribute to help gcc optimize them away.

---
 arch/x86/kernel/alternative.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/alternative.c +0 -0
index 5cadcea035e0..beaf9fc44e2f 100644

arch/x86/kernel/alternative.c void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end) · line 630

Quoted 8 lines
arch/x86/kernel/alternative.c +1 -1
@@ -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 */
 

None of this makes any sense...

author
#2 lore raw
Quoted 27 lines · Peter Zijlstra
Quoted 26 lines · Miaohe Lin

When I compile the kernel bzImage, there are several compile errors:

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'

It's because __ibt_endbr_seal and __ibt_endbr_seal_end are not optimized away when CONFIG_X86_KERNEL_IBT isn't enabled. Remove noinline attribute to help gcc optimize them away.

---
 arch/x86/kernel/alternative.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/alternative.c +0 -0
index 5cadcea035e0..beaf9fc44e2f 100644
@@ -624,7 +624,7 @@ void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end)
 
 #else
 
Quoted 7 lines

arch/x86/kernel/alternative.c void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end) · line 630

Quoted 5 lines
arch/x86/kernel/alternative.c +1 -1
-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 */
 

None of this makes any sense...

This compile error occurs in my env when CONFIG_X86_KERNEL_IBT isn't enabled with gcc version 7.3.0 (GCC). And the generated assembly code looks like below:

0000000000000104 <alternative_instructions>:

 104:   e8 90 ff ff ff          callq  99 <int3_selftest>
 109:   e8 00 00 00 00          callq  10e <alternative_instructions+0xa>
 10e:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
 115:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
 11c:   e8 00 00 00 00          callq  121 <alternative_instructions+0x1d>
 121:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
 128:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
 12f:   e8 00 00 00 00          callq  134 <alternative_instructions+0x30>
 134:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
 13b:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
 142:   e8 00 00 00 00          callq  147 <alternative_instructions+0x43>
 147:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
 14e:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
 155:   e8 00 00 00 00          callq  15a <alternative_instructions+0x56>
Quoted 5 lines
15a:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
161:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
168:   e8 00 00 00 00          callq  16d <alternative_instructions+0x69>
16d:   83 3d 00 00 00 00 00    cmpl   $0x0,0x0(%rip)        # 174 <alternative_instructions+0x70>
174:   75 4a                   jne    1c0 <alternative_instructions+0xbc>

It seems the call to apply_ibt_endbr() is not optimized out when CONFIG_X86_KERNEL_IBT isn't enabled. And after the patch, the generated assembly code looks like below:

0000000000000104 <alternative_instructions>:

 104:   e8 90 ff ff ff          callq  99 <int3_selftest>
 109:   e8 00 00 00 00          callq  10e <alternative_instructions+0xa>
 10e:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
 115:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
 11c:   e8 00 00 00 00          callq  121 <alternative_instructions+0x1d>
 121:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
 128:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
 12f:   e8 00 00 00 00          callq  134 <alternative_instructions+0x30>
 134:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
 13b:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
 142:   e8 00 00 00 00          callq  147 <alternative_instructions+0x43>
 147:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
 14e:   48 c7 c7 00 00 00 00    mov    $0x0,%rdi
 155:   e8 00 00 00 00          callq  15a <alternative_instructions+0x56>
Quoted 2 lines
15a:   83 3d 00 00 00 00 00    cmpl   $0x0,0x0(%rip)        # 161 <alternative_instructions+0x5d>
161:   75 4a                   jne    1ad <alternative_instructions+0xa9>

The call to apply_ibt_endbr() is optimized out this time. Maybe it's the problem of gcc. But remove noinline attribute make compile works in my env. Am I miss something?

Thanks,
Miaohe Lin

Quoted 3 lines

.

#3 lore raw
Quoted 31 lines · Miaohe Lin
Quoted 30 lines · Peter Zijlstra
Quoted 29 lines · Miaohe Lin

When I compile the kernel bzImage, there are several compile errors:

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'

It's because __ibt_endbr_seal and __ibt_endbr_seal_end are not optimized away when CONFIG_X86_KERNEL_IBT isn't enabled. Remove noinline attribute 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 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) { }
 
Quoted 7 lines
Quoted 4 lines

arch/x86/kernel/alternative.c void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end) · line 630

Quoted 2 lines
arch/x86/kernel/alternative.c +0 -0
 #endif /* CONFIG_X86_KERNEL_IBT */
 

None of this makes any sense...

This compile error occurs in my env when CONFIG_X86_KERNEL_IBT isn't enabled with gcc version 7.3.0 (GCC).

*sigh*... geriatric GCC :/

Anyway; perhaps clarify the changelog to state something like:

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 -- leading to link errors due to missing __ibt_endbr_seal* symbols.

author
#4 lore raw
Quoted 37 lines · Peter Zijlstra
Quoted 36 lines · Miaohe Lin
Quoted 34 lines · Peter Zijlstra
Quoted 23 lines · Miaohe Lin

When I compile the kernel bzImage, there are several compile errors:

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'

It's because __ibt_endbr_seal and __ibt_endbr_seal_end are not optimized away when CONFIG_X86_KERNEL_IBT isn't enabled. Remove noinline attribute to help gcc optimize them away.

---
 arch/x86/kernel/alternative.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/alternative.c +0 -0
index 5cadcea035e0..beaf9fc44e2f 100644

arch/x86/kernel/alternative.c void __init_or_module noinline apply_ibt_endbr(s32 *start, s32 *end) · line 630

Quoted 8 lines
arch/x86/kernel/alternative.c +1 -1
@@ -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 */
 

None of this makes any sense...

Quoted 4 lines
Quoted 2 lines

This compile error occurs in my env when CONFIG_X86_KERNEL_IBT isn't enabled with gcc version 7.3.0 (GCC).

*sigh*... geriatric GCC :/

Yes, a geriatric GCC problem. :(

Quoted 10 lines

Anyway; perhaps clarify the changelog to state something like:

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 -- leading to link errors due to missing __ibt_endbr_seal* symbols.

Will do it in v2. Thanks for your suggestion and comment.

Thanks,
Miaohe Lin

Quoted 4 lines

.