We can't have a source file with the same name that exist in both the
common code and in the arch specific code for efi/. This can lead to
comfusion in make and it can pick up the wrong source file. This issue
lead to a failure to build a pv-shim for x86 out-of-tree, as this is
one example of an x86 build using the efi/stub.c.
The issue is that in out-of-tree, make might find x86/efi/stub.c via
VPATH, but as the target needs to be rebuilt due to FORCE, make
actually avoid changing the source tree and rebuilt the target with
VPATH ignored, so $@ lead to the build tree where "stub.c" dosen't
exist yet so a link is made to "common/stub.c".
Rework the new common/stub.c file to have a different name than the
already existing one. And build both *stub.c as two different objects.
This mean we have to move some efi_compat_* aliases which are probably
useless for Arm.
Avoid using $(EFIOBJ-y) as an alias for $(clean-files), add
common_stub.c directly to $(clean-files).
Fixes: 7f96859b0d00 ("xen: reuse x86 EFI stub functions for Arm")
Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
For the cflag addition in non-ARM_EFI, I was tempted to apply it to
the whole directory instead of just stub.o. (Even if there's only a
single object). I think that would be enough to overwrite the
-fshort-wchar from efi-common.mk, but I forgot what cflags come after
that. But adding it to just one object mean that it's added at the
last possible moment.
---
xen/arch/arm/efi/Makefile | 8 ++------
xen/arch/x86/efi/Makefile | 2 +-
xen/common/efi/efi-common.mk | 4 ++--
xen/arch/x86/efi/stub.c | 7 -------
xen/common/efi/{stub.c => common_stub.c} | 6 ++++++
5 files changed, 11 insertions(+), 16 deletions(-)
rename xen/common/efi/{stub.c => common_stub.c} (67%)
diff --git a/xen/arch/arm/efi/Makefile b/xen/arch/arm/efi/Makefile
index bd954a3b2d..8e463d156a 100644
--- a/xen/arch/arm/efi/Makefile
+++ b/xen/arch/arm/efi/Makefile
@@ -4,12 +4,8 @@ ifeq ($(CONFIG_ARM_EFI),y)
obj-y += $(EFIOBJ-y)
obj-$(CONFIG_ACPI) += efi-dom0.init.o
else
-# Add stub.o to EFIOBJ-y to re-use the clean-files in
-# efi-common.mk. Otherwise the link of stub.c in arm/efi
-# will not be cleaned in "make clean".
-EFIOBJ-y += stub.o
-obj-y += stub.o
+obj-y += common_stub.o
-$(obj)/stub.o: CFLAGS-y += -fno-short-wchar
+$(obj)/common_stub.o: CFLAGS-y += -fno-short-wchar
endif
diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile
index 034ec87895..bbabfc3795 100644
--- a/xen/arch/x86/efi/Makefile
+++ b/xen/arch/x86/efi/Makefile
@@ -11,7 +11,7 @@ $(obj)/boot.init.o: $(obj)/buildid.o
$(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary=4)
$(addprefix $(obj)/,$(EFIOBJ-y)): CFLAGS_stack_boundary := $(cflags-stack-boundary)
-obj-y := stub.o
+obj-y := common_stub.o stub.o
obj-$(XEN_BUILD_EFI) := $(filter-out %.init.o,$(EFIOBJ-y))
obj-bin-$(XEN_BUILD_EFI) := $(filter %.init.o,$(EFIOBJ-y))
extra-$(XEN_BUILD_EFI) += buildid.o relocs-dummy.o
diff --git a/xen/common/efi/efi-common.mk b/xen/common/efi/efi-common.mk
index ec2c34f198..5d5c427e8b 100644
--- a/xen/common/efi/efi-common.mk
+++ b/xen/common/efi/efi-common.mk
@@ -9,9 +9,9 @@ CFLAGS-y += -iquote $(srcdir)
# e.g.: It transforms "dir/foo/bar" into successively
# "dir foo bar", ".. .. ..", "../../.."
$(obj)/%.c: $(srctree)/common/efi/%.c FORCE
- $(Q)test -f $@ || \
- ln -nfs $(subst $(space),/,$(patsubst %,..,$(subst /, ,$(obj))))/source/common/efi/$(<F) $@
+ $(Q)ln -nfs $(subst $(space),/,$(patsubst %,..,$(subst /, ,$(obj))))/source/common/efi/$(<F) $@
clean-files += $(patsubst %.o, %.c, $(EFIOBJ-y:.init.o=.o) $(EFIOBJ-))
+clean-files += common_stub.c
.PRECIOUS: $(obj)/%.c
diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c
index f2365bc041..2cd5c8d4dc 100644
--- a/xen/arch/x86/efi/stub.c
+++ b/xen/arch/x86/efi/stub.c
@@ -8,7 +8,6 @@
#include <efi/eficon.h>
#include <efi/efidevp.h>
#include <efi/efiapi.h>
-#include "../../../common/efi/stub.c"
/*
* Here we are in EFI stub. EFI calls are not supported due to lack
@@ -55,9 +54,3 @@ bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
}
void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
-
-int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *)
- __attribute__((__alias__("efi_get_info")));
-
-int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *)
- __attribute__((__alias__("efi_runtime_call")));
diff --git a/xen/common/efi/stub.c b/xen/common/efi/common_stub.c
similarity index 67%
rename from xen/common/efi/stub.c
rename to xen/common/efi/common_stub.c
index 15694632c2..4dc724b2ac 100644
--- a/xen/common/efi/stub.c
+++ b/xen/common/efi/common_stub.c
@@ -30,3 +30,9 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
{
return -ENOSYS;
}
+
+int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *)
+ __attribute__((__alias__("efi_get_info")));
+
+int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *)
+ __attribute__((__alias__("efi_runtime_call")));
--
Anthony PERARD
common code and in the arch specific code for efi/. This can lead to
comfusion in make and it can pick up the wrong source file. This issue
lead to a failure to build a pv-shim for x86 out-of-tree, as this is
one example of an x86 build using the efi/stub.c.
The issue is that in out-of-tree, make might find x86/efi/stub.c via
VPATH, but as the target needs to be rebuilt due to FORCE, make
actually avoid changing the source tree and rebuilt the target with
VPATH ignored, so $@ lead to the build tree where "stub.c" dosen't
exist yet so a link is made to "common/stub.c".
Rework the new common/stub.c file to have a different name than the
already existing one. And build both *stub.c as two different objects.
This mean we have to move some efi_compat_* aliases which are probably
useless for Arm.
Avoid using $(EFIOBJ-y) as an alias for $(clean-files), add
common_stub.c directly to $(clean-files).
Fixes: 7f96859b0d00 ("xen: reuse x86 EFI stub functions for Arm")
Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
For the cflag addition in non-ARM_EFI, I was tempted to apply it to
the whole directory instead of just stub.o. (Even if there's only a
single object). I think that would be enough to overwrite the
-fshort-wchar from efi-common.mk, but I forgot what cflags come after
that. But adding it to just one object mean that it's added at the
last possible moment.
---
xen/arch/arm/efi/Makefile | 8 ++------
xen/arch/x86/efi/Makefile | 2 +-
xen/common/efi/efi-common.mk | 4 ++--
xen/arch/x86/efi/stub.c | 7 -------
xen/common/efi/{stub.c => common_stub.c} | 6 ++++++
5 files changed, 11 insertions(+), 16 deletions(-)
rename xen/common/efi/{stub.c => common_stub.c} (67%)
diff --git a/xen/arch/arm/efi/Makefile b/xen/arch/arm/efi/Makefile
index bd954a3b2d..8e463d156a 100644
--- a/xen/arch/arm/efi/Makefile
+++ b/xen/arch/arm/efi/Makefile
@@ -4,12 +4,8 @@ ifeq ($(CONFIG_ARM_EFI),y)
obj-y += $(EFIOBJ-y)
obj-$(CONFIG_ACPI) += efi-dom0.init.o
else
-# Add stub.o to EFIOBJ-y to re-use the clean-files in
-# efi-common.mk. Otherwise the link of stub.c in arm/efi
-# will not be cleaned in "make clean".
-EFIOBJ-y += stub.o
-obj-y += stub.o
+obj-y += common_stub.o
-$(obj)/stub.o: CFLAGS-y += -fno-short-wchar
+$(obj)/common_stub.o: CFLAGS-y += -fno-short-wchar
endif
diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile
index 034ec87895..bbabfc3795 100644
--- a/xen/arch/x86/efi/Makefile
+++ b/xen/arch/x86/efi/Makefile
@@ -11,7 +11,7 @@ $(obj)/boot.init.o: $(obj)/buildid.o
$(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary=4)
$(addprefix $(obj)/,$(EFIOBJ-y)): CFLAGS_stack_boundary := $(cflags-stack-boundary)
-obj-y := stub.o
+obj-y := common_stub.o stub.o
obj-$(XEN_BUILD_EFI) := $(filter-out %.init.o,$(EFIOBJ-y))
obj-bin-$(XEN_BUILD_EFI) := $(filter %.init.o,$(EFIOBJ-y))
extra-$(XEN_BUILD_EFI) += buildid.o relocs-dummy.o
diff --git a/xen/common/efi/efi-common.mk b/xen/common/efi/efi-common.mk
index ec2c34f198..5d5c427e8b 100644
--- a/xen/common/efi/efi-common.mk
+++ b/xen/common/efi/efi-common.mk
@@ -9,9 +9,9 @@ CFLAGS-y += -iquote $(srcdir)
# e.g.: It transforms "dir/foo/bar" into successively
# "dir foo bar", ".. .. ..", "../../.."
$(obj)/%.c: $(srctree)/common/efi/%.c FORCE
- $(Q)test -f $@ || \
- ln -nfs $(subst $(space),/,$(patsubst %,..,$(subst /, ,$(obj))))/source/common/efi/$(<F) $@
+ $(Q)ln -nfs $(subst $(space),/,$(patsubst %,..,$(subst /, ,$(obj))))/source/common/efi/$(<F) $@
clean-files += $(patsubst %.o, %.c, $(EFIOBJ-y:.init.o=.o) $(EFIOBJ-))
+clean-files += common_stub.c
.PRECIOUS: $(obj)/%.c
diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c
index f2365bc041..2cd5c8d4dc 100644
--- a/xen/arch/x86/efi/stub.c
+++ b/xen/arch/x86/efi/stub.c
@@ -8,7 +8,6 @@
#include <efi/eficon.h>
#include <efi/efidevp.h>
#include <efi/efiapi.h>
-#include "../../../common/efi/stub.c"
/*
* Here we are in EFI stub. EFI calls are not supported due to lack
@@ -55,9 +54,3 @@ bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
}
void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
-
-int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *)
- __attribute__((__alias__("efi_get_info")));
-
-int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *)
- __attribute__((__alias__("efi_runtime_call")));
diff --git a/xen/common/efi/stub.c b/xen/common/efi/common_stub.c
similarity index 67%
rename from xen/common/efi/stub.c
rename to xen/common/efi/common_stub.c
index 15694632c2..4dc724b2ac 100644
--- a/xen/common/efi/stub.c
+++ b/xen/common/efi/common_stub.c
@@ -30,3 +30,9 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
{
return -ENOSYS;
}
+
+int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *)
+ __attribute__((__alias__("efi_get_info")));
+
+int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *)
+ __attribute__((__alias__("efi_runtime_call")));
--
Anthony PERARD