From 086af669a517951b3a43038102f5f5352ef03567 Mon Sep 17 00:00:00 2001 From: Nikita Kniazev Date: Wed, 1 May 2024 11:29:46 +0300 Subject: [PATCH] gcc/clang: -m* flags when architecture is not explicitly set GCC is picky, -m32/-m64 is available only on a subset of targets, while Clang supports them universally. --- .ci/azp-linux-test.yml | 10 +++++++--- .ci/azp-macos-test.yml | 10 +++++++--- .ci/azp-windows-test.yml | 8 ++++++-- azure-pipelines.yml | 8 ++++++-- src/tools/clang-linux.jam | 9 +++++++++ src/tools/gcc.jam | 34 +++++++++++++++++++++++++++------- 6 files changed, 62 insertions(+), 17 deletions(-) diff --git a/.ci/azp-linux-test.yml b/.ci/azp-linux-test.yml index 9736e215d7..edc4c03b6c 100644 --- a/.ci/azp-linux-test.yml +++ b/.ci/azp-linux-test.yml @@ -1,3 +1,7 @@ +parameters: +- name: b2_opts + type: string + steps: - bash: | set -e @@ -26,16 +30,16 @@ steps: displayName: Test - bash: | set -e - ./src/engine/b2 b2 warnings-as-errors=on variant=debug,release address-model=32,64 toolset=${TOOLSET} + ./src/engine/b2 b2 warnings-as-errors=on variant=debug,release ${TOOLSET:+toolset=$TOOLSET} ${{ parameters.b2_opts }} displayName: "No Warnings" - bash: | set -e ./bootstrap.sh ${TOOLSET} - ./b2 --prefix=$HOME/temp/.b2 install toolset=${TOOLSET} + ./b2 --prefix=$HOME/temp/.b2 install ${TOOLSET:+toolset=$TOOLSET} ${{ parameters.b2_opts }} rm ./b2 export PATH=$HOME/temp/.b2/bin:$PATH cd $HOME touch build.jam b2 -v - b2 -n --debug-configuration toolset=${TOOLSET} + b2 -n --debug-configuration ${TOOLSET:+toolset=$TOOLSET} ${{ parameters.b2_opts }} displayName: Bootstrap diff --git a/.ci/azp-macos-test.yml b/.ci/azp-macos-test.yml index 1e517948b4..45ed2e3807 100644 --- a/.ci/azp-macos-test.yml +++ b/.ci/azp-macos-test.yml @@ -1,3 +1,7 @@ +parameters: +- name: b2_opts + type: string + steps: - bash: | set -e @@ -20,16 +24,16 @@ steps: displayName: Test - bash: | set -e - ./src/engine/b2 b2 warnings-as-errors=on variant=debug,release address-model=32,64 ${TOOLSET:+toolset=$TOOLSET} + ./src/engine/b2 b2 warnings-as-errors=on variant=debug,release ${TOOLSET:+toolset=$TOOLSET} ${{ parameters.b2_opts }} displayName: "No Warnings" - bash: | set -e ./bootstrap.sh ${TOOLSET} - ./b2 --prefix=$HOME/temp/.b2 install ${TOOLSET:+toolset=$TOOLSET} + ./b2 --prefix=$HOME/temp/.b2 install ${TOOLSET:+toolset=$TOOLSET} ${{ parameters.b2_opts }} rm ./b2 export PATH=$HOME/temp/.b2/bin:$PATH cd $HOME touch build.jam b2 -v - b2 -n --debug-configuration ${TOOLSET:+toolset=$TOOLSET} + b2 -n --debug-configuration ${TOOLSET:+toolset=$TOOLSET} ${{ parameters.b2_opts }} displayName: Bootstrap diff --git a/.ci/azp-windows-test.yml b/.ci/azp-windows-test.yml index 037aeccdb4..59cf230bd2 100644 --- a/.ci/azp-windows-test.yml +++ b/.ci/azp-windows-test.yml @@ -1,3 +1,7 @@ +parameters: +- name: b2_opts + type: string + steps: - powershell: | Set-PSDebug -Trace 1 @@ -22,7 +26,7 @@ steps: $env:HOME = $env:HOMEDRIVE + $env:HOMEPATH $env:path += ';' + $env:CXX_PATH echo "using" $env:TEST_TOOLSET ":" ":" $env:CXX ";" > ${env:HOME}/user-config.jam - ./src/engine/b2.exe --debug-configuration b2 warnings-as-errors=on variant=debug,release toolset=$env:TEST_TOOLSET + ./src/engine/b2.exe --debug-configuration b2 warnings-as-errors=on variant=debug,release toolset=$env:TEST_TOOLSET ${{ parameters.b2_opts }} displayName: "No Warnings" - powershell: | Set-PSDebug -Trace 1 @@ -30,7 +34,7 @@ steps: $env:path += ';' + $env:CXX_PATH echo "using" $env:TEST_TOOLSET ":" ":" $env:CXX ";" > ${env:HOME}/user-config.jam ./bootstrap.bat $env:TOOLSET - ./b2.exe --debug-configuration --prefix=${env:HOME}/temp/.b2 install toolset=$env:TEST_TOOLSET + ./b2.exe --debug-configuration --prefix=${env:HOME}/temp/.b2 install toolset=$env:TEST_TOOLSET ${{ parameters.b2_opts }} Remove-Item ./b2.exe $env:path += $env:HOME + '/temp/.b2' + ';' + $env:PATH cd $env:HOME diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b67384e021..3adc2f4b23 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -91,12 +91,14 @@ stages: - job: 'Linux_Latest' strategy: matrix: - GCC ${{variables.gcc_latest}}: {TOOLSET: "gcc-${{variables.gcc_latest}}", PACKAGES: "g++-${{variables.gcc_latest}}", VM_IMAGE: "${{variables.linux_latest_vm}}"} - Clang ${{variables.clang_latest}}: {TOOLSET: "clang-${{variables.clang_latest}}", PACKAGES: "clang-${{variables.clang_latest}}", LLVM_OS: "${{variables.linux_latest_os}}", LLVM_VER: "${{variables.clang_latest}}", VM_IMAGE: "${{variables.linux_latest_vm}}"} + GCC ${{variables.gcc_latest}}: {TOOLSET: "gcc-${{variables.gcc_latest}}", PACKAGES: "g++-${{variables.gcc_latest}}-multilib", VM_IMAGE: "${{variables.linux_latest_vm}}"} + Clang ${{variables.clang_latest}}: {TOOLSET: "clang-${{variables.clang_latest}}", PACKAGES: "clang-${{variables.clang_latest}} libstdc++-${{variables.gcc_latest}}-dev-i386-cross", LLVM_OS: "${{variables.linux_latest_os}}", LLVM_VER: "${{variables.clang_latest}}", VM_IMAGE: "${{variables.linux_latest_vm}}"} pool: vmImage: $(VM_IMAGE) steps: - template: .ci/azp-linux-test.yml + parameters: + b2_opts: address-model=32,64 - job: 'Windows_Latest' strategy: @@ -108,6 +110,8 @@ stages: continueOnError: 'true' steps: - template: .ci/azp-windows-test.yml + parameters: + b2_opts: address-model=32,64 - job: 'macOS' strategy: diff --git a/src/tools/clang-linux.jam b/src/tools/clang-linux.jam index 26891f4b60..758ec5fe00 100644 --- a/src/tools/clang-linux.jam +++ b/src/tools/clang-linux.jam @@ -126,6 +126,12 @@ rule get-short-version ( command-string : single-digit-since ? ) return $(version[1]) ; } +local rule compile-link-flags ( * ) +{ + toolset.flags clang-linux.compile OPTIONS $(1) : $(2) ; + toolset.flags clang-linux.link OPTIONS $(1) : $(2) ; +} + ############################################################################### # Flags @@ -135,6 +141,9 @@ toolset.flags clang-linux.compile INCLUDE-PCH : -include-pch ; # For clang, 'on' and 'full' are identical. toolset.flags clang-linux.compile OPTIONS full : -Wno-inline ; +compile-link-flags 32 : -m32 ; +compile-link-flags 64 : -m64 ; + # LTO toolset.flags clang-linux.compile OPTIONS on/thin : -flto=thin ; toolset.flags clang-linux.link OPTIONS on/thin : -flto=thin ; diff --git a/src/tools/gcc.jam b/src/tools/gcc.jam index e5f8f53a46..f3e109e785 100644 --- a/src/tools/gcc.jam +++ b/src/tools/gcc.jam @@ -184,11 +184,12 @@ rule init ( version ? : command * : options * : requirement * ) bin ?= [ common.get-absolute-tool-path $(command[-1]) ] ; root ?= $(bin:D) ; } + local machine ; local target-os ; # Autodetect the version and flavor if not given. if $(command) { - local machine = [ MATCH "^([^ ]+)" : + machine = [ MATCH "^([^ ]+)" : [ SHELL "$(command-string) -dumpmachine" ] ] ; if ! $(version) { # ?= operator does not short-circuit version ?= [ get-short-version $(command-string) ] ; @@ -203,6 +204,8 @@ rule init ( version ? : command * : options * : requirement * ) case *mingw* : target-os ?= windows ; case *cygwin* : target-os ?= cygwin ; case *linux* : target-os ?= linux ; + case *aix* : target-os ?= aix ; + case *hpux* : target-os ?= hpux ; # TODO: finish this list. } } @@ -276,6 +279,20 @@ rule init ( version ? : command * : options * : requirement * ) toolset.flags gcc VERSION $(condition) : [ regex.split $(version) "[.]" ] ; init-cxxstd-flags $(condition) : $(version) ; + + if ! $(target-os) in aix hpux + { + if [ MATCH "^(i.86|x86|powerpc|ppc|sparc)" : $(machine:L) ] + { + compile-link-flags $(condition)//32 : -m32 ; + compile-link-flags $(condition)//64 : -m64 ; + } + if [ MATCH "^(s390)" : $(machine:L) ] + { + compile-link-flags $(condition)//32 : -m31 ; + compile-link-flags $(condition)//64 : -m64 ; + } + } } if [ os.name ] = NT @@ -362,16 +379,19 @@ local rule compile-link-flags ( * ) { # Handle address-model - compile-link-flags aix/32 : -maix32 ; - compile-link-flags aix/64 : -maix64 ; + compile-link-flags gcc/aix/32 : -maix32 ; + compile-link-flags gcc/aix/64 : -maix64 ; - compile-link-flags hpux/32 : -milp32 ; - compile-link-flags hpux/64 : -mlp64 ; + compile-link-flags gcc/hpux/32 : -milp32 ; + compile-link-flags gcc/hpux/64 : -mlp64 ; local generic-os = [ set.difference $(all-os) : aix hpux ] ; local arch = power sparc x86 ; - compile-link-flags $(generic-os)/$(arch)/32 : -m32 ; - compile-link-flags $(generic-os)/$(arch)/64 : -m64 ; + compile-link-flags gcc/$(generic-os)/$(arch)/32 : -m32 ; + compile-link-flags gcc/$(generic-os)/$(arch)/64 : -m64 ; + + compile-link-flags gcc/s390x/32 : -m31 ; + compile-link-flags gcc/s390x/64 : -m64 ; } {