Skip to content

luzer: print metrics only once - #93

Open
ligurio wants to merge 4 commits into
masterfrom
ligurio/gh-89-print-metrics-once
Open

luzer: print metrics only once#93
ligurio wants to merge 4 commits into
masterfrom
ligurio/gh-89-print-metrics-once

Conversation

@ligurio

@ligurio ligurio commented Jun 30, 2026

Copy link
Copy Markdown
Owner

The function metrics_print() is called twice when -fork/-jobs are used. The reason is that metrics_print() is called from __attribute__((destructor)), and the destructor is executed in each forked process. When libFuzzer is run with the -fork=N or -jobs=N flags, it forks child processes. Each child process inherits the loaded shared library and its destructors.

The patch fixes that by adding a check to metrics_print() to skip printing if all metrics are zero (so the parent process with zeros won't print, but the child process with data will).

Fixes #89

@ligurio
ligurio force-pushed the ligurio/gh-89-print-metrics-once branch from 1b26476 to 2811473 Compare June 30, 2026 11:02
@ligurio
ligurio requested a review from Buristan June 30, 2026 11:04
@ligurio
ligurio removed the request for review from Buristan June 30, 2026 15:12
@ligurio
ligurio requested a review from Buristan July 3, 2026 10:02
@ligurio ligurio assigned Buristan and unassigned Buristan Jul 3, 2026
@ligurio
ligurio force-pushed the ligurio/gh-89-print-metrics-once branch from 2811473 to d8d77c1 Compare July 3, 2026 12:42
Проблема: На NixOS clang wrapper через hardening flags добавляет -D_FORTIFY_SOURCE=2 после пользовательских флагов, а -O2 — до. Когда CMake переопределяет -O2 на -O0 (для ASan/UBSan тестовых целей), -D_FORTIFY_SOURCE=2 остаётся, и glibc 2.40+ выдаёт ошибку: _FORTIFY_SOURCE requires compiling with optimization (-O).

Исправление (в двух файлах):

1. luzer/CMakeLists.txt:46-52 — Добавлен -U_FORTIFY_SOURCE в общие флаги компиляции (belt-and-suspenders).
2. luzer/tests/CMakeLists.txt:218-219, 350-351 — Заменены -O0 на -O1 для ASan/UBSan тестовых целей (luac_asan, luac_ubsan, testlib_asan, testlib_ubsan). -O1 — минимальный рекомендуемый уровень оптимизации для санитайзеров.

(cherry picked from commit 563e0a64f0e985562d48687652781a275382cba8)
@ligurio
ligurio force-pushed the ligurio/gh-89-print-metrics-once branch from d8d77c1 to 99695e5 Compare July 9, 2026 18:11

@Buristan Buristan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Sergey!
Thanks for the patch set!
Please consider my comments below.

For now tests are failing.


[PATCH 1/2] luzer: print metrics only once

Please consider my comments below.

It would be nice to add the test for fork mode.


[PATCH 2/2] cmake: FORTIFY_SOURCE

This patch looks like it is not ready for review. Commit message is in Russian.
Why -O0 is replaced with -O1?

Comment thread luzer/luzer.c
check_parent_or_child(void)
{
static pid_t saved_pid = -1;
static bool first_call = true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this flag is redundant. Let's just use static saved_pid which is defined on library's initialization. Then we don't need this first_call plie.

@ligurio
ligurio force-pushed the ligurio/gh-89-print-metrics-once branch from 99695e5 to 18f89c5 Compare July 16, 2026 16:40
ligurio and others added 3 commits July 17, 2026 21:31
The function metrics_print() is called twice when `-fork`/`-jobs`
are used. The reason is that `metrics_print()` is called from
`__attribute__((destructor))`, and the destructor is executed in
each forked process. When libFuzzer is run with the `-fork=N` or
`-jobs=N` flags, it forks child processes. Each child process
inherits the loaded shared library and its destructors.

Fixes #89
@ligurio
ligurio force-pushed the ligurio/gh-89-print-metrics-once branch from f5b7f27 to 9b0c252 Compare July 17, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The function metrics_print() is called twice

2 participants