From 81f2abdffca8e4d81a7d5ee6ddc8879a2727dcf6 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 13 Jan 2022 10:11:40 -0800 Subject: [PATCH] compilers: Convert b_sanitize to a freeform array option There are a lot of sanitizers these days, and trying to keep up with them would be entirely too much work. Instead we'll do a compile check to see if the option is valid. A list makes more sense than a string, since users could just write `address,undefined` or they could write `undefined,address`. With the list we get to handle that ourselves and users writing code know that it's not safe to simply do a check like ```meson if get_option('b_sanitize') == 'address,undefined' ... endif ``` instead they need to do something like ```meson opt = get_option('b_sanitize') if opt.contains('address') and opt.contains('undefined') ... endif ``` To ensure backwards compatibility, a special check has been added to the get_option() call for `b_sanitize`, which converts it to a list if the compatibility is < 0.62, with a warning that the behavior will change in the future. Fixes #8283 Fixes #7761 Fixes #5154 Fixes #1582 --- docs/markdown/Builtin-options.md | 165 +++++++++--------- docs/markdown/snippets/b_sanitizer_changes.md | 17 ++ mesonbuild/backend/vs2010backend.py | 2 +- mesonbuild/compilers/compilers.py | 15 +- mesonbuild/compilers/cuda.py | 4 +- mesonbuild/compilers/mixins/gnu.py | 10 +- mesonbuild/compilers/mixins/islinker.py | 2 +- mesonbuild/compilers/mixins/visualstudio.py | 10 +- mesonbuild/interpreter/interpreter.py | 22 ++- mesonbuild/linkers/linkers.py | 18 +- mesonbuild/modules/gnome.py | 4 +- test cases/common/250 sanitizer/meson.build | 4 + .../subprojects/new_behavior/meson.build | 10 ++ .../subprojects/old_behavior/meson.build | 9 + unittests/allplatformstests.py | 4 +- 15 files changed, 178 insertions(+), 118 deletions(-) create mode 100644 docs/markdown/snippets/b_sanitizer_changes.md create mode 100644 test cases/common/250 sanitizer/meson.build create mode 100644 test cases/common/250 sanitizer/subprojects/new_behavior/meson.build create mode 100644 test cases/common/250 sanitizer/subprojects/old_behavior/meson.build diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md index 613b8b89b523..8e9eedbf909e 100644 --- a/docs/markdown/Builtin-options.md +++ b/docs/markdown/Builtin-options.md @@ -33,21 +33,21 @@ Installation options are all relative to the prefix, except: ### Directories -| Option | Default value | Description | -| ------ | ------------- | ----------- | -| prefix | see below | Installation prefix | -| bindir | bin | Executable directory | -| datadir | share | Data file directory | -| includedir | include | Header file directory | -| infodir | share/info | Info page directory | -| libdir | see below | Library directory | -| libexecdir | libexec | Library executable directory | -| localedir | share/locale | Locale data directory | -| localstatedir | var | Localstate data directory | -| mandir | share/man | Manual page directory | -| sbindir | sbin | System executable directory | -| sharedstatedir | com | Architecture-independent data directory | -| sysconfdir | etc | Sysconf data directory | +| Option | Default value | Description | +| -------------- | ------------- | --------------------------------------- | +| prefix | see below | Installation prefix | +| bindir | bin | Executable directory | +| datadir | share | Data file directory | +| includedir | include | Header file directory | +| infodir | share/info | Info page directory | +| libdir | see below | Library directory | +| libexecdir | libexec | Library executable directory | +| localedir | share/locale | Locale data directory | +| localstatedir | var | Localstate data directory | +| mandir | share/man | Manual page directory | +| sbindir | sbin | System executable directory | +| sharedstatedir | com | Architecture-independent data directory | +| sysconfdir | etc | Sysconf data directory | `prefix` defaults to `C:/` on Windows, and `/usr/local` otherwise. You @@ -67,27 +67,27 @@ Options that are labeled "per machine" in the table are set per machine. See the [specifying options per machine](#specifying-options-per-machine) section for details. -| Option | Default value | Description | Is per machine | Is per subproject | -| ------ | ------------- | ----------- | -------------- | ----------------- | -| auto_features {enabled, disabled, auto} | auto | Override value of all 'auto' features | no | no | -| backend {ninja, vs,
vs2010, vs2012, vs2013, vs2015, vs2017, vs2019, vs2022, xcode} | ninja | Backend to use | no | no | -| buildtype {plain, debug,
debugoptimized, release, minsize, custom} | debug | Build type to use | no | no | -| debug | true | Debug | no | no | -| default_library {shared, static, both} | shared | Default library type | no | yes | -| errorlogs | true | Whether to print the logs from failing tests. | no | no | -| install_umask {preserve, 0000-0777} | 022 | Default umask to apply on permissions of installed files | no | no | -| layout {mirror,flat} | mirror | Build directory layout | no | no | -| optimization {0, g, 1, 2, 3, s} | 0 | Optimization level | no | no | -| pkg_config_path {OS separated path} | '' | Additional paths for pkg-config to search before builtin paths | yes | no | -| cmake_prefix_path | [] | Additional prefixes for cmake to search before builtin paths | yes | no | -| stdsplit | true | Split stdout and stderr in test logs | no | no | -| strip | false | Strip targets on install | no | no | -| unity {on, off, subprojects} | off | Unity build | no | no | -| unity_size {>=2} | 4 | Unity file block size | no | no | -| warning_level {0, 1, 2, 3} | 1 | Set the warning level. From 0 = none to 3 = highest | no | yes | -| werror | false | Treat warnings as errors | no | yes | -| wrap_mode {default, nofallback,
nodownload, forcefallback, nopromote} | default | Wrap mode to use | no | no | -| force_fallback_for | [] | Force fallback for those dependencies | no | no | +| Option | Default value | Description | Is per machine | Is per subproject | +| ------------------------------------------------------------------------------------- | ------------- | -------------------------------------------------------------- | -------------- | ----------------- | +| auto_features {enabled, disabled, auto} | auto | Override value of all 'auto' features | no | no | +| backend {ninja, vs,
vs2010, vs2012, vs2013, vs2015, vs2017, vs2019, vs2022, xcode} | ninja | Backend to use | no | no | +| buildtype {plain, debug,
debugoptimized, release, minsize, custom} | debug | Build type to use | no | no | +| debug | true | Debug | no | no | +| default_library {shared, static, both} | shared | Default library type | no | yes | +| errorlogs | true | Whether to print the logs from failing tests. | no | no | +| install_umask {preserve, 0000-0777} | 022 | Default umask to apply on permissions of installed files | no | no | +| layout {mirror,flat} | mirror | Build directory layout | no | no | +| optimization {0, g, 1, 2, 3, s} | 0 | Optimization level | no | no | +| pkg_config_path {OS separated path} | '' | Additional paths for pkg-config to search before builtin paths | yes | no | +| cmake_prefix_path | [] | Additional prefixes for cmake to search before builtin paths | yes | no | +| stdsplit | true | Split stdout and stderr in test logs | no | no | +| strip | false | Strip targets on install | no | no | +| unity {on, off, subprojects} | off | Unity build | no | no | +| unity_size {>=2} | 4 | Unity file block size | no | no | +| warning_level {0, 1, 2, 3} | 1 | Set the warning level. From 0 = none to 3 = highest | no | yes | +| werror | false | Treat warnings as errors | no | yes | +| wrap_mode {default, nofallback,
nodownload, forcefallback, nopromote} | default | Wrap mode to use | no | no | +| force_fallback_for | [] | Force fallback for those dependencies | no | no | For setting optimization levels and toggling debug, you can either set the `buildtype` option, or you can @@ -98,7 +98,7 @@ from it. For example, `-Dbuildtype=debugoptimized` is the same as the two-way mapping: | buildtype | debug | optimization | -| --------- | ----- | ------------ | +| -------------- | ----- | ------------ | | plain | false | 0 | | debug | true | 0 | | debugoptimized | true | 2 | @@ -120,28 +120,31 @@ no options. The following options are available. Note that they may not be available on all platforms or with all compilers: -| Option | Default value | Possible values | Description | -|---------------|----------------|------------------------------------------------------------------|-------------------------------------------------------------------------------| -| b_asneeded | true | true, false | Use -Wl,--as-needed when linking | -| b_bitcode | false | true, false | Embed Apple bitcode, see below | -| b_colorout | always | auto, always, never | Use colored output | -| b_coverage | false | true, false | Enable coverage tracking | -| b_lundef | true | true, false | Don't allow undefined symbols when linking | -| b_lto | false | true, false | Use link time optimization | -| b_lto_threads | 0 | Any integer* | Use multiple threads for lto. *(Added in 0.57.0)* | -| b_lto_mode | default | default, thin | Select between lto modes, thin and default. *(Added in 0.57.0)* | -| b_ndebug | false | true, false, if-release | Disable asserts | -| b_pch | true | true, false | Use precompiled headers | -| b_pgo | off | off, generate, use | Use profile guided optimization | -| b_sanitize | none | see below | Code sanitizer to use | -| b_staticpic | true | true, false | Build static libraries as position independent | -| b_pie | false | true, false | Build position-independent executables (since 0.49.0) | -| b_vscrt | from_buildtype | none, md, mdd, mt, mtd, from_buildtype, static_from_buildtype | VS runtime library to use (since 0.48.0) (static_from_buildtype since 0.56.0) | - -The value of `b_sanitize` can be one of: `none`, `address`, `thread`, -`undefined`, `memory`, `address,undefined`, but note that some -compilers might not support all of them. For example Visual Studio -only supports the address sanitizer. +| Option | Default value | Possible values | Description | +| ------------- | -------------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------- | +| b_asneeded | true | true, false | Use -Wl,--as-needed when linking | +| b_bitcode | false | true, false | Embed Apple bitcode, see below | +| b_colorout | always | auto, always, never | Use colored output | +| b_coverage | false | true, false | Enable coverage tracking | +| b_lundef | true | true, false | Don't allow undefined symbols when linking | +| b_lto | false | true, false | Use link time optimization | +| b_lto_threads | 0 | Any integer† | Use multiple threads for lto. *(Added in 0.57.0)* | +| b_lto_mode | default | default, thin | Select between lto modes, thin and default. *(Added in 0.57.0)* | +| b_ndebug | false | true, false, if-release | Disable asserts | +| b_pch | true | true, false | Use precompiled headers | +| b_pgo | off | off, generate, use | Use profile guided optimization | +| b_sanitize | none or []* | see below | Code sanitizer(s) to use | +| b_staticpic | true | true, false | Build static libraries as position independent | +| b_pie | false | true, false | Build position-independent executables (since 0.49.0) | +| b_vscrt | from_buildtype | none, md, mdd, mt, mtd, from_buildtype, static_from_buildtype | VS runtime library to use (since 0.48.0) (static_from_buildtype since 0.56.0) | + +† The default and possible values of saniziers changed in 0.62. Before 0.62 they +were string values, and restricted to a specific subset of values: `none`, +`address`, `thread`, `undefined`, `memory`, or `address,undefined`. In 0.62 it +was changed to a free form array of sanitizers, which are checked by a compiler +and linker check. If the meson compatible version is `< 0.62` then +`get_option('b_sanitize')` will return a string value, even on later version of +meson as a compatibility feature. * < 0 means disable, == 0 means automatic selection, > 0 sets a specific number to use @@ -154,7 +157,7 @@ used internally to pick the CRT compiler arguments for `from_buildtype` or option: | buildtype | from_buildtype | static_from_buildtype | -| -------- | -------------- | --------------------- | +| -------------- | -------------- | --------------------- | | debug | `/MDd` | `/MTd` | | debugoptimized | `/MD` | `/MT` | | release | `/MD` | `/MT` | @@ -181,23 +184,23 @@ The following options are available. They can be set by passing the possible values they can take will depend on the target platform or compiler being used: -| Option | Default value | Possible values | Description | -| ------ | ------------- | --------------- | ----------- | -| c_args | | free-form comma-separated list | C compile arguments to use | -| c_link_args | | free-form comma-separated list | C link arguments to use | -| c_std | none | none, c89, c99, c11, c17, c18, c2x, gnu89, gnu99, gnu11, gnu17, gnu18, gnu2x | C language standard to use | -| c_winlibs | see below | free-form comma-separated list | Standard Windows libs to link against | -| c_thread_count | 4 | integer value ≥ 0 | Number of threads to use with emcc when using threads | -| cpp_args | | free-form comma-separated list | C++ compile arguments to use | -| cpp_link_args | | free-form comma-separated list | C++ link arguments to use | -| cpp_std | none | none, c++98, c++03, c++11, c++14, c++17, c++20
c++2a, c++1z, gnu++03, gnu++11, gnu++14, gnu++17, gnu++1z,
gnu++2a, gnu++20, vc++14, vc++17, vc++latest | C++ language standard to use | -| cpp_debugstl | false | true, false | C++ STL debug mode | -| cpp_eh | default | none, default, a, s, sc | C++ exception handling type | -| cpp_rtti | true | true, false | Whether to enable RTTI (runtime type identification) | -| cpp_thread_count | 4 | integer value ≥ 0 | Number of threads to use with emcc when using threads | -| cpp_winlibs | see below | free-form comma-separated list | Standard Windows libs to link against | -| fortran_std | none | [none, legacy, f95, f2003, f2008, f2018] | Fortran language standard to use | -| cuda_ccbindir | | filesystem path | CUDA non-default toolchain directory to use (-ccbin) *(Added in 0.57.1)* | +| Option | Default value | Possible values | Description | +| ---------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | +| c_args | | free-form comma-separated list | C compile arguments to use | +| c_link_args | | free-form comma-separated list | C link arguments to use | +| c_std | none | none, c89, c99, c11, c17, c18, c2x, gnu89, gnu99, gnu11, gnu17, gnu18, gnu2x | C language standard to use | +| c_winlibs | see below | free-form comma-separated list | Standard Windows libs to link against | +| c_thread_count | 4 | integer value ≥ 0 | Number of threads to use with emcc when using threads | +| cpp_args | | free-form comma-separated list | C++ compile arguments to use | +| cpp_link_args | | free-form comma-separated list | C++ link arguments to use | +| cpp_std | none | none, c++98, c++03, c++11, c++14, c++17, c++20
c++2a, c++1z, gnu++03, gnu++11, gnu++14, gnu++17, gnu++1z,
gnu++2a, gnu++20, vc++14, vc++17, vc++latest | C++ language standard to use | +| cpp_debugstl | false | true, false | C++ STL debug mode | +| cpp_eh | default | none, default, a, s, sc | C++ exception handling type | +| cpp_rtti | true | true, false | Whether to enable RTTI (runtime type identification) | +| cpp_thread_count | 4 | integer value ≥ 0 | Number of threads to use with emcc when using threads | +| cpp_winlibs | see below | free-form comma-separated list | Standard Windows libs to link against | +| fortran_std | none | [none, legacy, f95, f2003, f2008, f2018] | Fortran language standard to use | +| cuda_ccbindir | | filesystem path | CUDA non-default toolchain directory to use (-ccbin) *(Added in 0.57.1)* | The default values of `c_winlibs` and `cpp_winlibs` are in compiler-specific argument forms, but the libraries are: kernel32, @@ -269,10 +272,10 @@ name with the module name: `-D.