Skip to content

Commit

Permalink
gcc/clang: -m* flags when architecture is not explicitly set
Browse files Browse the repository at this point in the history
GCC is picky, -m32/-m64 is available only on a subset of targets, while Clang supports them universally.
  • Loading branch information
Kojoley committed May 5, 2024
1 parent bed068a commit 086af66
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
10 changes: 7 additions & 3 deletions .ci/azp-linux-test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
parameters:
- name: b2_opts
type: string

steps:
- bash: |
set -e
Expand Down Expand Up @@ -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
10 changes: 7 additions & 3 deletions .ci/azp-macos-test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
parameters:
- name: b2_opts
type: string

steps:
- bash: |
set -e
Expand All @@ -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
8 changes: 6 additions & 2 deletions .ci/azp-windows-test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
parameters:
- name: b2_opts
type: string

steps:
- powershell: |
Set-PSDebug -Trace 1
Expand All @@ -22,15 +26,15 @@ 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
$env:HOME = $env:HOMEDRIVE + $env:HOMEPATH
$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
Expand Down
8 changes: 6 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -108,6 +110,8 @@ stages:
continueOnError: 'true'
steps:
- template: .ci/azp-windows-test.yml
parameters:
b2_opts: address-model=32,64

- job: 'macOS'
strategy:
Expand Down
9 changes: 9 additions & 0 deletions src/tools/clang-linux.jam
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <inlining>full : -Wno-inline ;

compile-link-flags <address-model>32 : -m32 ;
compile-link-flags <address-model>64 : -m64 ;

# LTO
toolset.flags clang-linux.compile OPTIONS <lto>on/<lto-mode>thin : -flto=thin ;
toolset.flags clang-linux.link OPTIONS <lto>on/<lto-mode>thin : -flto=thin ;
Expand Down
34 changes: 27 additions & 7 deletions src/tools/gcc.jam
Original file line number Diff line number Diff line change
Expand Up @@ -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) ] ;
Expand All @@ -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.
}
}
Expand Down Expand Up @@ -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)/<architecture>/<address-model>32 : -m32 ;
compile-link-flags $(condition)/<architecture>/<address-model>64 : -m64 ;
}
if [ MATCH "^(s390)" : $(machine:L) ]
{
compile-link-flags $(condition)/<architecture>/<address-model>32 : -m31 ;
compile-link-flags $(condition)/<architecture>/<address-model>64 : -m64 ;
}
}
}

if [ os.name ] = NT
Expand Down Expand Up @@ -362,16 +379,19 @@ local rule compile-link-flags ( * )

{
# Handle address-model
compile-link-flags <target-os>aix/<address-model>32 : -maix32 ;
compile-link-flags <target-os>aix/<address-model>64 : -maix64 ;
compile-link-flags <toolset>gcc/<target-os>aix/<address-model>32 : -maix32 ;
compile-link-flags <toolset>gcc/<target-os>aix/<address-model>64 : -maix64 ;

compile-link-flags <target-os>hpux/<address-model>32 : -milp32 ;
compile-link-flags <target-os>hpux/<address-model>64 : -mlp64 ;
compile-link-flags <toolset>gcc/<target-os>hpux/<address-model>32 : -milp32 ;
compile-link-flags <toolset>gcc/<target-os>hpux/<address-model>64 : -mlp64 ;

local generic-os = [ set.difference $(all-os) : aix hpux ] ;
local arch = power sparc x86 ;
compile-link-flags <target-os>$(generic-os)/<architecture>$(arch)/<address-model>32 : -m32 ;
compile-link-flags <target-os>$(generic-os)/<architecture>$(arch)/<address-model>64 : -m64 ;
compile-link-flags <toolset>gcc/<target-os>$(generic-os)/<architecture>$(arch)/<address-model>32 : -m32 ;
compile-link-flags <toolset>gcc/<target-os>$(generic-os)/<architecture>$(arch)/<address-model>64 : -m64 ;

compile-link-flags <toolset>gcc/<architecture>s390x/<address-model>32 : -m31 ;
compile-link-flags <toolset>gcc/<architecture>s390x/<address-model>64 : -m64 ;
}

{
Expand Down

0 comments on commit 086af66

Please sign in to comment.