From 6b42b6ce9a9785db1aa2ea5b45a2db76df03b4cb Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Wed, 29 Nov 2023 17:10:41 -0700 Subject: [PATCH] build-binutils.py: Fix error with x86-64-v{2,3,4} as value to '-m' These values are not valid '-mtune' values, so the build errors. Do not add '-mtune' at all, unless one of these values has been specified, in which case '-mtune=native' is a safe choice. Closes: https://github.com/ClangBuiltLinux/tc-build/issues/255 Link: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html Signed-off-by: Nathan Chancellor --- build-binutils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/build-binutils.py b/build-binutils.py index 9cfe016e..0460a105 100755 --- a/build-binutils.py +++ b/build-binutils.py @@ -42,8 +42,8 @@ '--march', metavar='ARCH', help=''' - Add -march=ARCH and -mtune=ARCH to CFLAGS to optimize the toolchain for the target - host processor. + Add -march=ARCH to CFLAGS to optimize the toolchain for the processor that it will be + running on. ''', type=str) parser.add_argument('--show-build-commands', @@ -120,7 +120,14 @@ builder.folders.install = Path(args.install_folder).resolve() builder.folders.source = bsm.location if args.march: - builder.cflags += [f"-march={args.march}", f"-mtune={args.march}"] + builder.cflags.append(f"-march={args.march}") + # -march implies -mtune except for x86-64-v{2,3,4}, which are + # documented to imply -mtune=generic. If the user has requested one + # of these values, it is a safe assumption they only care about + # running on their machine, so add -mtune=native to further + # optimize the toolchain for their machine. + if 'x86-64-v' in args.march: + builder.cflags.append('-mtune=native') builder.show_commands = args.show_build_commands builder.build() else: