-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KNOWN TRAP]: segfault with stl.h wrapper for std::map (and no optimization enabled) #4395
Conversation
requires: - a build with all optimizations disabled - the definition of a function accepting std::map<std::string, double>
... which fails essentially in my use case, but still succeeds here.
The backtrace of the segfault reveals that the In the build with debug output (1f0677a), it is interesting to compare both clang
|
I will work around this issue for now, by always ensuring some optimization options. |
Hi Robert, you seem to have an ODR violation:
|
|
Actually, no, I take that back, after taking a fresh look at stl_bind.h ... and the error message in the #4396 PR description (showing the source locations). |
The CI for #4396 is nearly complete. I'll close the PR soon, but the CI results will expire only later: |
Thanks, Ralf for your extremely quick reply!
Where does that come from? Isn't including
I also checked my original build, which builds on top of old |
It depends on how you compile & link. Generally, there are three lines of defense against ODR violations:
But if you link multiple Translation Units (critical keyword when it comes to ODR) into one extension, all those defenses do not exist, on all platforms. — Note that most pybind11 unit tests are linked together as pybind11_tests.so. (You can see that more clearly here (compared to the cmake files).) Specific to pybind11/include/pybind11/cast.h Lines 39 to 40 in 9727dcd
It needs to resolve to the exact same template instantiations in all TUs linked together. (There is zero wiggle room for this, as we learned the hard way.) With this PR, the ODR arises from
I.e. the I think of that has the "worst kind of trap set by pybind11". It really is not obvious. One way to not have to worry about it so much: Set up your system with "one TU per extension". But that's not always feasible, then you have to think twice, and if things get really big (e.g. Google linking most things statically), test with the |
I'm fine to close this issue report. However, you might want to check the ODR warnings popping up in the current master branch: https://github.com/pybind/pybind11/actions/runs/3659994679/jobs/6186623695 |
Wow, thanks for pointing those out. Amazingly, I never noticed those before, even though I look at CI logs pretty regularly. Continuing under PR #4398. I think it's a very different problem. |
Description
When using both, a
Debug
build and thestl.h
wrapper forstd::map
, I ran into a surprising segfault.I spent a whole day tracking that error down to pybind11 being compiled with no optimization options enabled.
I tried to come up with a minimal example reproducing exactly my issue - but I failed.
However, I was able to reproduce the issue in a different context. For now, this PR provides this minimal example.
What is really weird is that adding a new wrapper in
test_stl.cpp
triggers a bug intest_stl_binders
.Note, that I had to add additional gcc and clang build configs to CI (with optimizations disabled) to trigger the bug in Linux. On Windows, it shows up with the existing jobs already.