-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
build: use PIE objects for non-PIC static libraries if b_pie=true #7760
Conversation
f35f5d2
to
6bdec78
Compare
Just a note that traditionally these sort of behaviour changes have been a bit dangerous. Usually someone's project breaks. Are there any known cases where this might happen? |
I don't know any, in fact I'm trying to make Meson more conservative: currently it's assuming that |
Because most files in QEMU are grouped into static libraries, Meson conservatively compiles them with -fPIC. This is overkill and produces slowdowns up to 20% on some TCG tests. As a stopgap measure, use the b_staticpic option to limit the slowdown to --enable-pie. mesonbuild/meson#7760 will allow us to use b_staticpic=false and let Meson do the right thing. Reported-by: Ahmed Karaman <ahmedkrmn@outlook.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200919155639.1045857-1-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Ping? |
This requires thinking about the implications fairly thoroughly. I'll try to get that done this weekend. |
One thought that came up was that maybe |
It would not help because there is no way to express that you want I think you are seeing this as an optimization that allows one to use (Related to this would it make sense to deprecate installing static_libraries if |
I guess the problem here is that the original design for |
Yeah that would be more precise, but then you'd also want a In my opinion even the This is also why I am okay with a boolean |
Because most files in QEMU are grouped into static libraries, Meson conservatively compiles them with -fPIC. This is overkill and produces slowdowns up to 20% on some TCG tests. As a stopgap measure, use the b_staticpic option to limit the slowdown to --enable-pie. mesonbuild/meson#7760 will allow us to use b_staticpic=false and let Meson do the right thing. Reported-by: Ahmed Karaman <ahmedkrmn@outlook.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200919155639.1045857-1-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Because most files in QEMU are grouped into static libraries, Meson conservatively compiles them with -fPIC. This is overkill and produces slowdowns up to 20% on some TCG tests. As a stopgap measure, use the b_staticpic option to limit the slowdown to --enable-pie. mesonbuild/meson#7760 will allow us to use b_staticpic=false and let Meson do the right thing. Reported-by: Ahmed Karaman <ahmedkrmn@outlook.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200919155639.1045857-1-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Because most files in QEMU are grouped into static libraries, Meson conservatively compiles them with -fPIC. This is overkill and produces slowdowns up to 20% on some TCG tests. As a stopgap measure, use the b_staticpic option to limit the slowdown to --enable-pie. mesonbuild/meson#7760 will allow us to use b_staticpic=false and let Meson do the right thing. Reported-by: Ahmed Karaman <ahmedkrmn@outlook.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200919155639.1045857-1-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200924092314.1722645-57-pbonzini@redhat.com>
…b_pie=true If static_library is used as a convenience library (e.g. for link_whole) it should in principle not need position independent code. However, if the executables that the libraries is linked to are PIE, the non-PIC objects in the static library will cause linker errors. To avoid this, obey b_pie for static libraries if either b_staticpic=false or they use "pic: false". Without this patch, QEMU cannot use b_staticpic, which causes a slowdown on some QEMU benchmarks up to 20%.
6bdec78
to
8d2bd5f
Compare
Because most files in QEMU are grouped into static libraries, Meson conservatively compiles them with -fPIC. This is overkill and produces slowdowns up to 20% on some TCG tests. As a stopgap measure, use the b_staticpic option to limit the slowdown to --enable-pie. mesonbuild/meson#7760 will allow us to use b_staticpic=false and let Meson do the right thing. Reported-by: Ahmed Karaman <ahmedkrmn@outlook.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200924092314.1722645-57-pbonzini@redhat.com> Message-Id: <20201007160038.26953-2-alex.bennee@linaro.org>
Because most files in QEMU are grouped into static libraries, Meson conservatively compiles them with -fPIC. This is overkill and produces slowdowns up to 20% on some TCG tests. As a stopgap measure, use the b_staticpic option to limit the slowdown to --enable-pie. mesonbuild/meson#7760 will allow us to use b_staticpic=false and let Meson do the right thing. Reported-by: Ahmed Karaman <ahmedkrmn@outlook.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200919155639.1045857-1-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Thinking about this more, There are really three cases that I can see.
On some platforms (mac?) the last two are the same, all code is at least PIE. You can't know where a library will be used when it is declared so barring advances in clairvoyance we can't autodetect that. So let's speculate some instead. If we had
The downside is that to match the current behaviour, the default value should be |
Right, this is why I would like to warn on installing (More precisely therefore this PR should be "use PIE objects for non-PIC static libraries if b_pie=true"). If we want to have PIE libraries in non-PIE projects or vice versa, adding
Yeah, the problem with
I have no problem with the default for |
Just in case: this MR gets an exception to get merged in after RC1 (if necessary). |
I went through this again and it clearly improves the situation for an important use case. I could not come up with a case where it would break things. If they exist, hopefully they crop up during the RC (though the pessimist in me expects that to only happen after the actual release :( ). f that happens we may need to revert this, but that's a different problem then. In case problems occur, we should consider overhauling the pic/pie options under a single toggle. The current split is confusing. |
The update to 0.57 has been delayed due to it causing warnings for some actual issues, but it brings in important bugfixes and new features. 0.58 also brings in a bugfix that is useful for modinfo. Important bugfixes: - 0.57: mesonbuild/meson#7760, build: use PIE objects for non-PIC static libraries if b_pie=true - 0.57: mesonbuild/meson#7900, thus avoiding unnecessary rebuilds after running meson. - 0.58.2: mesonbuild/meson#8900, fixes for passing extract_objects() to custom_target (useful for modinfo) Features: - 0.57: the keyval module has now been stabilized - 0.57: env argument to custom_target (useful for hexagon) - 0.57: Feature parity between "meson test" and QEMU's TAP driver - 0.57: mesonbuild/meson#8231, allows bringing back version numbers in the configuration summary Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The update to 0.57 has been delayed due to it causing warnings for some actual issues, but it brings in important bugfixes and new features. 0.58 also brings in a bugfix that is useful for modinfo. Important bugfixes: - 0.57: mesonbuild/meson#7760, build: use PIE objects for non-PIC static libraries if b_pie=true - 0.57: mesonbuild/meson#7900, thus avoiding unnecessary rebuilds after running meson. - 0.58.2: mesonbuild/meson#8900, fixes for passing extract_objects() to custom_target (useful for modinfo) Features: - 0.57: the keyval module has now been stabilized - 0.57: env argument to custom_target (useful for hexagon) - 0.57: Feature parity between "meson test" and QEMU's TAP driver - 0.57: mesonbuild/meson#8231, allows bringing back version numbers in the configuration summary Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The update to 0.57 has been delayed due to it causing warnings for some actual issues, but it brings in important bugfixes and new features. 0.58 also brings in a bugfix that is useful for modinfo. Important bugfixes: - 0.57: mesonbuild/meson#7760, build: use PIE objects for non-PIC static libraries if b_pie=true - 0.57: mesonbuild/meson#7900, thus avoiding unnecessary rebuilds after running meson. - 0.58.2: mesonbuild/meson#8900, fixes for passing extract_objects() to custom_target (useful for modinfo) Features: - 0.57: the keyval module has now been stabilized - 0.57: env argument to custom_target (useful for hexagon) - 0.57: Feature parity between "meson test" and QEMU's TAP driver - 0.57: mesonbuild/meson#8231, allows bringing back version numbers in the configuration summary - 0.59: Utility methods for feature objects Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
If
static_library
is used for a convenience library (e.g. for link_whole), the library should in principle not need position independent code. However, if the executables that the libraries is linked to are PIE, the non-PIC objects in the static library will cause linker errors. To avoid this, obeyb_pie
for static libraries if eitherb_staticpic=false
or they usepic: false
.Without this patch, a project that only uses static libraries as convenience libraries cannot use
b_staticpic=false
, because the correct setting would be, so to speak,b_staticpic=$b_pie
. This causes a massive slowdown on some QEMU benchmarks (up to 20%). We can work it around for now while we still have wrappers upon wrappers around Meson, but in the long run this should be fixed.But actually, this patch also provides a performance improvement if
b_pie=true
, becauseb_staticpic=true b_pie=true
is also slower than theb_staticpic=false b_pie=true
combo that is now fixed. This is because-fPIC
produces worse code than-fPIE
. On the aforementioned benchmark: