From e93f39ceffbad9d31f28667ed24774d41568a619 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. Clang supports -m32/-m64 universally. --- .ci/azp-linux-test.yml | 11 ++++++++--- .ci/azp-macos-test.yml | 11 ++++++++--- .ci/azp-windows-test.yml | 11 ++++++++--- azure-pipelines.yml | 8 ++++++-- src/tools/clang-linux.jam | 16 ++++++++++++++++ src/tools/gcc.jam | 21 ++++++++++++++++++++- 6 files changed, 66 insertions(+), 12 deletions(-) diff --git a/.ci/azp-linux-test.yml b/.ci/azp-linux-test.yml index 9736e215d7..393a01b46a 100644 --- a/.ci/azp-linux-test.yml +++ b/.ci/azp-linux-test.yml @@ -1,3 +1,8 @@ +parameters: +- name: b2_opts + type: string + default: '' + steps: - bash: | set -e @@ -26,16 +31,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..b93ea97393 100644 --- a/.ci/azp-macos-test.yml +++ b/.ci/azp-macos-test.yml @@ -1,3 +1,8 @@ +parameters: +- name: b2_opts + type: string + default: '' + steps: - bash: | set -e @@ -20,16 +25,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..0f1e68cafd 100644 --- a/.ci/azp-windows-test.yml +++ b/.ci/azp-windows-test.yml @@ -1,3 +1,8 @@ +parameters: +- name: b2_opts + type: string + default: '' + steps: - powershell: | Set-PSDebug -Trace 1 @@ -22,7 +27,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,11 +35,11 @@ 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 echo $null >> build.jam b2 -v - b2 -n --debug-configuration + b2 -n --debug-configuration toolset=$env:TEST_TOOLSET ${{ parameters.b2_opts }} displayName: Bootstrap diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b67384e021..50e4ad1930 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++-9-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..82501f6a88 100644 --- a/src/tools/clang-linux.jam +++ b/src/tools/clang-linux.jam @@ -30,11 +30,18 @@ toolset.inherit-generators clang-linux clang linux : gcc : gcc.mingw.link gcc.mingw.link.dll gcc.cygwin.link gcc.cygwin.link.dll ; +local all-os = [ feature.values ] ; +local all-arch = [ feature.values ] ; + toolset.inherit-rules clang-linux : gcc ; toolset.inherit-flags clang-linux : gcc : full on/full on/fat + $(all-os)/32 + $(all-os)/64 + $(all-os)/$(all-arch)/32 + $(all-os)/$(all-arch)/64 : INCLUDE-GCH ; @@ -126,6 +133,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 +148,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..61072358fb 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 @@ -369,6 +386,8 @@ local rule compile-link-flags ( * ) compile-link-flags hpux/64 : -mlp64 ; local generic-os = [ set.difference $(all-os) : aix hpux ] ; + compile-link-flags $(generic-os)/s390x/32 : -m31 ; + compile-link-flags $(generic-os)/s390x/64 : -m64 ; local arch = power sparc x86 ; compile-link-flags $(generic-os)/$(arch)/32 : -m32 ; compile-link-flags $(generic-os)/$(arch)/64 : -m64 ;