Skip to content

fix: keep logger output out of GOTCHA-wrapped libc calls - #30

Merged
hariharan-devarajan merged 6 commits into
developfrom
feat/bypass-posix-stdio
Oct 31, 2026
Merged

hariharan-devarajan merged 6 commits into
developfrom
feat/bypass-posix-stdio

Conversation

@rayandrew

@rayandrew rayandrew commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

When DFTracer wraps libc I/O with GOTCHA, cpp-logger's own fprintf and fflush go through the wrappers too.
So the logger's output lands in the trace, and DFTracer's debug logging inside a wrapper can call the logger again.
With v0.0.8 and the DFTracer preload, 20 log lines give 20 traced fflush events.

Now the logger calls the real vsnprintf, fputs and fflush, which it finds in libc when the library loads.
I did not copy the plain dlsym approach from DFTracer, because GOTCHA wraps dlsym itself.
Once a symbol is bound, dlsym(libc, "fputs") returns the GOTCHA wrapper.
My first version looked the functions up on the first log call and still traced 20 fputs and 20 fflush events.
Looking them up at load time works because DFTracer binds after libcpp-logger is initialized.
A copy loaded later with dlopen is fine too, since its initializers run before GOTCHA patches it.

The logger also uses vsnprintf now, not vsprintf, which could overflow the 4096 byte buffer and is deprecated on macOS.
The code moved out of the header into logger.cpp, so logger.h only has declarations.
-DCPP_LOGGER_LIBC_BYPASS=OFF goes back to plain libc, with no dlsym and no -ldl.
It is ON by default on Linux.

It does not work when cpp-logger is compiled into the executable and DFTracer is preloaded.
The executable's initializers run after the bind, so the lookup gets the wrappers and the output is traced again.
Reading libc's symbol table with dl_iterate_phdr would fix it.
I left that out to keep this simple, and the README says to use cpp-logger as a shared library with DFTracer.
Tell me if you want it anyway.

The repo has no unit tests, so I added a CI job that builds DFTracer develop against the commit under test and runs DFTracer's own tests.
It then runs a small program that logs 20 lines through cpp-logger under the DFTracer preload, and fails if the trace has any logger fputs or fflush event.
I ran the same script on x86_64 and glibc 2.28.
DFTracer's 63 tests passed and the trace was clean, so the probe reports 0 traced fputs and fflush.
That run used DFTracer's pinned GOTCHA v1.0.10.
Earlier by-hand runs with the GOTCHA branch from llnl/GOTCHA#178 gave the same result, and with v0.0.8 a similar program showed 20 traced fflush events.
I have not run the new workflow on GitHub yet, and it takes about 10 minutes.
It also fails if develop in DFTracer breaks for a reason that has nothing to do with us.
The library builds on glibc 2.28 and needs at most GLIBC_2.17 symbols, so the 2.28 wheels are fine.

The branch also has a few small commits.
CMake sets CMP0177 and no longer hides deprecated declarations.
There are clang-format 19.1.7 scripts, and the sources are reformatted with them.
There is a GitHub Actions workflow with build, docs and format jobs, and it cancels the older run when a pull request gets a new commit.
The repo only had the GitLab pipeline before, and I did not touch it.

Resolve the real vsnprintf, fputs and fflush when the library loads. GOTCHA wraps dlsym, so a lookup after it binds returns its wrapper and the logger recurses. Replace vsprintf with vsnprintf. CPP_LOGGER_LIBC_BYPASS turns this off.
@rayandrew
rayandrew marked this pull request as draft October 13, 2026 04:21
@rayandrew
rayandrew marked this pull request as ready for review October 13, 2026 04:33

@hariharan-devarajan hariharan-devarajan 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.

Looks good.

@hariharan-devarajan
hariharan-devarajan merged commit e2f126e into develop Oct 31, 2026
6 checks passed
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.

2 participants