Skip to contentSkip to conversation

Xen: fix EFI stub wchar_t size warning of arm32 building

PATCH Superseded Wei Chen 3 participants 4 messages Jul 1, 2022 – Jul 4, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Chen

author
#0 lore raw

PATCH 1/1 Xen: fix EFI stub wchar_t size warning of arm32 building

Xen uses "-fshort-wchar" in CFLAGS for EFI common code. Arm32 is using stub.c of EFI common code for EFI stub functions. But "-fshort-wchar" CFLAG will cause a warning when build stub.c for Arm32:
"arm-linux-gnueabihf-ld: warning: arch/arm/efi/built_in.o uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail"

This is because the "-fshort-wchar" flag causes GCC to generate code that is not binary compatible with code generated without that flag. Why this warning hasn't been triggered in Arm64 is because Arm64 does not use wchar type directly in any code for parameters, variables and return values. And in EFI code, wchar has been replaced by CHAR16 (the UEFI "abstraction" of wchar_t). CHAR16 has been specified as unsigned short type in typedef, the "-fshort-wchar" flag will not affect CHAR16. So Arm64 object files are exactly the same with "-fshort-wchar" and without "-fshort-wchar".

We are also not using wchar in Arm32 codes, but Arm32 will embed ABI information in ".ARM.attributes" section. This section stores some object file attributes, like ABI version, CPU arch and etc. And wchar size is described in this section by "Tag_ABI_PCS_wchar_t" too. Tag_ABI_PCS_wchar_t is 2 for object files with "-fshort-wchar", but for object files without "-fshort-wchar" is 4. Arm32 GCC ld will check this tag, and throw above warning when it finds the object files have different Tag_ABI_PCS_wchar_t values.

As gnu-efi-3.0 use the GCC option "-fshort-wchar" to force wchar to use short integers (2 bytes) instead of integers (4 bytes). So keep "-fshort-wchar" for Xen EFI code is reasonable. So in this patch, we add "-fno-short-wchar" to override "-fshort-wchar" for Arm32 to remove above warning.

---
 xen/arch/arm/efi/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
xen/arch/arm/efi/Makefile +4 -0
index dffe72e589..b06fb96c1f 100644
@@ -1,5 +1,9 @@
 include $(srctree)/common/efi/efi-common.mk
 
+ifeq ($(CONFIG_ARM_32),y)
+CFLAGS-y += -fno-short-wchar
+endif
+
 ifeq ($(CONFIG_ARM_EFI),y)
 obj-y += $(EFIOBJ-y)
 obj-$(CONFIG_ACPI) +=  efi-dom0.init.o
Signature · 1 line
2.25.1
#1 lore raw
Quoted 28 lines · Wei Chen

Xen uses "-fshort-wchar" in CFLAGS for EFI common code. Arm32 is using stub.c of EFI common code for EFI stub functions. But "-fshort-wchar" CFLAG will cause a warning when build stub.c for Arm32:
"arm-linux-gnueabihf-ld: warning: arch/arm/efi/built_in.o uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail"

This is because the "-fshort-wchar" flag causes GCC to generate code that is not binary compatible with code generated without that flag. Why this warning hasn't been triggered in Arm64 is because Arm64 does not use wchar type directly in any code for parameters, variables and return values. And in EFI code, wchar has been replaced by CHAR16 (the UEFI "abstraction" of wchar_t). CHAR16 has been specified as unsigned short type in typedef, the "-fshort-wchar" flag will not affect CHAR16. So Arm64 object files are exactly the same with "-fshort-wchar" and without "-fshort-wchar".

We are also not using wchar in Arm32 codes, but Arm32 will embed ABI information in ".ARM.attributes" section. This section stores some object file attributes, like ABI version, CPU arch and etc. And wchar size is described in this section by "Tag_ABI_PCS_wchar_t" too. Tag_ABI_PCS_wchar_t is 2 for object files with "-fshort-wchar", but for object files without "-fshort-wchar" is 4. Arm32 GCC ld will check this tag, and throw above warning when it finds the object files have different Tag_ABI_PCS_wchar_t values.

Quoted 7 lines

As gnu-efi-3.0 use the GCC option "-fshort-wchar" to force wchar to use short integers (2 bytes) instead of integers (4 bytes). So keep "-fshort-wchar" for Xen EFI code is reasonable. So in this patch, we add "-fno-short-wchar" to override "-fshort-wchar" for Arm32 to remove above warning.

Reported-and-Suggested-by Jan Beulich <[email protected]>

Interesting new tag (but why not).

Quoted 10 lines
---
 xen/arch/arm/efi/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
xen/arch/arm/efi/Makefile +0 -0
index dffe72e589..b06fb96c1f 100644

xen/arch/arm/efi/Makefile line 5

Quoted 5 lines
xen/arch/arm/efi/Makefile +3 -0
@@ -1,5 +1,9 @@
 include $(srctree)/common/efi/efi-common.mk
 
+ifeq ($(CONFIG_ARM_32),y)
+CFLAGS-y += -fno-short-wchar
+endif

Simply

CFLAGS-$(CONFIG_ARM_32) += -fno-short-wchar

? But, as suggested, perhaps further

$(obj)/stub.o: CFLAGS-$(CONFIG_ARM_32) += -fno-short-wchar

to make sure we'd notice any other uses / issues here. After all it is - at least in theory - possible that Arm32 would also gain EFI support, and then it would be a problem if the other ("real") files were compiled that way (albeit I think the issue would be easily noticeable, as I don't think things would build that way).

Jan

#2 lore raw
Quoted 22 lines · Jan Beulich
Quoted 10 lines
---
  xen/arch/arm/efi/Makefile | 4 ++++
  1 file changed, 4 insertions(+)
xen/arch/arm/efi/Makefile +0 -0
index dffe72e589..b06fb96c1f 100644

xen/arch/arm/efi/Makefile line 5

Quoted 5 lines
xen/arch/arm/efi/Makefile +3 -0
@@ -1,5 +1,9 @@
  include $(srctree)/common/efi/efi-common.mk
 
+ifeq ($(CONFIG_ARM_32),y)
+CFLAGS-y += -fno-short-wchar
+endif

Simply

CFLAGS-$(CONFIG_ARM_32) += -fno-short-wchar

? But, as suggested, perhaps further

Quoted 7 lines

$(obj)/stub.o: CFLAGS-$(CONFIG_ARM_32) += -fno-short-wchar

to make sure we'd notice any other uses / issues here. After all it is - at least in theory - possible that Arm32 would also gain EFI support, and then it would be a problem if the other ("real") files were compiled that way (albeit I think the issue would be easily noticeable, as I don't think things would build that way).

Instead of CONFIG_ARM_32, I would use CONFIG_ARM_EFI. So this would also work if we want to disable EFI on arm64 or enable on arm32.

Cheers,

Signature · 1 line
Julien Grall
author
#3 lore raw

Hi Julien,

Quoted 37 lines

-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 2022年7月1日 20:58
To: Jan Beulich <[email protected]>; Wei Chen <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Bertrand Marquis <[email protected]>; Volodymyr Babchuk <[email protected]>; [email protected]
Subject: Re: [PATCH] Xen: fix EFI stub wchar_t size warning of arm32 building

Quoted 24 lines · Jan Beulich
Quoted 10 lines
---
  xen/arch/arm/efi/Makefile | 4 ++++
  1 file changed, 4 insertions(+)
xen/arch/arm/efi/Makefile +0 -0
index dffe72e589..b06fb96c1f 100644

xen/arch/arm/efi/Makefile line 5

Quoted 5 lines
xen/arch/arm/efi/Makefile +3 -0
@@ -1,5 +1,9 @@
  include $(srctree)/common/efi/efi-common.mk
 
+ifeq ($(CONFIG_ARM_32),y)
+CFLAGS-y += -fno-short-wchar
+endif

Simply

CFLAGS-$(CONFIG_ARM_32) += -fno-short-wchar

? But, as suggested, perhaps further

$(obj)/stub.o: CFLAGS-$(CONFIG_ARM_32) += -fno-short-wchar

Quoted 9 lines
Quoted 5 lines

to make sure we'd notice any other uses / issues here. After all it is - at least in theory - possible that Arm32 would also gain EFI support, and then it would be a problem if the other ("real") files were compiled that way (albeit I think the issue would be easily noticeable, as I don't think things would build that way).

Instead of CONFIG_ARM_32, I would use CONFIG_ARM_EFI. So this would also work if we want to disable EFI on arm64 or enable on arm32.

We have already used CONFIG_ARM_EFI to distinguish EFI objects and stub objects for Arm, so maybe we just need to add "$(obj)/stub.o: CFLAGS-y += -fno-short-wchar" to:

ifeq ($(CONFIG_ARM_EFI),y)
..
else
...
$(obj)/stub.o: CFLAGS-y += -fno-short-wchar
obj-y += stub.o
endif

Thanks,
Wei Chen

Quoted 4 lines

Cheers,

--
Julien Grall