Message ID | cover.1641895400.git.fweimer@redhat.com |
---|---|
Headers | show |
Series | Remove some i386 system call optimizations | expand |
On Tue, Jan 11, 2022 at 2:05 AM Florian Weimer <fweimer@redhat.com> wrote: > > The configure check for CAN_USE_REGISTER_ASM_EBP is unreliable. And we > used it to switch away from using %ebx in assembler constraints, but > this appears to be no longer necessary. This GCC bug has been fixed in GCC 5 as seen in commit 021478683cc091de9902d297a7b161f8343ffb6a Author: Uros Bizjak <uros@gcc.gnu.org> Date: Fri Oct 17 08:00:58 2014 +0200 cpuid.h (__cpuid): Remove definitions that handle %ebx register in a special way. * config/i386/cpuid.h (__cpuid): Remove definitions that handle %ebx register in a special way. (__cpuid_count): Ditto. * config/i386/driver-i386.h: Protect with "#if defined(__GNUC__) && (__GNUC__ >= 5 || !defined(__PIC__))". (host_detect_local_cpu): Mention that GCC with non-fixed %ebx is required to compile the function. From-SVN: r216362 Since GCC 6.2 or above is required to build glibc, please remove the !OPTIMIZE_FOR_GCC_5 path and this issue will be resolved automatically. > Tested on i686-linux-gnu. Built with build-many-glibcs.py. > > Thanks, > Florian > > Florian Weimer (2): > i386: Always treat %ebx as an allocatable register > i386: Always use __libc_do_syscall for 6-argument syscalls (bug 27997) > > config.h.in | 4 - > sysdeps/unix/sysv/linux/i386/configure | 39 ---- > sysdeps/unix/sysv/linux/i386/configure.ac | 17 -- > sysdeps/unix/sysv/linux/i386/sysdep.h | 222 +++------------------- > 4 files changed, 27 insertions(+), 255 deletions(-) > > > base-commit: e72ef23ee88187284b4b1ca9b2e314e618429d35 > -- > 2.34.1 > -- H.J.
On Tue, Jan 11, 2022 at 6:00 AM H.J. Lu <hjl.tools@gmail.com> wrote: > > On Tue, Jan 11, 2022 at 2:05 AM Florian Weimer <fweimer@redhat.com> wrote: > > > > The configure check for CAN_USE_REGISTER_ASM_EBP is unreliable. And we > > used it to switch away from using %ebx in assembler constraints, but > > this appears to be no longer necessary. > > This GCC bug has been fixed in GCC 5 as seen in > > commit 021478683cc091de9902d297a7b161f8343ffb6a > Author: Uros Bizjak <uros@gcc.gnu.org> > Date: Fri Oct 17 08:00:58 2014 +0200 > > cpuid.h (__cpuid): Remove definitions that handle %ebx register in > a special way. > > * config/i386/cpuid.h (__cpuid): Remove definitions that handle %ebx > register in a special way. > (__cpuid_count): Ditto. > * config/i386/driver-i386.h: Protect with > "#if defined(__GNUC__) && (__GNUC__ >= 5 || !defined(__PIC__))". > (host_detect_local_cpu): Mention that GCC with non-fixed %ebx > is required to compile the function. > > From-SVN: r216362 > > Since GCC 6.2 or above is required to build glibc, please > remove the !OPTIMIZE_FOR_GCC_5 path and this issue > will be resolved automatically. There are /* Since GCC 5 and above can properly spill %ebx with PIC when needed, we can inline syscalls with 6 arguments if GCC 5 or above is used to compile glibc. Disable GCC 5 optimization when compiling for profiling or when -fno-omit-frame-pointer is used since asm ("ebp") can't be used to put the 6th argument in %ebp for syscall. */ #if !defined PROF && CAN_USE_REGISTER_ASM_EBP # define OPTIMIZE_FOR_GCC_5 #endif If we want to support profiling or -fno-omit-frame-pointer, we need to keep these codes. > > Tested on i686-linux-gnu. Built with build-many-glibcs.py. > > > > Thanks, > > Florian > > > > Florian Weimer (2): > > i386: Always treat %ebx as an allocatable register > > i386: Always use __libc_do_syscall for 6-argument syscalls (bug 27997) > > > > config.h.in | 4 - > > sysdeps/unix/sysv/linux/i386/configure | 39 ---- > > sysdeps/unix/sysv/linux/i386/configure.ac | 17 -- > > sysdeps/unix/sysv/linux/i386/sysdep.h | 222 +++------------------- > > 4 files changed, 27 insertions(+), 255 deletions(-) > > > > > > base-commit: e72ef23ee88187284b4b1ca9b2e314e618429d35 > > -- > > 2.34.1 > > > > > -- > H.J.
* H. J. Lu: > On Tue, Jan 11, 2022 at 6:00 AM H.J. Lu <hjl.tools@gmail.com> wrote: >> >> On Tue, Jan 11, 2022 at 2:05 AM Florian Weimer <fweimer@redhat.com> wrote: >> > >> > The configure check for CAN_USE_REGISTER_ASM_EBP is unreliable. And we >> > used it to switch away from using %ebx in assembler constraints, but >> > this appears to be no longer necessary. >> >> This GCC bug has been fixed in GCC 5 as seen in >> >> commit 021478683cc091de9902d297a7b161f8343ffb6a >> Author: Uros Bizjak <uros@gcc.gnu.org> >> Date: Fri Oct 17 08:00:58 2014 +0200 >> >> cpuid.h (__cpuid): Remove definitions that handle %ebx register in >> a special way. >> >> * config/i386/cpuid.h (__cpuid): Remove definitions that handle %ebx >> register in a special way. >> (__cpuid_count): Ditto. >> * config/i386/driver-i386.h: Protect with >> "#if defined(__GNUC__) && (__GNUC__ >= 5 || !defined(__PIC__))". >> (host_detect_local_cpu): Mention that GCC with non-fixed %ebx >> is required to compile the function. >> >> From-SVN: r216362 >> >> Since GCC 6.2 or above is required to build glibc, please >> remove the !OPTIMIZE_FOR_GCC_5 path and this issue >> will be resolved automatically. > > There are > > /* Since GCC 5 and above can properly spill %ebx with PIC when needed, > we can inline syscalls with 6 arguments if GCC 5 or above is used > to compile glibc. Disable GCC 5 optimization when compiling for > profiling or when -fno-omit-frame-pointer is used since asm ("ebp") > can't be used to put the 6th argument in %ebp for syscall. */ > #if !defined PROF && CAN_USE_REGISTER_ASM_EBP > # define OPTIMIZE_FOR_GCC_5 > #endif > > If we want to support profiling or -fno-omit-frame-pointer, > we need to keep these codes. This is strictly for %ebp, I think, as indicated by the comment. %ebx does not need to be special-cased for profiling. I assume that building glibc (with profiling) is proof enough that this works? Thanks, Florian
On Tue, Jan 11, 2022 at 12:37 PM Florian Weimer <fweimer@redhat.com> wrote: > > * H. J. Lu: > > > On Tue, Jan 11, 2022 at 6:00 AM H.J. Lu <hjl.tools@gmail.com> wrote: > >> > >> On Tue, Jan 11, 2022 at 2:05 AM Florian Weimer <fweimer@redhat.com> wrote: > >> > > >> > The configure check for CAN_USE_REGISTER_ASM_EBP is unreliable. And we > >> > used it to switch away from using %ebx in assembler constraints, but > >> > this appears to be no longer necessary. > >> > >> This GCC bug has been fixed in GCC 5 as seen in > >> > >> commit 021478683cc091de9902d297a7b161f8343ffb6a > >> Author: Uros Bizjak <uros@gcc.gnu.org> > >> Date: Fri Oct 17 08:00:58 2014 +0200 > >> > >> cpuid.h (__cpuid): Remove definitions that handle %ebx register in > >> a special way. > >> > >> * config/i386/cpuid.h (__cpuid): Remove definitions that handle %ebx > >> register in a special way. > >> (__cpuid_count): Ditto. > >> * config/i386/driver-i386.h: Protect with > >> "#if defined(__GNUC__) && (__GNUC__ >= 5 || !defined(__PIC__))". > >> (host_detect_local_cpu): Mention that GCC with non-fixed %ebx > >> is required to compile the function. > >> > >> From-SVN: r216362 > >> > >> Since GCC 6.2 or above is required to build glibc, please > >> remove the !OPTIMIZE_FOR_GCC_5 path and this issue > >> will be resolved automatically. > > > > There are > > > > /* Since GCC 5 and above can properly spill %ebx with PIC when needed, > > we can inline syscalls with 6 arguments if GCC 5 or above is used > > to compile glibc. Disable GCC 5 optimization when compiling for > > profiling or when -fno-omit-frame-pointer is used since asm ("ebp") > > can't be used to put the 6th argument in %ebp for syscall. */ > > #if !defined PROF && CAN_USE_REGISTER_ASM_EBP > > # define OPTIMIZE_FOR_GCC_5 > > #endif > > > > If we want to support profiling or -fno-omit-frame-pointer, > > we need to keep these codes. > > This is strictly for %ebp, I think, as indicated by the comment. %ebx > does not need to be special-cased for profiling. > > I assume that building glibc (with profiling) is proof enough that this > works? You need to test glibc build with -fno-omit-frame-pointer.
* H. J. Lu: >> > There are >> > >> > /* Since GCC 5 and above can properly spill %ebx with PIC when needed, >> > we can inline syscalls with 6 arguments if GCC 5 or above is used >> > to compile glibc. Disable GCC 5 optimization when compiling for >> > profiling or when -fno-omit-frame-pointer is used since asm ("ebp") >> > can't be used to put the 6th argument in %ebp for syscall. */ >> > #if !defined PROF && CAN_USE_REGISTER_ASM_EBP >> > # define OPTIMIZE_FOR_GCC_5 >> > #endif >> > >> > If we want to support profiling or -fno-omit-frame-pointer, >> > we need to keep these codes. >> >> This is strictly for %ebp, I think, as indicated by the comment. %ebx >> does not need to be special-cased for profiling. >> >> I assume that building glibc (with profiling) is proof enough that this >> works? > > You need to test glibc build with -fno-omit-frame-pointer. I tried it, it works (with both patches applied). -fno-omit-frame-pointer is about %ebp, not %ebx. Thanks, Florian
On Tue, Jan 11, 2022 at 2:52 PM Florian Weimer <fweimer@redhat.com> wrote: > > * H. J. Lu: > > >> > There are > >> > > >> > /* Since GCC 5 and above can properly spill %ebx with PIC when needed, > >> > we can inline syscalls with 6 arguments if GCC 5 or above is used > >> > to compile glibc. Disable GCC 5 optimization when compiling for > >> > profiling or when -fno-omit-frame-pointer is used since asm ("ebp") > >> > can't be used to put the 6th argument in %ebp for syscall. */ > >> > #if !defined PROF && CAN_USE_REGISTER_ASM_EBP > >> > # define OPTIMIZE_FOR_GCC_5 > >> > #endif > >> > > >> > If we want to support profiling or -fno-omit-frame-pointer, > >> > we need to keep these codes. > >> > >> This is strictly for %ebp, I think, as indicated by the comment. %ebx > >> does not need to be special-cased for profiling. > >> > >> I assume that building glibc (with profiling) is proof enough that this > >> works? > > > > You need to test glibc build with -fno-omit-frame-pointer. > > I tried it, it works (with both patches applied). > -fno-omit-frame-pointer is about %ebp, not %ebx. > > Thanks, > Florian > Do they have to be in glibc 2.35? If not, I prefer to do it after 2.35 is branched. Thanks.
* H. J. Lu: > On Tue, Jan 11, 2022 at 2:52 PM Florian Weimer <fweimer@redhat.com> wrote: >> >> * H. J. Lu: >> >> >> > There are >> >> > >> >> > /* Since GCC 5 and above can properly spill %ebx with PIC when needed, >> >> > we can inline syscalls with 6 arguments if GCC 5 or above is used >> >> > to compile glibc. Disable GCC 5 optimization when compiling for >> >> > profiling or when -fno-omit-frame-pointer is used since asm ("ebp") >> >> > can't be used to put the 6th argument in %ebp for syscall. */ >> >> > #if !defined PROF && CAN_USE_REGISTER_ASM_EBP >> >> > # define OPTIMIZE_FOR_GCC_5 >> >> > #endif >> >> > >> >> > If we want to support profiling or -fno-omit-frame-pointer, >> >> > we need to keep these codes. >> >> >> >> This is strictly for %ebp, I think, as indicated by the comment. %ebx >> >> does not need to be special-cased for profiling. >> >> >> >> I assume that building glibc (with profiling) is proof enough that this >> >> works? >> > >> > You need to test glibc build with -fno-omit-frame-pointer. >> >> I tried it, it works (with both patches applied). >> -fno-omit-frame-pointer is about %ebp, not %ebx. >> >> Thanks, >> Florian >> > > Do they have to be in glibc 2.35? If not, I prefer to do it after > 2.35 is branched. We can't build glibc 2.35 with GCC 12 in Fedora without these changes. The %ebp avoidance I can activate with a configure argument, but the macros for optimized %ebx usage are incompatible with .altmacro, as used by the current Systemtap probes. Thanks, Florian
On Wed, Jan 12, 2022 at 11:37 AM Florian Weimer <fweimer@redhat.com> wrote: > > * H. J. Lu: > > > On Tue, Jan 11, 2022 at 2:52 PM Florian Weimer <fweimer@redhat.com> wrote: > >> > >> * H. J. Lu: > >> > >> >> > There are > >> >> > > >> >> > /* Since GCC 5 and above can properly spill %ebx with PIC when needed, > >> >> > we can inline syscalls with 6 arguments if GCC 5 or above is used > >> >> > to compile glibc. Disable GCC 5 optimization when compiling for > >> >> > profiling or when -fno-omit-frame-pointer is used since asm ("ebp") > >> >> > can't be used to put the 6th argument in %ebp for syscall. */ > >> >> > #if !defined PROF && CAN_USE_REGISTER_ASM_EBP > >> >> > # define OPTIMIZE_FOR_GCC_5 > >> >> > #endif > >> >> > > >> >> > If we want to support profiling or -fno-omit-frame-pointer, > >> >> > we need to keep these codes. > >> >> > >> >> This is strictly for %ebp, I think, as indicated by the comment. %ebx > >> >> does not need to be special-cased for profiling. > >> >> > >> >> I assume that building glibc (with profiling) is proof enough that this > >> >> works? > >> > > >> > You need to test glibc build with -fno-omit-frame-pointer. > >> > >> I tried it, it works (with both patches applied). > >> -fno-omit-frame-pointer is about %ebp, not %ebx. > >> > >> Thanks, > >> Florian > >> > > > > Do they have to be in glibc 2.35? If not, I prefer to do it after > > 2.35 is branched. > > We can't build glibc 2.35 with GCC 12 in Fedora without these changes. > > The %ebp avoidance I can activate with a configure argument, but the > macros for optimized %ebx usage are incompatible with .altmacro, as used > by the current Systemtap probes. Please open a glibc bug with a reproducer and CC me. Thanks.
* H. J. Lu: > On Wed, Jan 12, 2022 at 11:37 AM Florian Weimer <fweimer@redhat.com> wrote: >> >> * H. J. Lu: >> >> > On Tue, Jan 11, 2022 at 2:52 PM Florian Weimer <fweimer@redhat.com> wrote: >> >> >> >> * H. J. Lu: >> >> >> >> >> > There are >> >> >> > >> >> >> > /* Since GCC 5 and above can properly spill %ebx with PIC when needed, >> >> >> > we can inline syscalls with 6 arguments if GCC 5 or above is used >> >> >> > to compile glibc. Disable GCC 5 optimization when compiling for >> >> >> > profiling or when -fno-omit-frame-pointer is used since asm ("ebp") >> >> >> > can't be used to put the 6th argument in %ebp for syscall. */ >> >> >> > #if !defined PROF && CAN_USE_REGISTER_ASM_EBP >> >> >> > # define OPTIMIZE_FOR_GCC_5 >> >> >> > #endif >> >> >> > >> >> >> > If we want to support profiling or -fno-omit-frame-pointer, >> >> >> > we need to keep these codes. >> >> >> >> >> >> This is strictly for %ebp, I think, as indicated by the comment. %ebx >> >> >> does not need to be special-cased for profiling. >> >> >> >> >> >> I assume that building glibc (with profiling) is proof enough that this >> >> >> works? >> >> > >> >> > You need to test glibc build with -fno-omit-frame-pointer. >> >> >> >> I tried it, it works (with both patches applied). >> >> -fno-omit-frame-pointer is about %ebp, not %ebx. >> >> >> >> Thanks, >> >> Florian >> >> >> > >> > Do they have to be in glibc 2.35? If not, I prefer to do it after >> > 2.35 is branched. >> >> We can't build glibc 2.35 with GCC 12 in Fedora without these changes. >> >> The %ebp avoidance I can activate with a configure argument, but the >> macros for optimized %ebx usage are incompatible with .altmacro, as used >> by the current Systemtap probes. > > Please open a glibc bug with a reproducer and CC me. Done: <https://sourceware.org/bugzilla/show_bug.cgi?id=28771> Thanks, Florian
On Wed, Jan 12, 2022 at 12:12 PM Florian Weimer <fweimer@redhat.com> wrote: > > * H. J. Lu: > > > On Wed, Jan 12, 2022 at 11:37 AM Florian Weimer <fweimer@redhat.com> wrote: > >> > >> * H. J. Lu: > >> > >> > On Tue, Jan 11, 2022 at 2:52 PM Florian Weimer <fweimer@redhat.com> wrote: > >> >> > >> >> * H. J. Lu: > >> >> > >> >> >> > There are > >> >> >> > > >> >> >> > /* Since GCC 5 and above can properly spill %ebx with PIC when needed, > >> >> >> > we can inline syscalls with 6 arguments if GCC 5 or above is used > >> >> >> > to compile glibc. Disable GCC 5 optimization when compiling for > >> >> >> > profiling or when -fno-omit-frame-pointer is used since asm ("ebp") > >> >> >> > can't be used to put the 6th argument in %ebp for syscall. */ > >> >> >> > #if !defined PROF && CAN_USE_REGISTER_ASM_EBP > >> >> >> > # define OPTIMIZE_FOR_GCC_5 > >> >> >> > #endif > >> >> >> > > >> >> >> > If we want to support profiling or -fno-omit-frame-pointer, > >> >> >> > we need to keep these codes. > >> >> >> > >> >> >> This is strictly for %ebp, I think, as indicated by the comment. %ebx > >> >> >> does not need to be special-cased for profiling. > >> >> >> > >> >> >> I assume that building glibc (with profiling) is proof enough that this > >> >> >> works? > >> >> > > >> >> > You need to test glibc build with -fno-omit-frame-pointer. > >> >> > >> >> I tried it, it works (with both patches applied). > >> >> -fno-omit-frame-pointer is about %ebp, not %ebx. > >> >> > >> >> Thanks, > >> >> Florian > >> >> > >> > > >> > Do they have to be in glibc 2.35? If not, I prefer to do it after > >> > 2.35 is branched. > >> > >> We can't build glibc 2.35 with GCC 12 in Fedora without these changes. > >> > >> The %ebp avoidance I can activate with a configure argument, but the > >> macros for optimized %ebx usage are incompatible with .altmacro, as used > >> by the current Systemtap probes. > > > > Please open a glibc bug with a reproducer and CC me. > > Done: <https://sourceware.org/bugzilla/show_bug.cgi?id=28771> > OPTIMIZE_FOR_GCC_5 enables 2 things: one is let GCC handle -fPIC and the other is use register int reg asm ("ebp") which is unreliable. You want to let GCC handle -fPIC and remove CAN_USE_REGISTER_ASM_EBP. If this is correct, please combine 2 patches into one and reference BZ #28771 in the commit log. Thanks.
* H. J. Lu: > OPTIMIZE_FOR_GCC_5 enables 2 things: one is let GCC handle > -fPIC and the other is use > > register int reg asm ("ebp") > > which is unreliable. You want to let GCC handle -fPIC and > remove CAN_USE_REGISTER_ASM_EBP. If this is correct, > please combine 2 patches into one and reference BZ #28771 > in the commit log. Yes, that is an accurate summary. I will send a patch according to your suggestions tomorrow. Thanks, Florian