Commit 4c1906a
committed
Merge bitcoin/bitcoin#31992: cmake: Avoid fuzzer "multiple definition of `main'" errors
57d8b1f cmake: Avoid fuzzer "multiple definition of `main'" errors (Ryan Ofsky)
Pull request description:
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 bitcoin/bitcoin#31741 and had some discussion there starting in bitcoin/bitcoin#31741 (review)
---
This PR is part of the [process separation project](bitcoin/bitcoin#28722).
ACKs for top commit:
hebasto:
ACK 57d8b1f, tested on Ubuntu 24.04.
Tree-SHA512: 4011adbc0b08742e83cf7c0560d3d5b5694a863358e6ac9a21239626b4a8fedceca66db34b5a46136a7b26849bb1d8710c894689322ae97e1c407687c3f57d502 files changed
+25
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
| 350 | + | |
349 | 351 | | |
350 | 352 | | |
351 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
352 | 367 | | |
353 | 368 | | |
354 | 369 | | |
355 | | - | |
| 370 | + | |
356 | 371 | | |
357 | 372 | | |
358 | 373 | | |
| |||
365 | 380 | | |
366 | 381 | | |
367 | 382 | | |
368 | | - | |
| 383 | + | |
369 | 384 | | |
370 | 385 | | |
371 | 386 | | |
372 | 387 | | |
373 | | - | |
374 | 388 | | |
375 | 389 | | |
376 | 390 | | |
| |||
382 | 396 | | |
383 | 397 | | |
384 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
385 | 402 | | |
386 | | - | |
387 | 403 | | |
388 | 404 | | |
389 | 405 | | |
390 | 406 | | |
391 | 407 | | |
392 | 408 | | |
393 | 409 | | |
394 | | - | |
| 410 | + | |
395 | 411 | | |
396 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
397 | 416 | | |
398 | 417 | | |
399 | 418 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
| |||
0 commit comments