* [PATCH v2 1/3] meson: specify fuzz linker script as a project arg
2020-09-02 17:36 [PATCH v2 0/3] Fix oss-fuzz builds post-meson integration Alexander Bulekov
@ 2020-09-02 17:36 ` Alexander Bulekov
2020-09-02 17:36 ` [PATCH v2 2/3] fuzz: Add support for custom fuzzing library Alexander Bulekov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Bulekov @ 2020-09-02 17:36 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Thomas Huth, Alexander Bulekov, Bandan Das,
Stefan Hajnoczi, pbonzini
With this change, the fuzzer-linker script should be specified outside
any --start-group/--end-group pairs. We need this on oss-fuzz, where
partially applying the linker-script results in a linker failure
Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
---
meson.build | 9 ++++++++-
tests/qtest/fuzz/meson.build | 3 ---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/meson.build b/meson.build
index 74f8ea0c2e..94413c2c25 100644
--- a/meson.build
+++ b/meson.build
@@ -40,6 +40,14 @@ add_project_link_arguments(config_host['QEMU_LDFLAGS'].split(),
add_project_arguments(config_host['QEMU_INCLUDES'].split(),
language: ['c', 'cpp', 'objc'])
+# Specify linker-script with add_project_link_arguments so that it is not placed
+# within a linker --start-group/--end-group pair
+if 'CONFIG_FUZZ' in config_host
+ add_project_link_arguments(['-Wl,-T,',
+ (meson.current_source_dir() / 'tests/qtest/fuzz/fork_fuzz.ld')],
+ native: false, language: ['c', 'cpp', 'objc'])
+endif
+
python = import('python').find_installation()
link_language = meson.get_external_property('link_language', 'cpp')
@@ -1019,7 +1027,6 @@ foreach target : target_dirs
'gui': false,
'sources': specific_fuzz.sources(),
'dependencies': specific_fuzz.dependencies(),
- 'link_depends': [files('tests/qtest/fuzz/fork_fuzz.ld')],
}]
endif
else
diff --git a/tests/qtest/fuzz/meson.build b/tests/qtest/fuzz/meson.build
index bb0a3f271d..bcc393828e 100644
--- a/tests/qtest/fuzz/meson.build
+++ b/tests/qtest/fuzz/meson.build
@@ -6,11 +6,8 @@ specific_fuzz_ss.add(when: 'CONFIG_I440FX', if_true: files('i440fx_fuzz.c'))
specific_fuzz_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('virtio_net_fuzz.c'))
specific_fuzz_ss.add(when: 'CONFIG_VIRTIO_SCSI', if_true: files('virtio_scsi_fuzz.c'))
-# unfortunately declare_dependency does not support link_depends, so
-# this will be duplicated in meson.build
fork_fuzz = declare_dependency(
link_args: ['-fsanitize=fuzzer',
- '-Wl,-T,' + (meson.current_source_dir() / 'fork_fuzz.ld'),
'-Wl,-wrap,qtest_inb',
'-Wl,-wrap,qtest_inw',
'-Wl,-wrap,qtest_inl',
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] fuzz: Add support for custom fuzzing library
2020-09-02 17:36 [PATCH v2 0/3] Fix oss-fuzz builds post-meson integration Alexander Bulekov
2020-09-02 17:36 ` [PATCH v2 1/3] meson: specify fuzz linker script as a project arg Alexander Bulekov
@ 2020-09-02 17:36 ` Alexander Bulekov
2020-09-02 17:36 ` [PATCH v2 3/3] scripts/oss-fuzz/build.sh: fix rpath Alexander Bulekov
2020-09-02 17:47 ` [PATCH v2 0/3] Fix oss-fuzz builds post-meson integration Paolo Bonzini
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Bulekov @ 2020-09-02 17:36 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Thomas Huth, Alexander Bulekov, Bandan Das,
Stefan Hajnoczi, pbonzini
On oss-fuzz, we must use the LIB_FUZZING_ENGINE and CFLAGS environment
variables, rather than -fsanitize=fuzzer. With this change, when
LIB_FUZZING_ENGINE is set, the --enable-fuzzing configure option will
use that environment variable during the linking stage, rather than
-fsanitize=fuzzer
Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
---
configure | 12 ++++++++++--
tests/qtest/fuzz/meson.build | 4 ++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/configure b/configure
index 6ecaff429b..15a283c64f 100755
--- a/configure
+++ b/configure
@@ -6165,7 +6165,7 @@ fi
##########################################
# checks for fuzzer
-if test "$fuzzing" = "yes" ; then
+if test "$fuzzing" = "yes" && test -z "${LIB_FUZZING_ENGINE+xxx}"; then
write_c_fuzzer_skeleton
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=fuzzer" ""; then
have_fuzzer=yes
@@ -7505,7 +7505,14 @@ if test "$have_mlockall" = "yes" ; then
echo "HAVE_MLOCKALL=y" >> $config_host_mak
fi
if test "$fuzzing" = "yes" ; then
- QEMU_CFLAGS="$QEMU_CFLAGS -fsanitize=fuzzer-no-link"
+ # If LIB_FUZZING_ENGINE is set, assume we are running on OSS-Fuzz, and the
+ # needed CFLAGS have already been provided
+ if test -z "${LIB_FUZZING_ENGINE+xxx}" ; then
+ QEMU_CFLAGS="$QEMU_CFLAGS -fsanitize=fuzzer-no-link"
+ FUZZ_EXE_LDFLAGS="-fsanitize=fuzzer"
+ else
+ FUZZ_EXE_LDFLAGS="$LIB_FUZZING_ENGINE"
+ fi
fi
if test "$plugins" = "yes" ; then
@@ -7620,6 +7627,7 @@ fi
if test "$fuzzing" != "no"; then
echo "CONFIG_FUZZ=y" >> $config_host_mak
fi
+echo "FUZZ_EXE_LDFLAGS=$FUZZ_EXE_LDFLAGS" >> $config_host_mak
if test "$edk2_blobs" = "yes" ; then
echo "DECOMPRESS_EDK2_BLOBS=y" >> $config_host_mak
diff --git a/tests/qtest/fuzz/meson.build b/tests/qtest/fuzz/meson.build
index bcc393828e..b31ace7d5a 100644
--- a/tests/qtest/fuzz/meson.build
+++ b/tests/qtest/fuzz/meson.build
@@ -7,8 +7,8 @@ specific_fuzz_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('virtio_net_fuzz.
specific_fuzz_ss.add(when: 'CONFIG_VIRTIO_SCSI', if_true: files('virtio_scsi_fuzz.c'))
fork_fuzz = declare_dependency(
- link_args: ['-fsanitize=fuzzer',
- '-Wl,-wrap,qtest_inb',
+ link_args: config_host['FUZZ_EXE_LDFLAGS'].split() +
+ ['-Wl,-wrap,qtest_inb',
'-Wl,-wrap,qtest_inw',
'-Wl,-wrap,qtest_inl',
'-Wl,-wrap,qtest_outb',
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] scripts/oss-fuzz/build.sh: fix rpath
2020-09-02 17:36 [PATCH v2 0/3] Fix oss-fuzz builds post-meson integration Alexander Bulekov
2020-09-02 17:36 ` [PATCH v2 1/3] meson: specify fuzz linker script as a project arg Alexander Bulekov
2020-09-02 17:36 ` [PATCH v2 2/3] fuzz: Add support for custom fuzzing library Alexander Bulekov
@ 2020-09-02 17:36 ` Alexander Bulekov
2020-09-02 17:47 ` [PATCH v2 0/3] Fix oss-fuzz builds post-meson integration Paolo Bonzini
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Bulekov @ 2020-09-02 17:36 UTC (permalink / raw)
To: qemu-devel
Cc: pbonzini, Bandan Das, Thomas Huth, Stefan Hajnoczi,
Alexander Bulekov
Prior to this change,
readelf -d build/out/qemu/qemu-fuzz-i386-target-virtio-net-slirp
...
0x000000000000000f (RPATH) Library rpath: ['$$ORIGIN/lib':$ORIGIN/migration:$ORIGIN/]
As of 1a4db552d8 ("ninjatool: quote dollars in variables"), we don't
need to manually double the dollars. Also, remove the single-quotes as
they are copied into the rpath.
After this change:
0x000000000000000f (RPATH) Library rpath: [$ORIGIN/lib:$ORIGIN/migration:$ORIGIN/]
Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
---
scripts/oss-fuzz/build.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/oss-fuzz/build.sh b/scripts/oss-fuzz/build.sh
index f0b7442c96..d16207eb67 100755
--- a/scripts/oss-fuzz/build.sh
+++ b/scripts/oss-fuzz/build.sh
@@ -81,7 +81,7 @@ rm qemu-fuzz-i386
# Build a second time to build the final binary with correct rpath
../configure --disable-werror --cc="$CC" --cxx="$CXX" --enable-fuzzing \
--prefix="$DEST_DIR" --bindir="$DEST_DIR" --datadir="$DEST_DIR/data/" \
- --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="-Wl,-rpath,'\$\$ORIGIN/lib'" \
+ --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="-Wl,-rpath,\$ORIGIN/lib" \
--target-list="i386-softmmu"
make "-j$(nproc)" qemu-fuzz-i386 V=1
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] Fix oss-fuzz builds post-meson integration
2020-09-02 17:36 [PATCH v2 0/3] Fix oss-fuzz builds post-meson integration Alexander Bulekov
` (2 preceding siblings ...)
2020-09-02 17:36 ` [PATCH v2 3/3] scripts/oss-fuzz/build.sh: fix rpath Alexander Bulekov
@ 2020-09-02 17:47 ` Paolo Bonzini
3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2020-09-02 17:47 UTC (permalink / raw)
To: Alexander Bulekov, qemu-devel
On 02/09/20 19:36, Alexander Bulekov wrote:
> Since v1:
> * FUZZ_LINK_COMMAND -> FUZZ_EXE_LDFLAGS
> * Add a separate call to add_project_link_arguments, rather than
> appending to config_host['QEMU_LDFLAGS']
> * Remove stray comment in tests/qtest/fuzz/meson.build
>
> QEMU stopped building on oss-fuzz, after the meson integration, due to
> some linking issues:
>
> https://oss-fuzz-build-logs.storage.googleapis.com/log-3eaddfbd-7e05-4ddd-9d86-ee4b16c0fac6.txt
>
> Those problems should be partially fixed by:
>
> Depends-on: meson: fix libqos linking
> (https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg00802.html)
>
> These patches:
> 1. Build on the above patch to fix the way we specify the linker script,
> to ensure that it is not specified within start-group/end-group linker
> pairs
> 2. Add support for running --enable-fuzzing with a custom LIB_FUZZING_ENGINE
> 3. Fix a problem with how we specify custom rpath in the oss-fuzz
> build-script
>
> Alexander Bulekov (3):
> meson: specify fuzz linker script as a project arg
> fuzz: Add support for custom fuzzing library
> scripts/oss-fuzz/build.sh: fix rpath
>
> configure | 12 ++++++++++--
> meson.build | 9 ++++++++-
> scripts/oss-fuzz/build.sh | 2 +-
> tests/qtest/fuzz/meson.build | 7 ++-----
> 4 files changed, 21 insertions(+), 9 deletions(-)
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread