Skip to contentSkip to conversation

build: check functionality rather than binutils version

PATCH Superseded Bruce Richardson 3 participants 9 messages Jun 17, 2020 – Jul 5, 2020 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: check functionality rather than binutils version

Rather than checking the binutils version number, which can lead to unnecessary disabling of AVX512 if fixes have been backported to distro versions, we can instead check the output of "as" from binutils to see if it is correct.

These checks use the minimal assembly reproduction code posted to the public bug tracker for gcc/binutils for those issues [1][2]. If the binutils bug is present, the instruction parameters - specifically the displacement parameter - will be different in the disassembled output compared to the input. Therefore each check involves assembling a single instruction and disassembling it again, checking that the two match.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=23465

---
 buildtools/binutils-avx512-check.sh | 26 ++++++++++++++++++++++++++
 buildtools/meson.build              |  3 +--
 config/x86/meson.build              | 10 +++-------
 meson.build                         |  5 ++++-
 4 files changed, 34 insertions(+), 10 deletions(-)
 create mode 100755 buildtools/binutils-avx512-check.sh
buildtools/binutils-avx512-check.sh new file +26 -0
new file mode 100755
index 000000000..1e894d84d
@@ -0,0 +1,26 @@
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+AS=${AS:-as}
+MESON_BUILD_ROOT=${MESON_BUILD_ROOT:-/tmp}
+OBJFILE=$MESON_BUILD_ROOT/binutils-avx512-check.o
+# from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
+GATHER_PARAMS='0x8(,%ymm1,1),%ymm0{%k2}'
+# from https://sourceware.org/bugzilla/show_bug.cgi?id=23465
+MOVAPS_PARAMS='0x40(,%rax,1),%zmm0'
+
+# assemble vmovaps statement to file
+echo "vmovaps $MOVAPS_PARAMS" | $AS --64 -o $OBJFILE -
+# check the parameters are correct in the output, using objdump
+objdump -d  --no-show-raw-insn $OBJFILE | grep -q $MOVAPS_PARAMS || {
+	echo "vmovaps displacement error with as"
+	exit 1
+}
+
+# assemble vpgather to file and similarly check
+echo "vpgatherqq $GATHER_PARAMS" | $AS --64 -o $OBJFILE -
+objdump -d  --no-show-raw-insn $OBJFILE | grep -q $GATHER_PARAMS || {
+	echo "vpgatherqq displacement error with as"
+	exit 1
+}
buildtools/meson.build +1 -2
index d5f8291be..73a847c52 100644
@@ -1,13 +1,12 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017-2019 Intel Corporation
 
-subdir('pmdinfogen')
-
 pkgconf = find_program('pkg-config', 'pkgconf', required: false)
 pmdinfo = find_program('gen-pmdinfo-cfile.sh')
 list_dir_globs = find_program('list-dir-globs.py')
 check_symbols = find_program('check-symbols.sh')
 ldflags_ibverbs_static = find_program('options-ibverbs-static.sh')
+binutils_avx512_check = find_program('binutils-avx512-check.sh')
 
 # set up map-to-def script using python, either built-in or external
 python3 = import('python').find_installation(required: false)
config/x86/meson.build +3 -7
index adc857ba2..fbcd8e455 100644
@@ -3,14 +3,10 @@
 
 # get binutils version for the workaround of Bug 97
 if not is_windows
-	ldver = run_command('ld', '-v').stdout().strip()
-	if ldver.contains('2.30') and cc.has_argument('-mno-avx512f')
+	as_ok = run_command(binutils_avx512_check)
+	if as_ok.returncode() != 0 and cc.has_argument('-mno-avx512f')
 		machine_args += '-mno-avx512f'
-		message('Binutils 2.30 detected, disabling AVX512 support as workaround for bug #97')
-	endif
-	if ldver.contains('2.31') and cc.has_argument('-mno-avx512f')
-		machine_args += '-mno-avx512f'
-		message('Binutils 2.31 detected, disabling AVX512 support as workaround for bug #249')
+		message('Binutils error with AVX512 assembly, disabling AVX512 support')
 	endif
 endif
 
meson.build +4 -1
index 750fdeab1..ab4d60cfa 100644
@@ -41,10 +41,13 @@ global_inc = include_directories('.', 'config',
 	'lib/librte_eal/@0@/include'.format(host_machine.system()),
 	'lib/librte_eal/@0@/include'.format(arch_subdir),
 )
+
+# do configuration and get tool paths
+subdir('buildtools')
 subdir('config')
 
 # build libs and drivers
-subdir('buildtools')
+subdir('buildtools/pmdinfogen')
 subdir('lib')
 subdir('drivers')
 
Signature · 1 line
2.25.1
#1 lore raw

17/06/2020 12:40, Bruce Richardson:

Quoted 11 lines

Rather than checking the binutils version number, which can lead to unnecessary disabling of AVX512 if fixes have been backported to distro versions, we can instead check the output of "as" from binutils to see if it is correct.

These checks use the minimal assembly reproduction code posted to the public bug tracker for gcc/binutils for those issues [1][2]. If the binutils bug is present, the instruction parameters - specifically the displacement parameter - will be different in the disassembled output compared to the input. Therefore each check involves assembling a single instruction and disassembling it again, checking that the two match.

Whaoh, that's a very specific optimization :) Which distro is affected (backported binutils fix)?

buildtools/meson.build line 4

Quoted 8 lines

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=23465

---

buildtools/meson.build +0 -1
-subdir('pmdinfogen')

Why removing pmdinfogen?

meson.build global_inc = include_directories('.', 'config', · line 50

Quoted 9 lines
meson.build +3 -1
+# do configuration and get tool paths
+subdir('buildtools')
 subdir('config')
 
 # build libs and drivers
-subdir('buildtools')
+subdir('buildtools/pmdinfogen')

Is it related to binutils check?

[...]

meson.build

Quoted 4 lines
meson.build +2 -2
-	ldver = run_command('ld', '-v').stdout().strip()
-	if ldver.contains('2.30') and cc.has_argument('-mno-avx512f')
+	as_ok = run_command(binutils_avx512_check)
+	if as_ok.returncode() != 0 and cc.has_argument('-mno-avx512f')

"as_ok" is difficult to understand.
I would suggest "binutils_avx512_ok".

meson.build

Quoted 1 line
meson.build +1 -0
+		message('Binutils error with AVX512 assembly, disabling AVX512 support')

It looks like something which should be part of meson itself.

#2 lore raw
Quoted 13 lines · Thomas Monjalon

17/06/2020 12:40, Bruce Richardson:

Quoted 11 lines

Rather than checking the binutils version number, which can lead to unnecessary disabling of AVX512 if fixes have been backported to distro versions, we can instead check the output of "as" from binutils to see if it is correct.

These checks use the minimal assembly reproduction code posted to the public bug tracker for gcc/binutils for those issues [1][2]. If the binutils bug is present, the instruction parameters - specifically the displacement parameter - will be different in the disassembled output compared to the input. Therefore each check involves assembling a single instruction and disassembling it again, checking that the two match.

Quoted 3 lines

Whaoh, that's a very specific optimization :) Which distro is affected (backported binutils fix)?

Not an optimization, it's a bug, which necessitates disabling a whole instruction set, so we should really check for the bug rather than assuming all versions are affected. From [2] below, we have confirmation that the fix has been backported to both 2.30 and 2.31 binutils branches.

Quoted 10 lines

buildtools/meson.build line 4

Quoted 8 lines

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=23465

---

buildtools/meson.build +0 -1
-subdir('pmdinfogen')

Why removing pmdinfogen?

The pmdinfogen requires values that are set in the config folder, but the config folder processing now uses scripts that are in the buildtools folder. While we could refer to them using relative paths, I felt it better to separate out the compilation of pmdinfogen to the rest of the buildutils processing, which is simply assigning variables to scripts to make them easier to call later in the processing.

Quoted 7 lines
Quoted 7 lines
meson.build +2 -0
+# do configuration and get tool paths
+subdir('buildtools')
 subdir('config')
Quoted 6 lines

meson.build global_inc = include_directories('.', 'config', · line 50

Quoted 3 lines
 # build libs and drivers
meson.build +1 -1
-subdir('buildtools')
+subdir('buildtools/pmdinfogen')

Is it related to binutils check?

Pretty much. It just makes it easier to have the config processing use scripts in the buildtools folder.

Quoted 9 lines

[...]

meson.build

Quoted 4 lines
meson.build +2 -2
-	ldver = run_command('ld', '-v').stdout().strip()
-	if ldver.contains('2.30') and cc.has_argument('-mno-avx512f')
+	as_ok = run_command(binutils_avx512_check)
+	if as_ok.returncode() != 0 and cc.has_argument('-mno-avx512f')

"as_ok" is difficult to understand.
I would suggest "binutils_avx512_ok".

Sure, can change for v2 - though I'd suggest the slightly shorter binutils_ok.

Quoted 4 lines

meson.build

Quoted 1 line
meson.build +1 -0
+		message('Binutils error with AVX512 assembly, disabling AVX512 support')

It looks like something which should be part of meson itself.

That would certainly be nice to have, but I consider it infeasible, since there will be, even in the best case, a lag between a bug being discovered and workarounds making its way into tools. Even then you still have an update problem to work around it - update binutils and bug goes away, or update meson and you can work around it. In both cases you are requiring the user to update something, so fixing in DPDK is best.

/Bruce

#3 lore raw

PATCH v2 1/1 build: check functionality rather than binutils version

In reply to Bruce Richardson

Rather than checking the binutils version number, which can lead to unnecessary disabling of AVX512 if fixes have been backported to distro versions, we can instead check the output of "as" from binutils to see if it is correct.

The check in the script uses the minimal assembly reproduction code posted to the public bug tracker for gcc/binutils for those issues [1]. If the binutils bug is present, the instruction parameters - specifically the displacement parameter - will be different in the disassembled output compared to the input. Therefore the check involves assembling a single instruction and disassembling it again, checking that the two match.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028

---
V2:
- Renamed "as_ok" variable to "binutils_ok" for readability
- Removed one test case from the script because even though two DPDK bugs were filed, the one binutils bug is the root cause, and a single commit fixes them both
- Changed message() to warning() in the printout

---
 buildtools/binutils-avx512-check.sh | 16 ++++++++++++++++
 buildtools/meson.build              |  3 +--
 config/x86/meson.build              | 10 +++-------
 meson.build                         |  5 ++++-
 4 files changed, 24 insertions(+), 10 deletions(-)
 create mode 100755 buildtools/binutils-avx512-check.sh
buildtools/binutils-avx512-check.sh new file +16 -0
new file mode 100755
index 000000000..cef7b09ed
@@ -0,0 +1,16 @@
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+AS=${AS:-as}
+MESON_BUILD_ROOT=${MESON_BUILD_ROOT:-/tmp}
+OBJFILE=$MESON_BUILD_ROOT/binutils-avx512-check.o
+# from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
+GATHER_PARAMS='0x8(,%ymm1,1),%ymm0{%k2}'
+
+# assemble vpgather to file and similarly check
+echo "vpgatherqq $GATHER_PARAMS" | $AS --64 -o $OBJFILE -
+objdump -d  --no-show-raw-insn $OBJFILE | grep -q $GATHER_PARAMS || {
+	echo "vpgatherqq displacement error with as"
+	exit 1
+}
buildtools/meson.build +1 -2
index d5f8291be..73a847c52 100644
@@ -1,13 +1,12 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017-2019 Intel Corporation
 
-subdir('pmdinfogen')
-
 pkgconf = find_program('pkg-config', 'pkgconf', required: false)
 pmdinfo = find_program('gen-pmdinfo-cfile.sh')
 list_dir_globs = find_program('list-dir-globs.py')
 check_symbols = find_program('check-symbols.sh')
 ldflags_ibverbs_static = find_program('options-ibverbs-static.sh')
+binutils_avx512_check = find_program('binutils-avx512-check.sh')
 
 # set up map-to-def script using python, either built-in or external
 python3 = import('python').find_installation(required: false)
config/x86/meson.build +3 -7
index adc857ba2..6ec020ef6 100644
@@ -3,14 +3,10 @@
 
 # get binutils version for the workaround of Bug 97
 if not is_windows
-	ldver = run_command('ld', '-v').stdout().strip()
-	if ldver.contains('2.30') and cc.has_argument('-mno-avx512f')
+	binutils_ok = run_command(binutils_avx512_check)
+	if binutils_ok.returncode() != 0 and cc.has_argument('-mno-avx512f')
 		machine_args += '-mno-avx512f'
-		message('Binutils 2.30 detected, disabling AVX512 support as workaround for bug #97')
-	endif
-	if ldver.contains('2.31') and cc.has_argument('-mno-avx512f')
-		machine_args += '-mno-avx512f'
-		message('Binutils 2.31 detected, disabling AVX512 support as workaround for bug #249')
+		warning('Binutils error with AVX512 assembly, disabling AVX512 support')
 	endif
 endif
 
meson.build +4 -1
index 750fdeab1..ab4d60cfa 100644
@@ -41,10 +41,13 @@ global_inc = include_directories('.', 'config',
 	'lib/librte_eal/@0@/include'.format(host_machine.system()),
 	'lib/librte_eal/@0@/include'.format(arch_subdir),
 )
+
+# do configuration and get tool paths
+subdir('buildtools')
 subdir('config')
 
 # build libs and drivers
-subdir('buildtools')
+subdir('buildtools/pmdinfogen')
 subdir('lib')
 subdir('drivers')
 
Signature · 1 line
2.25.1
Tested-by on v2 1/1
#4 lore raw
Quoted 21 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Bruce Richardson
Sent: Thursday, June 18, 2020 12:57 PM
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; [email protected]; Richardson, Bruce <[email protected]>
Subject: [dpdk-dev] [PATCH v2] build: check functionality rather than binutils version

Rather than checking the binutils version number, which can lead to unnecessary disabling of AVX512 if fixes have been backported to distro versions, we can instead check the output of "as" from binutils to see if it is correct.

The check in the script uses the minimal assembly reproduction code posted to the public bug tracker for gcc/binutils for those issues [1]. If the binutils bug is present, the instruction parameters - specifically the displacement parameter - will be different in the disassembled output compared to the input. Therefore the check involves assembling a single instruction and disassembling it again, checking that the two match.

Quoted 3 lines

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028

Tested on binutils 2.30 without backported fixes, can confirm that __AVX512F__ define is not present at meson configure time.

#5 lore raw
In reply to Bruce Richardson

18/06/2020 13:56, Bruce Richardson:

Quoted 11 lines

Rather than checking the binutils version number, which can lead to unnecessary disabling of AVX512 if fixes have been backported to distro versions, we can instead check the output of "as" from binutils to see if it is correct.

The check in the script uses the minimal assembly reproduction code posted to the public bug tracker for gcc/binutils for those issues [1]. If the binutils bug is present, the instruction parameters - specifically the displacement parameter - will be different in the disassembled output compared to the input. Therefore the check involves assembling a single instruction and disassembling it again, checking that the two match.

[...]

buildtools/binutils-avx512-check.sh line 16

Quoted 13 lines
buildtools/binutils-avx512-check.sh new file +11 -0
+MESON_BUILD_ROOT=${MESON_BUILD_ROOT:-/tmp}
+OBJFILE=$MESON_BUILD_ROOT/binutils-avx512-check.o
+# from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
+GATHER_PARAMS='0x8(,%ymm1,1),%ymm0{%k2}'
+
+# assemble vpgather to file and similarly check
+echo "vpgatherqq $GATHER_PARAMS" | $AS --64 -o $OBJFILE -
+objdump -d  --no-show-raw-insn $OBJFILE | grep -q $GATHER_PARAMS || {
+	echo "vpgatherqq displacement error with as"
+	exit 1
+}

For the temporary OBJFILE, please use mktemp and trap for cleanup. If you grep "mktemp" in DPDK, you will see the filename is pretty well standardized with "dpdk." as prefix.
Thanks

#6 lore raw
Quoted 23 lines · Thomas Monjalon

18/06/2020 13:56, Bruce Richardson:

Quoted 11 lines

Rather than checking the binutils version number, which can lead to unnecessary disabling of AVX512 if fixes have been backported to distro versions, we can instead check the output of "as" from binutils to see if it is correct.

The check in the script uses the minimal assembly reproduction code posted to the public bug tracker for gcc/binutils for those issues [1]. If the binutils bug is present, the instruction parameters - specifically the displacement parameter - will be different in the disassembled output compared to the input. Therefore the check involves assembling a single instruction and disassembling it again, checking that the two match.

[...]

Quoted 10 lines
buildtools/binutils-avx512-check.sh new file +8 -0
+MESON_BUILD_ROOT=${MESON_BUILD_ROOT:-/tmp}
+OBJFILE=$MESON_BUILD_ROOT/binutils-avx512-check.o
+# from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
+GATHER_PARAMS='0x8(,%ymm1,1),%ymm0{%k2}'
+
+# assemble vpgather to file and similarly check
+echo "vpgatherqq $GATHER_PARAMS" | $AS --64 -o $OBJFILE -
+objdump -d  --no-show-raw-insn $OBJFILE | grep -q $GATHER_PARAMS || {
Quoted 9 lines

buildtools/binutils-avx512-check.sh line 16

Quoted 3 lines
buildtools/binutils-avx512-check.sh new file +3 -0
+	echo "vpgatherqq displacement error with as"
+	exit 1
+}

For the temporary OBJFILE, please use mktemp and trap for cleanup. If you grep "mktemp" in DPDK, you will see the filename is pretty well standardized with "dpdk." as prefix.
Thanks

Will change for v3

#7 lore raw

PATCH v3 1/1 build: check functionality rather than binutils version

In reply to Bruce Richardson

Rather than checking the binutils version number, which can lead to unnecessary disabling of AVX512 if fixes have been backported to distro versions, we can instead check the output of "as" from binutils to see if it is correct.

The check in the script uses the minimal assembly reproduction code posted to the public bug tracker for gcc/binutils for those issues [1]. If the binutils bug is present, the instruction parameters - specifically the displacement parameter - will be different in the disassembled output compared to the input. Therefore the check involves assembling a single instruction and disassembling it again, checking that the two match.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028

---
V3:
- Use mktemp to create a temporary file rather than place object file in build folder. Use trap to ensure temp file deletion on exit.

V2:
- Renamed "as_ok" variable to "binutils_ok" for readability
- Removed one test case from the script because even though two DPDK bugs were filed, the one binutils bug is the root cause, and a single commit fixes them both
- Changed message() to warning() in the printout

---
 buildtools/binutils-avx512-check.sh | 16 ++++++++++++++++
 buildtools/meson.build              |  3 +--
 config/x86/meson.build              | 10 +++-------
 meson.build                         |  5 ++++-
 4 files changed, 24 insertions(+), 10 deletions(-)
 create mode 100755 buildtools/binutils-avx512-check.sh
buildtools/binutils-avx512-check.sh new file +16 -0
new file mode 100755
index 000000000..a7e068140
@@ -0,0 +1,16 @@
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+AS=${AS:-as}
+OBJFILE=$(mktemp -t dpdk.binutils-check.XXXXXX.o)
+trap 'rm -f "$OBJFILE"' EXIT
+# from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028
+GATHER_PARAMS='0x8(,%ymm1,1),%ymm0{%k2}'
+
+# assemble vpgather to file and similarly check
+echo "vpgatherqq $GATHER_PARAMS" | $AS --64 -o $OBJFILE -
+objdump -d  --no-show-raw-insn $OBJFILE | grep -q $GATHER_PARAMS || {
+	echo "vpgatherqq displacement error with as"
+	exit 1
+}
buildtools/meson.build +1 -2
index f9d2fdf74..cf0048f3c 100644
@@ -1,13 +1,12 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017-2019 Intel Corporation
 
-subdir('pmdinfogen')
-
 pkgconf = find_program('pkg-config', 'pkgconf', required: false)
 pmdinfo = find_program('gen-pmdinfo-cfile.sh')
 list_dir_globs = find_program('list-dir-globs.py')
 check_symbols = find_program('check-symbols.sh')
 ldflags_ibverbs_static = find_program('options-ibverbs-static.sh')
+binutils_avx512_check = find_program('binutils-avx512-check.sh')
 
 # set up map-to-win script using python, either built-in or external
 python3 = import('python').find_installation(required: false)
config/x86/meson.build +3 -7
index adc857ba2..6ec020ef6 100644
@@ -3,14 +3,10 @@
 
 # get binutils version for the workaround of Bug 97
 if not is_windows
-	ldver = run_command('ld', '-v').stdout().strip()
-	if ldver.contains('2.30') and cc.has_argument('-mno-avx512f')
+	binutils_ok = run_command(binutils_avx512_check)
+	if binutils_ok.returncode() != 0 and cc.has_argument('-mno-avx512f')
 		machine_args += '-mno-avx512f'
-		message('Binutils 2.30 detected, disabling AVX512 support as workaround for bug #97')
-	endif
-	if ldver.contains('2.31') and cc.has_argument('-mno-avx512f')
-		machine_args += '-mno-avx512f'
-		message('Binutils 2.31 detected, disabling AVX512 support as workaround for bug #249')
+		warning('Binutils error with AVX512 assembly, disabling AVX512 support')
 	endif
 endif
 
meson.build +4 -1
index d21adfd30..7c336df6d 100644
@@ -40,10 +40,13 @@ global_inc = include_directories('.', 'config',
 	'lib/librte_eal/@0@/include'.format(host_machine.system()),
 	'lib/librte_eal/@0@/include'.format(arch_subdir),
 )
+
+# do configuration and get tool paths
+subdir('buildtools')
 subdir('config')
 
 # build libs and drivers
-subdir('buildtools')
+subdir('buildtools/pmdinfogen')
 subdir('lib')
 subdir('drivers')
 
Signature · 1 line
2.25.1
#8 lore raw

04/07/2020 13:48, Bruce Richardson:

Quoted 22 lines

Rather than checking the binutils version number, which can lead to unnecessary disabling of AVX512 if fixes have been backported to distro versions, we can instead check the output of "as" from binutils to see if it is correct.

The check in the script uses the minimal assembly reproduction code posted to the public bug tracker for gcc/binutils for those issues [1]. If the binutils bug is present, the instruction parameters - specifically the displacement parameter - will be different in the disassembled output compared to the input. Therefore the check involves assembling a single instruction and disassembling it again, checking that the two match.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90028

---
V3:
- Use mktemp to create a temporary file rather than place object file in build folder. Use trap to ensure temp file deletion on exit.

Quoted 6 lines

V2:
- Renamed "as_ok" variable to "binutils_ok" for readability
- Removed one test case from the script because even though two DPDK bugs were filed, the one binutils bug is the root cause, and a single commit fixes them both
- Changed message() to warning() in the printout

Applied, thanks