Skip to content

Commit 0fd84f7

Browse files
executor: apply optnone to guest_handle_nested_vmentry_intel()
Florent Revest reported ThinLTO builds failing with the following error: <inline asm>:2:1: error: symbol 'after_vmentry_label' is already defined after_vmentry_label: ^ error: cannot compile inline asm , which turned out to be caused by the compiler not respecting `noinline`. Adding __attribute__((optnone)) (or optimize("O0") on GCC) fixes the issue.
1 parent d1b870e commit 0fd84f7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

executor/common_kvm_amd64_syzos.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,10 @@ guest_handle_nested_load_code(struct api_call_nested_load_code* cmd, uint64 cpu_
11511151
}
11521152
}
11531153

1154-
GUEST_CODE static noinline void
1154+
// Clang's LTO may ignore noinline and attempt to inline this function into both callers,
1155+
// which results in duplicate declaration of after_vmentry_label.
1156+
// Applying __optnone should prevent this behavior.
1157+
GUEST_CODE static noinline __optnone void
11551158
guest_handle_nested_vmentry_intel(uint64 vm_id, uint64 cpu_id, bool is_launch)
11561159
{
11571160
uint64 vmx_error_code = 0;

executor/common_kvm_syzos.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,19 @@
3535
#define __addrspace_guest
3636
#endif
3737

38+
// Disable optimizations for a particular function.
39+
#if defined(__clang__)
40+
#define __optnone __attribute__((optnone))
41+
#elif defined(__GNUC__)
42+
#define __optnone __attribute__((optimize("O0")))
43+
#else
44+
#define __optnone
45+
#endif
46+
3847
// Host will map the code in this section into the guest address space.
3948
#define GUEST_CODE __attribute__((section("guest"))) __no_stack_protector __addrspace_guest
4049

4150
// Start/end of the guest section.
4251
extern char *__start_guest, *__stop_guest;
4352

44-
#endif // EXECUTOR_COMMON_KVM_SYZOS_H
53+
#endif // EXECUTOR_COMMON_KVM_SYZOS_H

0 commit comments

Comments
 (0)