Skip to content

Commit

Permalink
gcc/clang: -m* flags when architecture is not explicitly set (#379)
Browse files Browse the repository at this point in the history
GCC is picky, -m32/-m64 flags are available only on a subset of targets. Clang supports -m32/-m64 universally.
  • Loading branch information
Kojoley authored May 9, 2024
1 parent 4e2ad2c commit 006b1ec
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
11 changes: 8 additions & 3 deletions .ci/azp-linux-test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
parameters:
- name: b2_opts
type: string
default: ''

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

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

steps:
- powershell: |
Set-PSDebug -Trace 1
Expand All @@ -22,19 +27,19 @@ 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
echo $null >> build.jam
b2 -v
b2 -n --debug-configuration
b2 -n --debug-configuration toolset=$env:TEST_TOOLSET ${{ parameters.b2_opts }}
displayName: Bootstrap
9 changes: 7 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ variables:
- { name: linux_latest_os, value: 'focal' }
- { name: windows_latest_vm, value: 'windows-2022' }
- { name: clang_latest, value: '17' }
- { name: clang_latest_libstdcxx, value: 9 }
- { name: gcc_latest, value: '13' }
- { name: vc_latest, value: 'vc143' }
- { name: vs_latest, value: '2022' }
Expand Down Expand Up @@ -91,12 +92,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.clang_latest_libstdcxx}}-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 +111,8 @@ stages:
continueOnError: 'true'
steps:
- template: .ci/azp-windows-test.yml
parameters:
b2_opts: address-model=32,64

- job: 'macOS'
strategy:
Expand Down
16 changes: 16 additions & 0 deletions src/tools/clang-linux.jam
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ toolset.inherit-generators clang-linux
<toolset>clang <toolset-clang:platform>linux : gcc
: gcc.mingw.link gcc.mingw.link.dll gcc.cygwin.link gcc.cygwin.link.dll ;

local all-os = [ feature.values <target-os> ] ;
local all-arch = [ feature.values <architecture> ] ;

toolset.inherit-rules clang-linux : gcc ;
toolset.inherit-flags clang-linux : gcc
: <inlining>full
<lto>on/<lto-mode>full
<lto>on/<lto-mode>fat
<target-os>$(all-os)/<address-model>32
<target-os>$(all-os)/<address-model>64
<target-os>$(all-os)/<architecture>$(all-arch)/<address-model>32
<target-os>$(all-os)/<architecture>$(all-arch)/<address-model>64
: INCLUDE-GCH
;

Expand Down Expand Up @@ -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

Expand All @@ -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 <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
21 changes: 20 additions & 1 deletion 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 @@ -369,6 +386,8 @@ local rule compile-link-flags ( * )
compile-link-flags <target-os>hpux/<address-model>64 : -mlp64 ;

local generic-os = [ set.difference $(all-os) : aix hpux ] ;
compile-link-flags <target-os>$(generic-os)/<architecture>s390x/<address-model>32 : -m31 ;
compile-link-flags <target-os>$(generic-os)/<architecture>s390x/<address-model>64 : -m64 ;
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 ;
Expand Down

0 comments on commit 006b1ec

Please sign in to comment.