Skip to content

Commit 7eb52c9

Browse files
committed
unix: add x86_64_v{2,3,4} Linux target variants
Clang 12 supports x86-64-{v2,v3,v4} as targets supporting newer microarchitecture levels. Let's add support for these to the build so we can produce binaries targeting newer CPUs. This issue is related to indygreg/PyOxidizer#392
1 parent 6b9be59 commit 7eb52c9

File tree

5 files changed

+435
-4
lines changed

5 files changed

+435
-4
lines changed

.github/workflows/linux.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,80 @@ jobs:
334334
py: 'cpython-3.10'
335335
optimizations: 'pgo+lto'
336336

337+
- target_triple: 'x86_64_v2-unknown-linux-gnu'
338+
py: 'cpython-3.9'
339+
optimizations: 'debug'
340+
- target_triple: 'x86_64_v2-unknown-linux-gnu'
341+
py: 'cpython-3.9'
342+
optimizations: 'lto'
343+
- target_triple: 'x86_64_v2-unknown-linux-gnu'
344+
py: 'cpython-3.9'
345+
optimizations: 'pgo'
346+
- target_triple: 'x86_64_v2-unknown-linux-gnu'
347+
py: 'cpython-3.9'
348+
optimizations: 'pgo+lto'
349+
350+
- target_triple: 'x86_64_v2-unknown-linux-gnu'
351+
py: 'cpython-3.10'
352+
optimizations: 'debug'
353+
- target_triple: 'x86_64_v2-unknown-linux-gnu'
354+
py: 'cpython-3.10'
355+
optimizations: 'lto'
356+
- target_triple: 'x86_64_v2-unknown-linux-gnu'
357+
py: 'cpython-3.10'
358+
optimizations: 'pgo'
359+
- target_triple: 'x86_64_v2-unknown-linux-gnu'
360+
py: 'cpython-3.10'
361+
optimizations: 'pgo+lto'
362+
363+
- target_triple: 'x86_64_v3-unknown-linux-gnu'
364+
py: 'cpython-3.9'
365+
optimizations: 'debug'
366+
- target_triple: 'x86_64_v3-unknown-linux-gnu'
367+
py: 'cpython-3.9'
368+
optimizations: 'lto'
369+
- target_triple: 'x86_64_v3-unknown-linux-gnu'
370+
py: 'cpython-3.9'
371+
optimizations: 'pgo'
372+
- target_triple: 'x86_64_v3-unknown-linux-gnu'
373+
py: 'cpython-3.9'
374+
optimizations: 'pgo+lto'
375+
376+
- target_triple: 'x86_64_v3-unknown-linux-gnu'
377+
py: 'cpython-3.10'
378+
optimizations: 'debug'
379+
- target_triple: 'x86_64_v3-unknown-linux-gnu'
380+
py: 'cpython-3.10'
381+
optimizations: 'lto'
382+
- target_triple: 'x86_64_v3-unknown-linux-gnu'
383+
py: 'cpython-3.10'
384+
optimizations: 'pgo'
385+
- target_triple: 'x86_64_v3-unknown-linux-gnu'
386+
py: 'cpython-3.10'
387+
optimizations: 'pgo+lto'
388+
389+
# GitHub Actions runners don't support x86-64-v4 so we can't PGO.
390+
- target_triple: 'x86_64_v4-unknown-linux-gnu'
391+
py: 'cpython-3.9'
392+
optimizations: 'debug'
393+
- target_triple: 'x86_64_v4-unknown-linux-gnu'
394+
py: 'cpython-3.9'
395+
optimizations: 'noopt'
396+
- target_triple: 'x86_64_v4-unknown-linux-gnu'
397+
py: 'cpython-3.9'
398+
optimizations: 'lto'
399+
400+
# GitHub Actions runners don't support x86-64-v4 so we can't PGO.
401+
- target_triple: 'x86_64_v4-unknown-linux-gnu'
402+
py: 'cpython-3.10'
403+
optimizations: 'debug'
404+
- target_triple: 'x86_64_v4-unknown-linux-gnu'
405+
py: 'cpython-3.10'
406+
optimizations: 'noopt'
407+
- target_triple: 'x86_64_v4-unknown-linux-gnu'
408+
py: 'cpython-3.10'
409+
optimizations: 'lto'
410+
337411
# musl doesn't support PGO.
338412
- target_triple: 'x86_64-unknown-linux-musl'
339413
py: 'cpython-3.8'
@@ -365,6 +439,66 @@ jobs:
365439
py: 'cpython-3.10'
366440
optimizations: 'lto'
367441

442+
- target_triple: 'x86_64_v2-unknown-linux-musl'
443+
py: 'cpython-3.9'
444+
optimizations: 'debug'
445+
- target_triple: 'x86_64_v2-unknown-linux-musl'
446+
py: 'cpython-3.9'
447+
optimizations: 'noopt'
448+
- target_triple: 'x86_64_v2-unknown-linux-musl'
449+
py: 'cpython-3.9'
450+
optimizations: 'lto'
451+
452+
- target_triple: 'x86_64_v2-unknown-linux-musl'
453+
py: 'cpython-3.10'
454+
optimizations: 'debug'
455+
- target_triple: 'x86_64_v2-unknown-linux-musl'
456+
py: 'cpython-3.10'
457+
optimizations: 'noopt'
458+
- target_triple: 'x86_64_v2-unknown-linux-musl'
459+
py: 'cpython-3.10'
460+
optimizations: 'lto'
461+
462+
- target_triple: 'x86_64_v3-unknown-linux-musl'
463+
py: 'cpython-3.9'
464+
optimizations: 'debug'
465+
- target_triple: 'x86_64_v3-unknown-linux-musl'
466+
py: 'cpython-3.9'
467+
optimizations: 'noopt'
468+
- target_triple: 'x86_64_v3-unknown-linux-musl'
469+
py: 'cpython-3.9'
470+
optimizations: 'lto'
471+
472+
- target_triple: 'x86_64_v3-unknown-linux-musl'
473+
py: 'cpython-3.10'
474+
optimizations: 'debug'
475+
- target_triple: 'x86_64_v3-unknown-linux-musl'
476+
py: 'cpython-3.10'
477+
optimizations: 'noopt'
478+
- target_triple: 'x86_64_v3-unknown-linux-musl'
479+
py: 'cpython-3.10'
480+
optimizations: 'lto'
481+
482+
- target_triple: 'x86_64_v4-unknown-linux-musl'
483+
py: 'cpython-3.9'
484+
optimizations: 'debug'
485+
- target_triple: 'x86_64_v4-unknown-linux-musl'
486+
py: 'cpython-3.9'
487+
optimizations: 'noopt'
488+
- target_triple: 'x86_64_v4-unknown-linux-musl'
489+
py: 'cpython-3.9'
490+
optimizations: 'lto'
491+
492+
- target_triple: 'x86_64_v4-unknown-linux-musl'
493+
py: 'cpython-3.10'
494+
optimizations: 'debug'
495+
- target_triple: 'x86_64_v4-unknown-linux-musl'
496+
py: 'cpython-3.10'
497+
optimizations: 'noopt'
498+
- target_triple: 'x86_64_v4-unknown-linux-musl'
499+
py: 'cpython-3.10'
500+
optimizations: 'lto'
501+
368502
needs:
369503
- pythonbuild
370504
- toolchain

cpython-unix/build-cpython.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ fi
700700
CPPFLAGS=$CFLAGS
701701

702702
CONFIGURE_FLAGS="
703-
--build=${BUILD_TRIPLE} \
703+
--build=${BUILD_TRIPLE}
704704
--host=${TARGET_TRIPLE}
705705
--prefix=/install
706706
--with-openssl=${TOOLS_PATH}/deps
@@ -712,6 +712,20 @@ if [ "${CC}" = "musl-clang" ]; then
712712
CPPFLAGS="${CPPFLAGS} -static"
713713
LDFLAGS="${LDFLAGS} -static"
714714
PYBUILD_SHARED=0
715+
716+
# In order to build the _blake2 extension module with SSE3+ instructions, we need
717+
# musl-clang to find headers that provide access to the intrinsics, as they are not
718+
# provided by musl. These are part of the include files that are part of clang.
719+
# But musl-clang eliminates them from the default include path. So copy them into
720+
# place.
721+
for h in /tools/clang-linux64/lib/clang/*/include/*intrin.h /tools/clang-linux64/lib/clang/*/include/{__wmmintrin_aes.h,__wmmintrin_pclmul.h,mm_malloc.h}; do
722+
filename=$(basename "$h")
723+
if [ -e "/tools/host/include/${filename}" ]; then
724+
echo "${filename} already exists; don't need to copy!"
725+
exit 1
726+
fi
727+
cp "$h" /tools/host/include/
728+
done
715729
else
716730
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-shared"
717731
PYBUILD_SHARED=1

cpython-unix/build.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,17 @@ def add_target_env(env, build_platform, target_triple, build_env):
9898
if build_platform == "linux64":
9999
env["BUILD_TRIPLE"] = "x86_64-unknown-linux-gnu"
100100

101-
# TODO should the musl target be normalized?
102-
env["TARGET_TRIPLE"] = target_triple.replace(
103-
"-unknown-linux-musl", "-unknown-linux-gnu"
101+
env["TARGET_TRIPLE"] = (
102+
target_triple.replace("x86_64_v2-", "x86_64-")
103+
.replace("x86_64_v3-", "x86_64-")
104+
.replace("x86_64_v4-", "x86_64-")
105+
# TODO should the musl target be normalized?
106+
.replace("-unknown-linux-musl", "-unknown-linux-gnu")
104107
)
105108

109+
# This will make x86_64_v2, etc count as cross-compiling. This is
110+
# semantically correct, since the current machine may not support
111+
# instructions on the target machine type.
106112
if env["BUILD_TRIPLE"] != target_triple or target_triple.endswith(
107113
"-unknown-linux-musl"
108114
):

0 commit comments

Comments
 (0)