Ryan Ofsky 34aeb70748 cmake: Avoid fuzzer "multiple definition of `main'" errors
This change builds libraries with -fsanitize=fuzzer-no-link instead of
-fsanitize=fuzzer when the cmake -DSANITIZERS=fuzzer option is specified. This
is necessary to make fuzzing and IPC cmake options compatible with each other
and avoid CI failures in #30975 which enables IPC in the fuzzer CI build:

https://cirrus-ci.com/task/5366255504326656?logs=ci#L2817
https://cirrus-ci.com/task/5233064575500288?logs=ci#L2384

The failures can also be reproduced by checking out #31741 and building with
`cmake -B build -DBUILD_FOR_FUZZING=ON -DSANITIZERS=fuzzer -DENABLE_IPC=ON`
with this fix reverted.

The fix updates the cmake build so when -DSANITIZERS=fuzzer is specified, the
fuzz test binary is built with -fsanitize=fuzzer (so it can use libFuzzer's
main function), and libraries are built with -fsanitize=fuzzer-no-link (so they
can be linked into other executables with their own main functions).

Previously when -DSANITIZERS=fuzzer was specified, -fsanitize=fuzzer was
applied to ALL libraries and executables. This was inappropriate because it
made it impossible to build any executables other than the fuzz test executable
without triggering link errors:

- "multiple definition of `main'"
- "undefined reference to `LLVMFuzzerTestOneInput'"

if they depended on any libraries instrumented for fuzzing.

This was especially a problem when the ENABLE_IPC option was set because it
made building the mpgen code generator impossible so nothing else that depended
on generated sources, including the fuzz test binary, could be built either.

This commit was previously part of
https://github.com/bitcoin/bitcoin/pull/31741 and had some discussion there
starting in
https://github.com/bitcoin/bitcoin/pull/31741#pullrequestreview-2619682385
2025-03-04 14:45:05 -05:00
..
2025-02-18 12:29:18 +00:00
2024-10-25 18:09:36 +01:00
2024-09-17 09:54:18 +02:00
2024-11-11 14:14:39 +00:00
2024-11-26 20:47:08 -05:00
2024-12-05 14:37:47 +00:00
2024-08-04 08:51:36 +02:00
2024-11-04 14:19:40 -05:00
2024-09-10 11:20:40 -03:00
2025-01-22 11:29:05 +01:00
2025-01-22 11:29:05 +01:00
2025-01-14 19:01:53 +01:00
2024-10-21 23:24:17 +02:00
2024-08-29 13:49:57 +02:00
2024-12-19 13:46:52 +01:00
2024-12-31 00:04:20 -03:00
2024-12-31 00:04:20 -03:00