[V2] tools/virtio: fix build break for aarch64

Message ID 20230323040024.3809108-1-peng.fan@oss.nxp.com
State New
Headers
Series [V2] tools/virtio: fix build break for aarch64 |

Commit Message

Peng Fan (OSS) March 23, 2023, 4 a.m. UTC
  From: Peng Fan <peng.fan@nxp.com>

"-mfunction-return=thunk -mindirect-branch-register" are only valid
for x86. So introduce compiler operation check to avoid such issues

Fixes: 0d0ed4006127 ("tools/virtio: enable to build with retpoline")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---

V2:
 Use /dev/null as output dest
 Move call cc-option to the original CFLAGS

 tools/virtio/Makefile | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
  

Comments

Peng Fan April 20, 2023, 3:35 a.m. UTC | #1
> Subject: [PATCH V2] tools/virtio: fix build break for aarch64

Ping...

Thanks,
Peng.

> 
> From: Peng Fan <peng.fan@nxp.com>
> 
> "-mfunction-return=thunk -mindirect-branch-register" are only valid for x86.
> So introduce compiler operation check to avoid such issues
> 
> Fixes: 0d0ed4006127 ("tools/virtio: enable to build with retpoline")
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
> 
> V2:
>  Use /dev/null as output dest
>  Move call cc-option to the original CFLAGS
> 
>  tools/virtio/Makefile | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/virtio/Makefile b/tools/virtio/Makefile index
> 7b7139d97d74..d128925980e0 100644
> --- a/tools/virtio/Makefile
> +++ b/tools/virtio/Makefile
> @@ -4,7 +4,18 @@ test: virtio_test vringh_test
>  virtio_test: virtio_ring.o virtio_test.o
>  vringh_test: vringh_test.o vringh.o virtio_ring.o
> 
> -CFLAGS += -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I. -I../include/ -
> I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing
> -fno-common -MMD -U_FORTIFY_SOURCE -
> include ../../include/linux/kconfig.h -mfunction-return=thunk -fcf-
> protection=none -mindirect-branch-register
> +try-run = $(shell set -e;		\
> +	if ($(1)) >/dev/null 2>&1;	\
> +	then echo "$(2)";		\
> +	else echo "$(3)";		\
> +	fi)
> +
> +__cc-option = $(call try-run,\
> +	$(1) -Werror $(2) -c -x c /dev/null -o /dev/null,$(2),) cc-option =
> +$(call __cc-option, $(CC),$(1))
> +
> +CFLAGS += -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I.
> +-I../include/ -I ../../usr/include/ -Wno-pointer-sign
> +-fno-strict-overflow -fno-strict-aliasing -fno-common -MMD
> +-U_FORTIFY_SOURCE -include ../../include/linux/kconfig.h $(call
> +cc-option,-mfunction-return=thunk) $(call
> +cc-option,-fcf-protection=none) $(call
> +cc-option,-mindirect-branch-register)
> +
>  CFLAGS += -pthread
>  LDFLAGS += -pthread
>  vpath %.c ../../drivers/virtio ../../drivers/vhost
> --
> 2.37.1
  
Peng Fan (OSS) May 5, 2023, 2:37 a.m. UTC | #2
Any comments?

Thanks,
Peng.

On 4/20/2023 11:35 AM, Peng Fan wrote:
>> Subject: [PATCH V2] tools/virtio: fix build break for aarch64
> 
> Ping...
> 
> Thanks,
> Peng.
> 
>>
>> From: Peng Fan <peng.fan@nxp.com>
>>
>> "-mfunction-return=thunk -mindirect-branch-register" are only valid for x86.
>> So introduce compiler operation check to avoid such issues
>>
>> Fixes: 0d0ed4006127 ("tools/virtio: enable to build with retpoline")
>> Signed-off-by: Peng Fan <peng.fan@nxp.com>
>> ---
>>
>> V2:
>>   Use /dev/null as output dest
>>   Move call cc-option to the original CFLAGS
>>
>>   tools/virtio/Makefile | 13 ++++++++++++-
>>   1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/virtio/Makefile b/tools/virtio/Makefile index
>> 7b7139d97d74..d128925980e0 100644
>> --- a/tools/virtio/Makefile
>> +++ b/tools/virtio/Makefile
>> @@ -4,7 +4,18 @@ test: virtio_test vringh_test
>>   virtio_test: virtio_ring.o virtio_test.o
>>   vringh_test: vringh_test.o vringh.o virtio_ring.o
>>
>> -CFLAGS += -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I. -I../include/ -
>> I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing
>> -fno-common -MMD -U_FORTIFY_SOURCE -
>> include ../../include/linux/kconfig.h -mfunction-return=thunk -fcf-
>> protection=none -mindirect-branch-register
>> +try-run = $(shell set -e;		\
>> +	if ($(1)) >/dev/null 2>&1;	\
>> +	then echo "$(2)";		\
>> +	else echo "$(3)";		\
>> +	fi)
>> +
>> +__cc-option = $(call try-run,\
>> +	$(1) -Werror $(2) -c -x c /dev/null -o /dev/null,$(2),) cc-option =
>> +$(call __cc-option, $(CC),$(1))
>> +
>> +CFLAGS += -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I.
>> +-I../include/ -I ../../usr/include/ -Wno-pointer-sign
>> +-fno-strict-overflow -fno-strict-aliasing -fno-common -MMD
>> +-U_FORTIFY_SOURCE -include ../../include/linux/kconfig.h $(call
>> +cc-option,-mfunction-return=thunk) $(call
>> +cc-option,-fcf-protection=none) $(call
>> +cc-option,-mindirect-branch-register)
>> +
>>   CFLAGS += -pthread
>>   LDFLAGS += -pthread
>>   vpath %.c ../../drivers/virtio ../../drivers/vhost
>> --
>> 2.37.1
>
  
Xuan Zhuo May 8, 2023, 3:07 a.m. UTC | #3
On Thu, 23 Mar 2023 12:00:24 +0800, "Peng Fan (OSS)" <peng.fan@oss.nxp.com> wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> "-mfunction-return=thunk -mindirect-branch-register" are only valid
> for x86. So introduce compiler operation check to avoid such issues
>
> Fixes: 0d0ed4006127 ("tools/virtio: enable to build with retpoline")
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>
> V2:
>  Use /dev/null as output dest
>  Move call cc-option to the original CFLAGS
>
>  tools/virtio/Makefile | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/tools/virtio/Makefile b/tools/virtio/Makefile
> index 7b7139d97d74..d128925980e0 100644
> --- a/tools/virtio/Makefile
> +++ b/tools/virtio/Makefile
> @@ -4,7 +4,18 @@ test: virtio_test vringh_test
>  virtio_test: virtio_ring.o virtio_test.o
>  vringh_test: vringh_test.o vringh.o virtio_ring.o
>
> -CFLAGS += -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I. -I../include/ -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -include ../../include/linux/kconfig.h -mfunction-return=thunk -fcf-protection=none -mindirect-branch-register
> +try-run = $(shell set -e;		\
> +	if ($(1)) >/dev/null 2>&1;	\
> +	then echo "$(2)";		\
> +	else echo "$(3)";		\
> +	fi)
> +
> +__cc-option = $(call try-run,\
> +	$(1) -Werror $(2) -c -x c /dev/null -o /dev/null,$(2),)
> +cc-option = $(call __cc-option, $(CC),$(1))

Can we sqush these to one function?

> +
> +CFLAGS += -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I. -I../include/ -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -include ../../include/linux/kconfig.h $(call cc-option,-mfunction-return=thunk) $(call cc-option,-fcf-protection=none) $(call cc-option,-mindirect-branch-register)

nit: this line is too long. Can we split it?

Thanks.

> +
>  CFLAGS += -pthread
>  LDFLAGS += -pthread
>  vpath %.c ../../drivers/virtio ../../drivers/vhost
> --
> 2.37.1
>
  

Patch

diff --git a/tools/virtio/Makefile b/tools/virtio/Makefile
index 7b7139d97d74..d128925980e0 100644
--- a/tools/virtio/Makefile
+++ b/tools/virtio/Makefile
@@ -4,7 +4,18 @@  test: virtio_test vringh_test
 virtio_test: virtio_ring.o virtio_test.o
 vringh_test: vringh_test.o vringh.o virtio_ring.o
 
-CFLAGS += -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I. -I../include/ -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -include ../../include/linux/kconfig.h -mfunction-return=thunk -fcf-protection=none -mindirect-branch-register
+try-run = $(shell set -e;		\
+	if ($(1)) >/dev/null 2>&1;	\
+	then echo "$(2)";		\
+	else echo "$(3)";		\
+	fi)
+
+__cc-option = $(call try-run,\
+	$(1) -Werror $(2) -c -x c /dev/null -o /dev/null,$(2),)
+cc-option = $(call __cc-option, $(CC),$(1))
+
+CFLAGS += -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I. -I../include/ -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -include ../../include/linux/kconfig.h $(call cc-option,-mfunction-return=thunk) $(call cc-option,-fcf-protection=none) $(call cc-option,-mindirect-branch-register)
+
 CFLAGS += -pthread
 LDFLAGS += -pthread
 vpath %.c ../../drivers/virtio ../../drivers/vhost