Fix sanitizer errors with clang 18.1.1
v3 cover Fix sanitizer errors with clang 18.1.1
I upgraded my Fedora Asahi Remix from 39 to 40 and found new sanitizer errors with clang it ships so here are fixes.
The patch "meson: Drop the .fa library prefix" may have a broad impact to the build system so please tell me if you have a concern with it.
To: Michael Tokarev <[email protected]>
To: Laurent Vivier <[email protected]>
To: Paolo Bonzini <[email protected]>
To: Marc-André Lureau <[email protected]>
To: Daniel P. Berrangé <[email protected]>
To: Thomas Huth <[email protected]>
To: Philippe Mathieu-Daudé <[email protected]>
To: Alex Bennée <[email protected]>
To: Wainer dos Santos Moschetta <[email protected]>
To: Beraldo Leal <[email protected]>
To: Richard Henderson <[email protected]>
To: Laurent Vivier <[email protected]>
Changes in v3:
- Moved changes that should belong to patch "meson: Drop the .fa library prefix" from patch "meson: Add -fno-sanitize=function".
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Added more patches and converted them to a series.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Akihiko Odaki (3):
qemu-keymap: Free xkb allocations
meson: Add -fno-sanitize=function
meson: Drop the .fa library prefix
docs/devel/build-system.rst | 5 ----- meson.build | 19 +++---------------- qemu-keymap.c | 3 +++ stubs/blk-exp-close-all.c | 2 +- .gitlab-ci.d/buildtest-template.yml | 2 -- .gitlab-ci.d/buildtest.yml | 2 -- gdbstub/meson.build | 2 -- tcg/meson.build | 2 -- tests/Makefile.include | 2 +- tests/qtest/libqos/meson.build | 1 - 10 files changed, 8 insertions(+), 32 deletions(-)
---
base-commit: c25df57ae8f9fe1c72eee2dab37d76d904ac382e
change-id: 20240501-xkb-258483ccc5d8
Best regards,
Signature · 1 line
Akihiko Odaki <[email protected]>
PATCH v3 1/3 qemu-keymap: Free xkb allocations
This fixes LeakSanitizer complaints with xkbcommon 1.6.0.
--- qemu-keymap.c | 3 +++ 1 file changed, 3 insertions(+)
qemu-keymap.c +3 -0
@@ -237,6 +237,9 @@ int main(int argc, char *argv[])xkb_state_unref (state); state =NULL ; +xkb_keymap_unref (map); +xkb_context_unref (ctx); +/* add quirks */ fprintf (outfile, "\n"
Signature · 1 line
2.45.1
Re: [PATCH v3 1/3] qemu-keymap: Free xkb allocations
Quoted 13 lines · Akihiko Odaki
This fixes LeakSanitizer complaints with xkbcommon 1.6.0.
Signed-off-by Akihiko Odaki <[email protected]>--- qemu-keymap.c | 3 +++ 1 file changed, 3 insertions(+)qemu-keymap.c +0
-0
qemu-keymap.c int main(int argc, char *argv[]) · line 245
Quoted 9 lines
qemu-keymap.c +3
-0@@ -237,6 +237,9 @@ int main(int argc, char *argv[])xkb_state_unref (state); state =NULL ; +xkb_keymap_unref (map); +xkb_context_unref (ctx); +/* add quirks */ fprintf (outfile, "\n"
This is surely a sanitizer bug. We're unconditionally about to exit() the program here, where everything is freed, so nothing is leaked.
thanks
-- PMM
Re: [PATCH v3 1/3] qemu-keymap: Free xkb allocations
22.05.2024 14:35, Peter Maydell wrote:
...
Quoted 3 lines
This is surely a sanitizer bug. We're unconditionally about to
exit()the program here, where everything is freed, so nothing is leaked.
https://lists.nongnu.org/archive/html/qemu-devel/2024-05/msg00658.html fwiw.
/mjt
Signature · 4 lines
GPG Key transition (from rsa2048 to rsa4096) since 2024-04-24. New key: rsa4096/61AD3D98ECDF2C8E 9D8B E14E 3F2A 9DD7 9199 28F1 61AD 3D98 ECDF 2C8E Old key: rsa2048/457CE0A0804465C5 6EE1 95D1 886E 8FFB 810D 4324 457C E0A0 8044 65C5 Transition statement: http://www.corpit.ru/mjt/gpg-transition-2024.txt
Daniel P. Berrangé
Reviewed-byRe: [PATCH v3 1/3] qemu-keymap: Free xkb allocations
In reply to Peter MaydellQuoted 17 lines · Peter Maydell
Quoted 16 lines · Akihiko Odaki
This fixes LeakSanitizer complaints with xkbcommon 1.6.0.
Signed-off-by Akihiko Odaki <[email protected]>--- qemu-keymap.c | 3 +++ 1 file changed, 3 insertions(+)qemu-keymap.c +0
-0@@ -237,6 +237,9 @@ int main(int argc, char *argv[])xkb_state_unref (state); state =NULL ;
Quoted 10 lines
qemu-keymap.c int main(int argc, char *argv[]) · line 245
Quoted 6 lines
qemu-keymap.c +3
-0+xkb_keymap_unref (map); +xkb_context_unref (ctx); +/* add quirks */ fprintf (outfile, "\n"This is surely a sanitizer bug. We're unconditionally about to
exit()the program here, where everything is freed, so nothing is leaked.
I'm not sure I'd call it a sanitizer bug, rather its expected behaviour of sanitizers. Even if you're about to exit, its important to see info about all memory that is not freed by that time, since it can reveal leaks that were ongoing in the process that are valid things to fix. To make the sanitizers usable you need to get rid of the noise. IOW, either have to provide a file to supress reports of memory that is expected to remain allocated, or have to free it despite being about to exit. Free'ing is the more maintainable strategy, as IME, supression files get outdated over time.
So as long as the free'ing action is not unreasonably expensive, we should just do its, so from my POV I'd
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v3 1/3] qemu-keymap: Free xkb allocations
Quoted 30 lines · Daniel P. Berrangé
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Akihiko Odaki
This fixes LeakSanitizer complaints with xkbcommon 1.6.0.
Signed-off-by Akihiko Odaki <[email protected]>--- qemu-keymap.c | 3 +++ 1 file changed, 3 insertions(+)qemu-keymap.c +0
-0@@ -237,6 +237,9 @@ int main(int argc, char *argv[])xkb_state_unref (state); state =NULL ;Quoted 10 lines
qemu-keymap.c int main(int argc, char *argv[]) · line 245
Quoted 6 lines
qemu-keymap.c +3
-0+xkb_keymap_unref (map); +xkb_context_unref (ctx); +/* add quirks */ fprintf (outfile, "\n"This is surely a sanitizer bug. We're unconditionally about to
exit()the program here, where everything is freed, so nothing is leaked.
Quoted 9 lines
I'm not sure I'd call it a sanitizer bug, rather its expected behaviour of sanitizers. Even if you're about to exit, its important to see info about all memory that is not freed by that time, since it can reveal leaks that were ongoing in the process that are valid things to fix. To make the sanitizers usable you need to get rid of the noise. IOW, either have to provide a file to supress reports of memory that is expected to remain allocated, or have to free it despite being about to exit. Free'ing is the more maintainable strategy, as IME, supression files get outdated over time.
I think if there's still a live variable pointing to the unfreed memory at point of exit the compiler/sanitizer should be able to deduce that that's not a real leak. And if you believe that these really are leaks then you also need to be fixing them on the early exit paths, like the one where we exit(1) if xkb_keymap_new_from_names() fails.
I don't object to this change, but I think that if the sanitizer complains about this kind of thing it's a bug, because it obscures real leaks.
-- PMM
Re: [PATCH v3 1/3] qemu-keymap: Free xkb allocations
Quoted 48 lines · Peter Maydell
Quoted 30 lines · Daniel P. Berrangé
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Akihiko Odaki
This fixes LeakSanitizer complaints with xkbcommon 1.6.0.
Signed-off-by Akihiko Odaki <[email protected]>--- qemu-keymap.c | 3 +++ 1 file changed, 3 insertions(+)qemu-keymap.c +0
-0@@ -237,6 +237,9 @@ int main(int argc, char *argv[])xkb_state_unref (state); state =NULL ;Quoted 10 lines
qemu-keymap.c int main(int argc, char *argv[]) · line 245
Quoted 6 lines
qemu-keymap.c +3
-0+xkb_keymap_unref (map); +xkb_context_unref (ctx); +/* add quirks */ fprintf (outfile, "\n"This is surely a sanitizer bug. We're unconditionally about to
exit()the program here, where everything is freed, so nothing is leaked.Quoted 9 lines
I'm not sure I'd call it a sanitizer bug, rather its expected behaviour of sanitizers. Even if you're about to exit, its important to see info about all memory that is not freed by that time, since it can reveal leaks that were ongoing in the process that are valid things to fix. To make the sanitizers usable you need to get rid of the noise. IOW, either have to provide a file to supress reports of memory that is expected to remain allocated, or have to free it despite being about to exit. Free'ing is the more maintainable strategy, as IME, supression files get outdated over time.
I think if there's still a live variable pointing to the unfreed memory at point of exit the compiler/sanitizer should be able to deduce that that's not a real leak. And if you believe that these really are leaks then you also need to be fixing them on the early exit paths, like the one where we exit(1) if
xkb_keymap_new_from_names()fails.
Quoted 3 lines
I don't object to this change, but I think that if the sanitizer complains about this kind of thing it's a bug, because it obscures real leaks.
The sanitizer can certainly be improved to keep the automatic variables alive when there is exit(), but I'm a bit sympathetic with the sanitizer.
Covering such a case requires the sanitizer to know that exit() terminates the process. Perhaps the sanitizer can look for __attribute__((noreturn)) and __builtin_unreachable(), but they may not be present and not reliable. I think it is a legitimate design decision not to try to deal with this kind of situation instead of partially handling it with attributes and builtin calls.
Regards,
Akihiko Odaki
PATCH v3 2/3 meson: Add -fno-sanitize=function
In reply to Akihiko Odaki-fsanitize=function enforces the consistency of function types, but include/qemu/lockable.h contains function pointer casts, which violate the rule. We already disables exact type checks for CFI with -fsanitize-cfi-icall-generalize-pointers so disable -fsanitize=function as well.
--- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meson.build +1 -1
@@ -298,7 +298,7 @@ endforeach qemu_common_flags = [ '-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', - '-fno-strict-aliasing', '-fno-common', '-fwrapv' ] + '-fno-sanitize=function', '-fno-strict-aliasing', '-fno-common', '-fwrapv' ] qemu_cflags = [] qemu_ldflags = []
Signature · 1 line
2.45.1
Re: [PATCH v3 2/3] meson: Add -fno-sanitize=function
Quoted 5 lines · Akihiko Odaki
-fsanitize=function enforces the consistency of function types, but
include/qemu/lockable.hcontains function pointer casts, which violate the rule. We already disables exact type checks for CFI with -fsanitize-cfi-icall-generalize-pointers so disable -fsanitize=function as well.
Ah, I was already wondering why we didn't see this in the CFI builds yet, but now I understand :-)
Anyway, just FYI, I've also opened some bug tickets for this some days ago:
https://gitlab.com/qemu-project/qemu/-/issues/2346
https://gitlab.com/qemu-project/qemu/-/issues/2345
(I assume we still should fix the underlying issues at one point in time and remove the compiler flag here again later? Otherwise you could close these with the "Resolves:" keyword in your patch description)
meson.build endforeach · line 303
Quoted 6 lines
qemu_common_flags= ['-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE',meson.build +1
-1- '-fno-strict-aliasing', '-fno-common', '-fwrapv' ] + '-fno-sanitize=function', '-fno-strict-aliasing', '-fno-common', '-fwrapv' ] qemu_cflags = [] qemu_ldflags = []
With GCC, I get:
I think you need to add this via cc.get_supported_arguments() to make sure that we only add it for compilers that support this option.
Thomas
PATCH v3 3/3 meson: Drop the .fa library prefix
In reply to Akihiko OdakiThe non-standard .fa library prefix breaks the link source de-duplication done by Meson so drop it.
The lack of link source de-duplication causes AddressSanitizer to complain ODR violations, and makes GNU ld abort when combined with clang's LTO.
Previously, the non-standard prefix was necessary for fork-fuzzing. Meson wraps all standard-prefixed libraries with --start-group and --end-group. This made a fork-fuzz.ld linker script wrapped as well and broke builds. Commit d2e6f9272d33 ("fuzz: remove fork-fuzzing scaffolding") dropped fork-fuzzing so we can now restore the standard prefix.
The occurences of the prefix were detected and removed by performing a tree-wide search with 'fa' and .fa (note the quotes and dot).
--- docs/devel/build-system.rst | 5 ----- meson.build | 17 ++--------------- stubs/blk-exp-close-all.c | 2 +- .gitlab-ci.d/buildtest-template.yml | 2 -- .gitlab-ci.d/buildtest.yml | 2 -- gdbstub/meson.build | 2 -- tcg/meson.build | 2 -- tests/Makefile.include | 2 +- tests/qtest/libqos/meson.build | 1 - 9 files changed, 4 insertions(+), 31 deletions(-)
docs/devel/build-system.rst +0 -5
@@ -236,15 +236,10 @@ Subsystem sourcesets: are then turned into static libraries as follows:: libchardev = static_library('chardev', chardev_ss.sources(), - name_suffix: 'fa', build_by_default: false) chardev = declare_dependency(link_whole: libchardev) - As of Meson 0.55.1, the special ``.fa`` suffix should be used for everything - that is used with ``link_whole``, to ensure that the link flags are placed - correctly in the command line. - Target-independent emulator sourcesets: Various general purpose helper code is compiled only once and the .o files are linked into all output binaries that need it.
meson.build +2 -15
@@ -3462,14 +3462,12 @@ endif qom_ss = qom_ss.apply({}) libqom = static_library('qom', qom_ss.sources() + genh, dependencies: [qom_ss.dependencies()], - name_suffix: 'fa', build_by_default: false) qom = declare_dependency(link_whole: libqom) event_loop_base = files('event-loop-base.c') event_loop_base = static_library('event-loop-base', sources: event_loop_base + genh, - name_suffix: 'fa', build_by_default: false) event_loop_base = declare_dependency(link_whole: event_loop_base, dependencies: [qom])
@@ -3703,7 +3701,6 @@ qemu_syms = custom_target('qemu.syms', output: 'qemu.syms', authz_ss = authz_ss.apply({}) libauthz = static_library('authz', authz_ss.sources() + genh, dependencies: [authz_ss.dependencies()], - name_suffix: 'fa', build_by_default: false) authz = declare_dependency(link_whole: libauthz,
@@ -3712,7 +3709,6 @@ authz = declare_dependency(link_whole: libauthz, crypto_ss = crypto_ss.apply({}) libcrypto = static_library('crypto', crypto_ss.sources() + genh, dependencies: [crypto_ss.dependencies()], - name_suffix: 'fa', build_by_default: false) crypto = declare_dependency(link_whole: libcrypto,
@@ -3722,13 +3718,11 @@ io_ss = io_ss.apply({}) libio = static_library('io', io_ss.sources() + genh, dependencies: [io_ss.dependencies()], link_with: libqemuutil, - name_suffix: 'fa', build_by_default: false) io = declare_dependency(link_whole: libio, dependencies: [crypto, qom]) libmigration = static_library('migration', sources: migration_files + genh, - name_suffix: 'fa', build_by_default: false) migration = declare_dependency(link_with: libmigration, dependencies: [zlib, qom, io])
@@ -3738,7 +3732,6 @@ block_ss = block_ss.apply({}) libblock = static_library('block', block_ss.sources() + genh, dependencies: block_ss.dependencies(), link_depends: block_syms, - name_suffix: 'fa', build_by_default: false) block = declare_dependency(link_whole: [libblock],
@@ -3748,7 +3741,6 @@ block = declare_dependency(link_whole: [libblock], blockdev_ss = blockdev_ss.apply({}) libblockdev = static_library('blockdev', blockdev_ss.sources() + genh, dependencies: blockdev_ss.dependencies(), - name_suffix: 'fa', build_by_default: false) blockdev = declare_dependency(link_whole: [libblockdev],
@@ -3757,13 +3749,11 @@ blockdev = declare_dependency(link_whole: [libblockdev], qmp_ss = qmp_ss.apply({}) libqmp = static_library('qmp', qmp_ss.sources() + genh, dependencies: qmp_ss.dependencies(), - name_suffix: 'fa', build_by_default: false) qmp = declare_dependency(link_whole: [libqmp]) libchardev = static_library('chardev', chardev_ss.sources() + genh, - name_suffix: 'fa', dependencies: chardev_ss.dependencies(), build_by_default: false)
@@ -3771,7 +3761,6 @@ chardev = declare_dependency(link_whole: libchardev) hwcore_ss = hwcore_ss.apply({}) libhwcore = static_library('hwcore', sources: hwcore_ss.sources() + genh, - name_suffix: 'fa', build_by_default: false) hwcore = declare_dependency(link_whole: libhwcore) common_ss.add(hwcore)
@@ -3807,8 +3796,7 @@ common_all = static_library('common', sources: common_ss.all_sources() + genh, include_directories: common_user_inc, implicit_include_directories: false, - dependencies: common_ss.all_dependencies(), - name_suffix: 'fa') + dependencies: common_ss.all_dependencies()) feature_to_c = find_program('scripts/feature_to_c.py')
@@ -3909,8 +3897,7 @@ foreach target : target_dirs objects: objects, include_directories: target_inc, c_args: c_args, - build_by_default: false, - name_suffix: 'fa') + build_by_default: false) if target.endswith('-softmmu') execs = [{
stubs/blk-exp-close-all.c +1 -1
@@ -1,7 +1,7 @@#include "qemu/osdep.h" #include "block/export.h" -/* Only used in programs that support block exports (libblockdev.fa) */ +/* Only used in programs that support block exports (libblockdev.a) */ void blk_exp_close_all (void ) { }
.gitlab-ci.d/buildtest-template.yml +0 -2
@@ -45,10 +45,8 @@ exclude: - build/**/*.p - build/**/*.a.p - - build/**/*.fa.p - build/**/*.c.o - build/**/*.c.o.d - - build/**/*.fa .common_test_job_template: extends: .base_job_template
.gitlab-ci.d/buildtest.yml +0 -2
@@ -178,10 +178,8 @@ build-previous-qemu: exclude: - build-previous/**/*.p - build-previous/**/*.a.p - - build-previous/**/*.fa.p - build-previous/**/*.c.o - build-previous/**/*.c.o.d - - build-previous/**/*.fa needs: job: amd64-opensuse-leap-container variables:
gdbstub/meson.build +0 -2
@@ -19,13 +19,11 @@ gdb_system_ss = gdb_system_ss.apply({}) libgdb_user = static_library('gdb_user', gdb_user_ss.sources() + genh, - name_suffix: 'fa', c_args: '-DCONFIG_USER_ONLY', build_by_default: false) libgdb_system = static_library('gdb_system', gdb_system_ss.sources() + genh, - name_suffix: 'fa', build_by_default: false) gdb_user = declare_dependency(link_whole: libgdb_user)
tcg/meson.build +0 -2
@@ -31,7 +31,6 @@ tcg_ss = tcg_ss.apply({}) libtcg_user = static_library('tcg_user', tcg_ss.sources() + genh, - name_suffix: 'fa', c_args: '-DCONFIG_USER_ONLY', build_by_default: false)
@@ -41,7 +40,6 @@ user_ss.add(tcg_user) libtcg_system = static_library('tcg_system', tcg_ss.sources() + genh, - name_suffix: 'fa', c_args: '-DCONFIG_SOFTMMU', build_by_default: false)
tests/Makefile.include +1 -1
@@ -87,7 +87,7 @@ distclean-tcg: $(DISTCLEAN_TCG_TARGET_RULES) .PHONY: check-venv check-avocado check-acceptance check-acceptance-deprecated-warning # Build up our target list from the filtered list of ninja targets -TARGETS=$(patsubst libqemu-%.fa, %, $(filter libqemu-%.fa, $(ninja-targets))) +TARGETS=$(patsubst libqemu-%.a, %, $(filter libqemu-%.a, $(ninja-targets))) TESTS_VENV_TOKEN=$(BUILD_DIR)/pyvenv/tests.group TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/results
tests/qtest/libqos/meson.build +0 -1
@@ -68,7 +68,6 @@ if have_virtfs endif libqos = static_library('qos', libqos_srcs + genh, - name_suffix: 'fa', build_by_default: false) qos = declare_dependency(link_whole: libqos)
Signature · 1 line
2.45.1
Re: [PATCH v3 3/3] meson: Drop the .fa library prefix
Quoted 2 lines · Akihiko Odaki
The non-standard .fa library prefix breaks the link source de-duplication done by Meson so drop it.
Can you show the difference in the command lines?
One possibility to force de-duplication of objects is to change "link_whole: foo" to "objects: foo.extract_all_objects(recursive:
false)" in all the declare_dependency() invocations that involve a 'fa' archive.
This completely gets rid of the archives, which now become just a dummy target. I have gotten reports of "ld" exhausting the limit of open files when using thin archives (thin archives contain "symbolic links" to the files with the actual object code, thus reducing disk usage), and this would also be fixed.
The disadvantage is requiring a bump to Meson 1.1.x as the minimum required version (the recommended version is 1.2.x because earlier versions are incompatible with recent macOS). It could be done before this patch (because then this patch is a total no-op), or after too to fix the immediate issue with sanitizer builds.
Paolo
Quoted 264 lines
The lack of link source de-duplication causes AddressSanitizer to complain ODR violations, and makes GNU ld abort when combined with clang's LTO.
Previously, the non-standard prefix was necessary for fork-fuzzing. Meson wraps all standard-prefixed libraries with --start-group and --end-group. This made a fork-fuzz.ld linker script wrapped as well and broke builds. Commit
d2e6f9272d33("fuzz: remove fork-fuzzing scaffolding") dropped fork-fuzzing so we can now restore the standard prefix.The occurences of the prefix were detected and removed by performing a tree-wide search with 'fa' and .fa (note the quotes and dot).
Signed-off-by Akihiko Odaki <[email protected]>--- docs/devel/build-system.rst | 5 ----- meson.build | 17 ++--------------- stubs/blk-exp-close-all.c | 2 +- .gitlab-ci.d/buildtest-template.yml | 2 -- .gitlab-ci.d/buildtest.yml | 2 -- gdbstub/meson.build | 2 -- tcg/meson.build | 2 -- tests/Makefile.include | 2 +- tests/qtest/libqos/meson.build | 1 - 9 files changed, 4 insertions(+), 31 deletions(-)docs/devel/build-system.rst +0
-5@@ -236,15 +236,10 @@ Subsystem sourcesets: are then turned into static libraries as follows:: libchardev = static_library('chardev', chardev_ss.sources(), - name_suffix: 'fa', build_by_default: false) chardev = declare_dependency(link_whole: libchardev) - As of Meson 0.55.1, the special ``.fa`` suffix should be used for everything - that is used with ``link_whole``, to ensure that the link flags are placed - correctly in the command line. - Target-independent emulator sourcesets: Various general purpose helper code is compiled only once and the .o files are linked into all output binaries that need it.meson.build +2
-15@@ -3462,14 +3462,12 @@ endif qom_ss = qom_ss.apply({}) libqom = static_library('qom', qom_ss.sources() + genh, dependencies: [qom_ss.dependencies()], - name_suffix: 'fa', build_by_default: false) qom = declare_dependency(link_whole: libqom) event_loop_base = files('event-loop-base.c') event_loop_base = static_library('event-loop-base', sources: event_loop_base + genh, - name_suffix: 'fa', build_by_default: false) event_loop_base = declare_dependency(link_whole: event_loop_base, dependencies: [qom])@@ -3703,7 +3701,6 @@ qemu_syms = custom_target('qemu.syms', output: 'qemu.syms', authz_ss = authz_ss.apply({}) libauthz = static_library('authz', authz_ss.sources() + genh, dependencies: [authz_ss.dependencies()], - name_suffix: 'fa', build_by_default: false) authz = declare_dependency(link_whole: libauthz,@@ -3712,7 +3709,6 @@ authz = declare_dependency(link_whole: libauthz, crypto_ss = crypto_ss.apply({}) libcrypto = static_library('crypto', crypto_ss.sources() + genh, dependencies: [crypto_ss.dependencies()], - name_suffix: 'fa', build_by_default: false) crypto = declare_dependency(link_whole: libcrypto,@@ -3722,13 +3718,11 @@ io_ss = io_ss.apply({}) libio = static_library('io', io_ss.sources() + genh, dependencies: [io_ss.dependencies()], link_with: libqemuutil, - name_suffix: 'fa', build_by_default: false) io = declare_dependency(link_whole: libio, dependencies: [crypto, qom]) libmigration = static_library('migration', sources: migration_files + genh, - name_suffix: 'fa', build_by_default: false) migration = declare_dependency(link_with: libmigration, dependencies: [zlib, qom, io])@@ -3738,7 +3732,6 @@ block_ss = block_ss.apply({}) libblock = static_library('block', block_ss.sources() + genh, dependencies: block_ss.dependencies(), link_depends: block_syms, - name_suffix: 'fa', build_by_default: false) block = declare_dependency(link_whole: [libblock],@@ -3748,7 +3741,6 @@ block = declare_dependency(link_whole: [libblock], blockdev_ss = blockdev_ss.apply({}) libblockdev = static_library('blockdev', blockdev_ss.sources() + genh, dependencies: blockdev_ss.dependencies(), - name_suffix: 'fa', build_by_default: false) blockdev = declare_dependency(link_whole: [libblockdev],@@ -3757,13 +3749,11 @@ blockdev = declare_dependency(link_whole: [libblockdev], qmp_ss = qmp_ss.apply({}) libqmp = static_library('qmp', qmp_ss.sources() + genh, dependencies: qmp_ss.dependencies(), - name_suffix: 'fa', build_by_default: false) qmp = declare_dependency(link_whole: [libqmp]) libchardev = static_library('chardev', chardev_ss.sources() + genh, - name_suffix: 'fa', dependencies: chardev_ss.dependencies(), build_by_default: false)@@ -3771,7 +3761,6 @@ chardev = declare_dependency(link_whole: libchardev) hwcore_ss = hwcore_ss.apply({}) libhwcore = static_library('hwcore', sources: hwcore_ss.sources() + genh, - name_suffix: 'fa', build_by_default: false) hwcore = declare_dependency(link_whole: libhwcore) common_ss.add(hwcore)@@ -3807,8 +3796,7 @@ common_all = static_library('common', sources: common_ss.all_sources() + genh, include_directories: common_user_inc, implicit_include_directories: false, - dependencies: common_ss.all_dependencies(), - name_suffix: 'fa') + dependencies: common_ss.all_dependencies()) feature_to_c = find_program('scripts/feature_to_c.py')@@ -3909,8 +3897,7 @@ foreach target : target_dirs objects: objects, include_directories: target_inc, c_args: c_args, - build_by_default: false, - name_suffix: 'fa') + build_by_default: false) if target.endswith('-softmmu') execs = [{stubs/blk-exp-close-all.c +1
-1@@ -1,7 +1,7 @@#include "qemu/osdep.h" #include "block/export.h" -/* Only used in programs that support block exports (libblockdev.fa) */ +/* Only used in programs that support block exports (libblockdev.a) */ void blk_exp_close_all (void ) { }.gitlab-ci.d/buildtest-template.yml +0
-2@@ -45,10 +45,8 @@ exclude: - build/**/*.p - build/**/*.a.p - - build/**/*.fa.p - build/**/*.c.o - build/**/*.c.o.d - - build/**/*.fa .common_test_job_template: extends: .base_job_template.gitlab-ci.d/buildtest.yml +0
-2@@ -178,10 +178,8 @@ build-previous-qemu: exclude: - build-previous/**/*.p - build-previous/**/*.a.p - - build-previous/**/*.fa.p - build-previous/**/*.c.o - build-previous/**/*.c.o.d - - build-previous/**/*.fa needs: job: amd64-opensuse-leap-container variables:gdbstub/meson.build +0
-2@@ -19,13 +19,11 @@ gdb_system_ss = gdb_system_ss.apply({}) libgdb_user = static_library('gdb_user', gdb_user_ss.sources() + genh, - name_suffix: 'fa', c_args: '-DCONFIG_USER_ONLY', build_by_default: false) libgdb_system = static_library('gdb_system', gdb_system_ss.sources() + genh, - name_suffix: 'fa', build_by_default: false) gdb_user = declare_dependency(link_whole: libgdb_user)tcg/meson.build +0
-2@@ -31,7 +31,6 @@ tcg_ss = tcg_ss.apply({}) libtcg_user = static_library('tcg_user', tcg_ss.sources() + genh, - name_suffix: 'fa', c_args: '-DCONFIG_USER_ONLY', build_by_default: false)@@ -41,7 +40,6 @@ user_ss.add(tcg_user) libtcg_system = static_library('tcg_system', tcg_ss.sources() + genh, - name_suffix: 'fa', c_args: '-DCONFIG_SOFTMMU', build_by_default: false)tests/Makefile.include +1
-1@@ -87,7 +87,7 @@ distclean-tcg: $(DISTCLEAN_TCG_TARGET_RULES) .PHONY: check-venv check-avocado check-acceptance check-acceptance-deprecated-warning # Build up our target list from the filtered list of ninja targets -TARGETS=$(patsubst libqemu-%.fa, %, $(filter libqemu-%.fa, $(ninja-targets))) +TARGETS=$(patsubst libqemu-%.a, %, $(filter libqemu-%.a, $(ninja-targets))) TESTS_VENV_TOKEN=$(BUILD_DIR)/pyvenv/tests.group TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/resultstests/qtest/libqos/meson.build +0
-2@@ -68,7 +68,6 @@ if have_virtfs endif libqos = static_library('qos', libqos_srcs + genh, - name_suffix: 'fa', build_by_default: false) qos = declare_dependency(link_whole: libqos) --2.45.1
Re: [PATCH v3 3/3] meson: Drop the .fa library prefix
Quoted 12 lines · Paolo Bonzini
Quoted 2 lines · Akihiko Odaki
The non-standard .fa library prefix breaks the link source de-duplication done by Meson so drop it.
Can you show the difference in the command lines?
One possibility to force de-duplication of objects is to change "
link_whole: foo" to "objects: foo.extract_all_objects(recursive:
false)" in all thedeclare_dependency()invocations that involve a 'fa' archive.
Quoted 5 lines
This completely gets rid of the archives, which now become just a dummy target. I have gotten reports of "ld" exhausting the limit of open files when using thin archives (thin archives contain "symbolic links" to the files with the actual object code, thus reducing disk usage), and this would also be fixed.
Ah, I forgot that this would also fix an issue with link_whole dependencies (https://github.com/mesonbuild/meson/pull/8151). It would be possible to revert 3eacf70bb5a83e4775ad8003cbca63a40f70c8c2 and instead just add gnutls to the crypto variable.
Paolo
Quoted 272 lines
The disadvantage is requiring a bump to Meson 1.1.x as the minimum required version (the recommended version is 1.2.x because earlier versions are incompatible with recent macOS). It could be done before this patch (because then this patch is a total no-op), or after too to fix the immediate issue with sanitizer builds.
Paolo
Quoted 264 lines
The lack of link source de-duplication causes AddressSanitizer to complain ODR violations, and makes GNU ld abort when combined with clang's LTO.
Previously, the non-standard prefix was necessary for fork-fuzzing. Meson wraps all standard-prefixed libraries with --start-group and --end-group. This made a fork-fuzz.ld linker script wrapped as well and broke builds. Commit
d2e6f9272d33("fuzz: remove fork-fuzzing scaffolding") dropped fork-fuzzing so we can now restore the standard prefix.The occurences of the prefix were detected and removed by performing a tree-wide search with 'fa' and .fa (note the quotes and dot).
Signed-off-by Akihiko Odaki <[email protected]>--- docs/devel/build-system.rst | 5 ----- meson.build | 17 ++--------------- stubs/blk-exp-close-all.c | 2 +- .gitlab-ci.d/buildtest-template.yml | 2 -- .gitlab-ci.d/buildtest.yml | 2 -- gdbstub/meson.build | 2 -- tcg/meson.build | 2 -- tests/Makefile.include | 2 +- tests/qtest/libqos/meson.build | 1 - 9 files changed, 4 insertions(+), 31 deletions(-)docs/devel/build-system.rst +0
-5@@ -236,15 +236,10 @@ Subsystem sourcesets: are then turned into static libraries as follows:: libchardev = static_library('chardev', chardev_ss.sources(), - name_suffix: 'fa', build_by_default: false) chardev = declare_dependency(link_whole: libchardev) - As of Meson 0.55.1, the special ``.fa`` suffix should be used for everything - that is used with ``link_whole``, to ensure that the link flags are placed - correctly in the command line. - Target-independent emulator sourcesets: Various general purpose helper code is compiled only once and the .o files are linked into all output binaries that need it.meson.build +2
-15@@ -3462,14 +3462,12 @@ endif qom_ss = qom_ss.apply({}) libqom = static_library('qom', qom_ss.sources() + genh, dependencies: [qom_ss.dependencies()], - name_suffix: 'fa', build_by_default: false) qom = declare_dependency(link_whole: libqom) event_loop_base = files('event-loop-base.c') event_loop_base = static_library('event-loop-base', sources: event_loop_base + genh, - name_suffix: 'fa', build_by_default: false) event_loop_base = declare_dependency(link_whole: event_loop_base, dependencies: [qom])@@ -3703,7 +3701,6 @@ qemu_syms = custom_target('qemu.syms', output: 'qemu.syms', authz_ss = authz_ss.apply({}) libauthz = static_library('authz', authz_ss.sources() + genh, dependencies: [authz_ss.dependencies()], - name_suffix: 'fa', build_by_default: false) authz = declare_dependency(link_whole: libauthz,@@ -3712,7 +3709,6 @@ authz = declare_dependency(link_whole: libauthz, crypto_ss = crypto_ss.apply({}) libcrypto = static_library('crypto', crypto_ss.sources() + genh, dependencies: [crypto_ss.dependencies()], - name_suffix: 'fa', build_by_default: false) crypto = declare_dependency(link_whole: libcrypto,@@ -3722,13 +3718,11 @@ io_ss = io_ss.apply({}) libio = static_library('io', io_ss.sources() + genh, dependencies: [io_ss.dependencies()], link_with: libqemuutil, - name_suffix: 'fa', build_by_default: false) io = declare_dependency(link_whole: libio, dependencies: [crypto, qom]) libmigration = static_library('migration', sources: migration_files + genh, - name_suffix: 'fa', build_by_default: false) migration = declare_dependency(link_with: libmigration, dependencies: [zlib, qom, io])@@ -3738,7 +3732,6 @@ block_ss = block_ss.apply({}) libblock = static_library('block', block_ss.sources() + genh, dependencies: block_ss.dependencies(), link_depends: block_syms, - name_suffix: 'fa', build_by_default: false) block = declare_dependency(link_whole: [libblock],@@ -3748,7 +3741,6 @@ block = declare_dependency(link_whole: [libblock], blockdev_ss = blockdev_ss.apply({}) libblockdev = static_library('blockdev', blockdev_ss.sources() + genh, dependencies: blockdev_ss.dependencies(), - name_suffix: 'fa', build_by_default: false) blockdev = declare_dependency(link_whole: [libblockdev],@@ -3757,13 +3749,11 @@ blockdev = declare_dependency(link_whole: [libblockdev], qmp_ss = qmp_ss.apply({}) libqmp = static_library('qmp', qmp_ss.sources() + genh, dependencies: qmp_ss.dependencies(), - name_suffix: 'fa', build_by_default: false) qmp = declare_dependency(link_whole: [libqmp]) libchardev = static_library('chardev', chardev_ss.sources() + genh, - name_suffix: 'fa', dependencies: chardev_ss.dependencies(), build_by_default: false)@@ -3771,7 +3761,6 @@ chardev = declare_dependency(link_whole: libchardev) hwcore_ss = hwcore_ss.apply({}) libhwcore = static_library('hwcore', sources: hwcore_ss.sources() + genh, - name_suffix: 'fa', build_by_default: false) hwcore = declare_dependency(link_whole: libhwcore) common_ss.add(hwcore)@@ -3807,8 +3796,7 @@ common_all = static_library('common', sources: common_ss.all_sources() + genh, include_directories: common_user_inc, implicit_include_directories: false, - dependencies: common_ss.all_dependencies(), - name_suffix: 'fa') + dependencies: common_ss.all_dependencies()) feature_to_c = find_program('scripts/feature_to_c.py')@@ -3909,8 +3897,7 @@ foreach target : target_dirs objects: objects, include_directories: target_inc, c_args: c_args, - build_by_default: false, - name_suffix: 'fa') + build_by_default: false) if target.endswith('-softmmu') execs = [{stubs/blk-exp-close-all.c +1
-1@@ -1,7 +1,7 @@#include "qemu/osdep.h" #include "block/export.h" -/* Only used in programs that support block exports (libblockdev.fa) */ +/* Only used in programs that support block exports (libblockdev.a) */ void blk_exp_close_all (void ) { }.gitlab-ci.d/buildtest-template.yml +0
-2@@ -45,10 +45,8 @@ exclude: - build/**/*.p - build/**/*.a.p - - build/**/*.fa.p - build/**/*.c.o - build/**/*.c.o.d - - build/**/*.fa .common_test_job_template: extends: .base_job_template.gitlab-ci.d/buildtest.yml +0
-2@@ -178,10 +178,8 @@ build-previous-qemu: exclude: - build-previous/**/*.p - build-previous/**/*.a.p - - build-previous/**/*.fa.p - build-previous/**/*.c.o - build-previous/**/*.c.o.d - - build-previous/**/*.fa needs: job: amd64-opensuse-leap-container variables:gdbstub/meson.build +0
-2@@ -19,13 +19,11 @@ gdb_system_ss = gdb_system_ss.apply({}) libgdb_user = static_library('gdb_user', gdb_user_ss.sources() + genh, - name_suffix: 'fa', c_args: '-DCONFIG_USER_ONLY', build_by_default: false) libgdb_system = static_library('gdb_system', gdb_system_ss.sources() + genh, - name_suffix: 'fa', build_by_default: false) gdb_user = declare_dependency(link_whole: libgdb_user)tcg/meson.build +0
-2@@ -31,7 +31,6 @@ tcg_ss = tcg_ss.apply({}) libtcg_user = static_library('tcg_user', tcg_ss.sources() + genh, - name_suffix: 'fa', c_args: '-DCONFIG_USER_ONLY', build_by_default: false)@@ -41,7 +40,6 @@ user_ss.add(tcg_user) libtcg_system = static_library('tcg_system', tcg_ss.sources() + genh, - name_suffix: 'fa', c_args: '-DCONFIG_SOFTMMU', build_by_default: false)tests/Makefile.include +1
-1@@ -87,7 +87,7 @@ distclean-tcg: $(DISTCLEAN_TCG_TARGET_RULES) .PHONY: check-venv check-avocado check-acceptance check-acceptance-deprecated-warning # Build up our target list from the filtered list of ninja targets -TARGETS=$(patsubst libqemu-%.fa, %, $(filter libqemu-%.fa, $(ninja-targets))) +TARGETS=$(patsubst libqemu-%.a, %, $(filter libqemu-%.a, $(ninja-targets))) TESTS_VENV_TOKEN=$(BUILD_DIR)/pyvenv/tests.group TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/resultstests/qtest/libqos/meson.build +0
-2@@ -68,7 +68,6 @@ if have_virtfs endif libqos = static_library('qos', libqos_srcs + genh, - name_suffix: 'fa', build_by_default: false) qos = declare_dependency(link_whole: libqos) --2.45.1
Re: [PATCH v3 3/3] meson: Drop the .fa library prefix
In reply to Paolo BonziniQuoted 5 lines · Paolo Bonzini
Quoted 2 lines · Akihiko Odaki
The non-standard .fa library prefix breaks the link source de-duplication done by Meson so drop it.
Can you show the difference in the command lines?
Without this patch:
clang -o qemu-io qemu-io.p/qemu-io.c.o -Werror -flto -Wl,--as-needed -Wl,--no-undefined -pie -Wl,--whole-archive libblock.fa libcrypto.fa libauthz.fa libqom.fa libio.fa libevent-loop-base.fa -Wl,--no-whole-archive -fsanitize=cfi-icall -fsanitize-cfi-icall-generalize-pointers -fsanitize=undefined -fsanitize=address -fstack-protector-strong -Wl,-z,relro -Wl,-z,now -fuse-ld=lld -Wl,--start-group libqemuutil.a subprojects/libvhost-user/libvhost-user-glib.a subprojects/libvhost-user/libvhost-user.a libblock.fa libcrypto.fa libauthz.fa libqom.fa libio.fa libevent-loop-base.fa @block.syms /usr/lib64/libgio-2.0.so /usr/lib64/libgobject-2.0.so /usr/lib64/libglib-2.0.so /usr/lib64/libgmodule-2.0.so -pthread /usr/lib64/libgnutls.so -lm /usr/lib64/libpixman-1.so /usr/lib64/libzstd.so /usr/lib64/libz.so /usr/lib64/libcurl.so /usr/lib64/libssh.so -lbz2 -lpam -Wl,--end-group
With this patch:
clang -o qemu-io qemu-io.p/qemu-io.c.o -Werror -flto -Wl,--as-needed -Wl,--no-undefined -pie -Wl,--whole-archive -Wl,--start-group libblock.a libcrypto.a libauthz.a libqom.a libio.a libevent-loop-base.a -Wl,--no-whole-archive -fsanitize=cfi-icall -fsanitize-cfi-icall-generalize-pointers -fsanitize=undefined -fsanitize=address -fstack-protector-strong -Wl,-z,relro -Wl,-z,now -fuse-ld=lld libqemuutil.a subprojects/libvhost-user/libvhost-user-glib.a subprojects/libvhost-user/libvhost-user.a @block.syms /usr/lib64/libgio-2.0.so /usr/lib64/libgobject-2.0.so /usr/lib64/libglib-2.0.so /usr/lib64/libgmodule-2.0.so -pthread /usr/lib64/libgnutls.so -lm /usr/lib64/libpixman-1.so /usr/lib64/libzstd.so /usr/lib64/libz.so /usr/lib64/libcurl.so /usr/lib64/libssh.so -lbz2 -lpam -Wl,--end-group
Quoted 12 lines
One possibility to force de-duplication of objects is to change "
link_whole: foo" to "objects: foo.extract_all_objects(recursive:
false)" in all thedeclare_dependency()invocations that involve a 'fa' archive.This completely gets rid of the archives, which now become just a dummy target. I have gotten reports of "ld" exhausting the limit of open files when using thin archives (thin archives contain "symbolic links" to the files with the actual object code, thus reducing disk usage), and this would also be fixed.
Quoted 5 lines
The disadvantage is requiring a bump to Meson 1.1.x as the minimum required version (the recommended version is 1.2.x because earlier versions are incompatible with recent macOS). It could be done before this patch (because then this patch is a total no-op), or after too to fix the immediate issue with sanitizer builds.
I wrote such a change and applied after this patch, but it caused dependencies to be ignored. Please see "[PATCH RFC 0/2] meson: Pass objects to declare_dependency()", which I sent earlier.
Regards,
Akihiko Odaki