unix: link libpython with -Bsymbolic-functions#1019
Conversation
33424ee to
44f8e67
Compare
|
This change should only affect ELF/Linux. I don't have access to my Linux machine at the moment and can't conduct reliable performance testing. There's a possibility this improves |
44f8e67 to
4d19e45
Compare
This changes the runtime loader lookup semantics for libpython so function references are resolved in the local library first. * May improve startup time by eliding symbol lookups in the executable and other libraries. * Prevents symbols provided by libpython from resolving to other loaded libraries. * Enables additional compiler+linker optimizations by guaranteeing that libpython symbols resolve to the local library. (e.g. more aggressive inlining across translations units.) I believe this change is safe since we're already disabling semantic interposition and PGO+LTO+BOLT result in substantial inlining. However, this change can break `LD_PRELOAD` where a separate DSO providing libpython symbols is injected at the front of the loader search path. In this scenario, the libpython symbol will be used instead of the variant injected via `LD_PRELOAD`. I'm unsure if any popular software (that isn't malware) is relying on intercepting libpython symbols via `LD_PRELOAD`. But because of our aggressive build optimizations, various functions would have been inlined and wouldn't have been `LD_PRELOAD` interceptable anyway since the PLT was already elided. So this change effectively finishes the "migration" of making `LD_PRELOAD` unreliable.
4d19e45 to
868c3fa
Compare
|
Hmmm. I forgot we integrated libpython into |
|
I agree that this will likely have a limited effect given that I ran fastmark with and without this change on Python 3.14 for a quick benchmark, taking the average of three runs:
I can run more in-depth benchmarks if there is interest but that will need to wait until Monday. |
|
I would not list this in quirks at all. We've noticed that people tend to read the quirks page as pre-emptive documentation instead of as debugging steps, and so a heading " I see that the linked maskray blog post (which is excellent and I need to reread it a few times, thank you!) makes the same point:
That said, I am actually worried about a specific type of breakage, given our statically-linked bin/python: one thing we were worried about is programs that incorrectly do a I think one philosophical question here is how much we're interested in improving the performance of shared libpython. In theory, I'd be interested in seeing the benchmark of the following program linked against #include <Python.h>
int main(int argc, char *argv[]) {
return Py_BytesMain(argc, argv);
}(and I kind of want to build and ship that in our distributions in a corner somewhere, it's useful for regression-testing other things like getpath changes), but I think there's a pretty strong argument for not carrying a patch to the build if the only improvement is on shared libpython. |
This changes the runtime loader lookup semantics for libpython so function references are resolved in the local library first.
I believe this change is safe since we're already disabling semantic interposition and PGO+LTO+BOLT result in substantial inlining.
However, this change can break
LD_PRELOADwhere a separate DSO providing libpython symbols is injected at the front of the loader search path. In this scenario, the libpython symbol will be used instead of the variant injected viaLD_PRELOAD. I'm unsure if any popular software (that isn't malware) is relying on intercepting libpython symbols viaLD_PRELOAD. But because of our aggressive build optimizations, various functions would have been inlined and wouldn't have beenLD_PRELOADinterceptable anyway since the PLT was already elided. So this change effectively finishes the "migration" of makingLD_PRELOADunreliable.