Repository navigation
fix: keep logger output out of GOTCHA-wrapped libc calls - #30
Merged
Merged
Conversation
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
marked this pull request as draft
October 13, 2026 04:21
rayandrew
marked this pull request as ready for review
October 13, 2026 04:33
hariharan-devarajan
approved these changes
Oct 31, 2026
hariharan-devarajan
left a comment
Collaborator
There was a problem hiding this comment.
Looks good.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When DFTracer wraps libc I/O with GOTCHA, cpp-logger's own
fprintfandfflushgo 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
fflushevents.Now the logger calls the real
vsnprintf,fputsandfflush, which it finds in libc when the library loads.I did not copy the plain
dlsymapproach from DFTracer, because GOTCHA wrapsdlsymitself.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
fputsand 20fflushevents.Looking them up at load time works because DFTracer binds after libcpp-logger is initialized.
A copy loaded later with
dlopenis fine too, since its initializers run before GOTCHA patches it.The logger also uses
vsnprintfnow, notvsprintf, which could overflow the 4096 byte buffer and is deprecated on macOS.The code moved out of the header into
logger.cpp, sologger.honly has declarations.-DCPP_LOGGER_LIBC_BYPASS=OFFgoes back to plain libc, with nodlsymand 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_phdrwould 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
developagainst 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
fputsorfflushevent.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
fputsandfflush.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
fflushevents.I have not run the new workflow on GitHub yet, and it takes about 10 minutes.
It also fails if
developin 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.17symbols, so the 2.28 wheels are fine.The branch also has a few small commits.
CMake sets
CMP0177and no longer hides deprecated declarations.There are
clang-format19.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.