Skip to contentSkip to conversation

Fix sanitizer errors with clang 18.1.1

PATCH Superseded Akihiko Odaki 2 participants 5 messages May 22, 2024 – May 23, 2024 Arm/Amlogic Meson SoC support

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 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 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]>
#1 lore raw

PATCH v2 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
index 8c80f7a4ed65..7a9f38cf9863 100644
@@ -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
#2 lore raw

PATCH v2 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 | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)
meson.build +3 -16
index 91a0aa64c640..9eaf218609eb 100644
@@ -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 = []
 
@@ -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 = [{
Signature · 1 line
2.45.1
#3 lore raw

PATCH v2 3/3 meson: Drop the .fa library prefix

In reply to Akihiko Odaki

The 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 occurances of the prefix was detected and removed by performing a tree-wide search with 'fa' and .fa (note the quotes and dot).

---
 docs/devel/build-system.rst         | 5 -----
 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 -
 8 files changed, 2 insertions(+), 16 deletions(-)
docs/devel/build-system.rst +0 -5
index 09caf2f8e199..5baf027b7614 100644
@@ -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.
stubs/blk-exp-close-all.c +1 -1
index 1c7131676392..2f68e06d7d05 100644
@@ -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
index 22045add8064..69e468a576ba 100644
@@ -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
index cfdff175c389..c156e6f1d90e 100644
@@ -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
index da5721d8452b..c91e398ae726 100644
@@ -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
index 8251589fd4e9..f941413d5801 100644
@@ -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
index c9d1674bd070..d39d5dd6a43e 100644
@@ -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
index 3aed6efcb8d1..45b81c83ade3 100644
@@ -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
#4 lore raw

Re: [PATCH v2 3/3] meson: Drop the .fa library prefix

Am 22. Mai 2024 10:43:04 UTC schrieb Akihiko Odaki <[email protected]>:

Quoted 1 line

The non-standard .fa library prefix breaks the link source

s/prefix/suffix/ in the commit message and subject.

Best regards,
Bernhard

Quoted 155 lines

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 occurances of the prefix was detected and removed by performing a tree-wide search with 'fa' and .fa (note the quotes and dot).

---

docs/devel/build-system.rst         | 5 -----
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 -
8 files changed, 2 insertions(+), 16 deletions(-)
docs/devel/build-system.rst +0 -5
index 09caf2f8e199..5baf027b7614 100644
@@ -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.

stubs/blk-exp-close-all.c +1 -1
index 1c7131676392..2f68e06d7d05 100644
@@ -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
index 22045add8064..69e468a576ba 100644
@@ -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
index cfdff175c389..c156e6f1d90e 100644
@@ -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
index da5721d8452b..c91e398ae726 100644
@@ -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
index 8251589fd4e9..f941413d5801 100644
@@ -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 +0 -0
index c9d1674bd070..d39d5dd6a43e 100644
@@ -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

tests/Makefile.include +1 -1
-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 -0
index 3aed6efcb8d1..45b81c83ade3 100644
@@ -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)