Skip to content

Commit 8ffdaf9

Browse files
xzpeterbonzini
authored andcommitted
KVM: selftests: Fix build for evmcs.h
I got this error when building kvm selftests: /usr/bin/ld: /home/xz/git/linux/tools/testing/selftests/kvm/libkvm.a(vmx.o):/home/xz/git/linux/tools/testing/selftests/kvm/include/evmcs.h:222: multiple definition of `current_evmcs'; /tmp/cco1G48P.o:/home/xz/git/linux/tools/testing/selftests/kvm/include/evmcs.h:222: first defined here /usr/bin/ld: /home/xz/git/linux/tools/testing/selftests/kvm/libkvm.a(vmx.o):/home/xz/git/linux/tools/testing/selftests/kvm/include/evmcs.h:223: multiple definition of `current_vp_assist'; /tmp/cco1G48P.o:/home/xz/git/linux/tools/testing/selftests/kvm/include/evmcs.h:223: first defined here I think it's because evmcs.h is included both in a test file and a lib file so the structs have multiple declarations when linking. After all it's not a good habit to declare structs in the header files. Cc: Vitaly Kuznetsov <[email protected]> Signed-off-by: Peter Xu <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 139f742 commit 8ffdaf9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

tools/testing/selftests/kvm/include/evmcs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ struct hv_enlightened_vmcs {
219219
#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK \
220220
(~((1ull << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) - 1))
221221

222-
struct hv_enlightened_vmcs *current_evmcs;
223-
struct hv_vp_assist_page *current_vp_assist;
222+
extern struct hv_enlightened_vmcs *current_evmcs;
223+
extern struct hv_vp_assist_page *current_vp_assist;
224224

225225
int vcpu_enable_evmcs(struct kvm_vm *vm, int vcpu_id);
226226

tools/testing/selftests/kvm/lib/x86_64/vmx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
bool enable_evmcs;
1919

20+
struct hv_enlightened_vmcs *current_evmcs;
21+
struct hv_vp_assist_page *current_vp_assist;
22+
2023
struct eptPageTableEntry {
2124
uint64_t readable:1;
2225
uint64_t writable:1;

0 commit comments

Comments
 (0)