Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-libs/glibc/
Date: Sat, 25 Jun 2022 21:40:08
Message-Id: 1656193168.02aa6328a720c86d0157c4582f7e5bac72ae9296.sam@gentoo
1 commit: 02aa6328a720c86d0157c4582f7e5bac72ae9296
2 Author: James Le Cuirot <chewi <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jun 11 21:11:12 2022 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Sat Jun 25 21:39:28 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=02aa6328
7
8 sys-libs/glibc: Add stack-realign flag for compat with old 32-bit x86 binaries
9
10 Older 32-bit x86 binaries aligned the stack to 4 bytes, whereas modern
11 binaries align to 16 bytes. These older binaries sometimes segfault when
12 newer libraries use SSE instructions. This is becoming increasingly
13 common. Applying the -mstackrealign flag to the 32-bit build works
14 around the issue but at a performance cost. Other popular
15 distributions always apply this.
16
17 [sam: There's no good choices here. As Ionen pointed out (I'd missed
18 any reports of this), this ends up getting worse with GCC 12's
19 default-on vectorisation at -O2. Let's make it optional for now for
20 32-bit/x86 (irrelevant for other arches, it's specific to x86 ABI).
21
22 ncurses is going to need similar treatment. If we end up having
23 to do this for far more packages, we may revisit and e.g.
24 just append-flags in ebuilds for right ABI and tell users
25 to set -mno-stackrealign, or similar.
26
27 Another option would be to set this globally by default (again,
28 this is only ever for x86), but it'd possibly be a big performance
29 hit (and bad enough doing it in glibc, but it's unavoidable).
30
31 The only saving grace here is that there aren't _that_ many
32 libraries with such longevity & ABI stability from back then
33 that older applications are using.]
34
35 Bug: https://bugs.gentoo.org/616402
36 Bug: https://github.com/taviso/123elf/issues/12
37 Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>
38 Closes: https://github.com/gentoo/gentoo/pull/25858
39 Signed-off-by: Sam James <sam <AT> gentoo.org>
40
41 sys-libs/glibc/glibc-2.35-r7.ebuild | 31 ++++++++++++++++++-------------
42 sys-libs/glibc/glibc-9999.ebuild | 31 ++++++++++++++++++-------------
43 sys-libs/glibc/metadata.xml | 1 +
44 3 files changed, 37 insertions(+), 26 deletions(-)
45
46 diff --git a/sys-libs/glibc/glibc-2.35-r7.ebuild b/sys-libs/glibc/glibc-2.35-r7.ebuild
47 index a9b4a0d16717..3e8358532526 100644
48 --- a/sys-libs/glibc/glibc-2.35-r7.ebuild
49 +++ b/sys-libs/glibc/glibc-2.35-r7.ebuild
50 @@ -44,7 +44,7 @@ SRC_URI+=" https://gitweb.gentoo.org/proj/locale-gen.git/snapshot/locale-gen-${L
51 SRC_URI+=" multilib-bootstrap? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz )"
52 SRC_URI+=" systemd? ( https://gitweb.gentoo.org/proj/toolchain/glibc-systemd.git/snapshot/glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz )"
53
54 -IUSE="audit caps cet +clone3 compile-locales +crypt custom-cflags doc experimental-loong gd headers-only +multiarch multilib multilib-bootstrap nscd profile selinux +ssp +static-libs suid systemd systemtap test vanilla"
55 +IUSE="audit caps cet +clone3 compile-locales +crypt custom-cflags doc experimental-loong gd headers-only +multiarch multilib multilib-bootstrap nscd profile selinux +ssp stack-realign +static-libs suid systemd systemtap test vanilla"
56
57 # Minimum kernel version that glibc requires
58 MIN_KERN_VER="3.2.0"
59 @@ -305,22 +305,27 @@ setup_target_flags() {
60 export CFLAGS="-march=${t} ${CFLAGS}"
61 einfo "Auto adding -march=${t} to CFLAGS #185404"
62 fi
63 + # For compatibility with older binaries at slight performance cost.
64 + use stack-realign && export CFLAGS+=" -mstackrealign"
65 ;;
66 amd64)
67 # -march needed for #185404 #199334
68 # TODO: See cross-compile issues listed above for x86.
69 - [[ ${ABI} == x86 ]] &&
70 - if ! do_compile_test "${CFLAGS_x86}" 'void f(int i, void *p) {if (__sync_fetch_and_add(&i, 1)) f(i, p);}\nint main(){return 0;}\n'; then
71 - local t=${CTARGET_OPT:-${CTARGET}}
72 - t=${t%%-*}
73 - # Normally the target is x86_64-xxx, so turn that into the -march that
74 - # gcc actually accepts. #528708
75 - [[ ${t} == "x86_64" ]] && t="x86-64"
76 - filter-flags '-march=*'
77 - # ugly, ugly, ugly. ugly.
78 - CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
79 - export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
80 - einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
81 + if [[ ${ABI} == x86 ]]; then
82 + if ! do_compile_test "${CFLAGS_x86}" 'void f(int i, void *p) {if (__sync_fetch_and_add(&i, 1)) f(i, p);}\nint main(){return 0;}\n'; then
83 + local t=${CTARGET_OPT:-${CTARGET}}
84 + t=${t%%-*}
85 + # Normally the target is x86_64-xxx, so turn that into the -march that
86 + # gcc actually accepts. #528708
87 + [[ ${t} == "x86_64" ]] && t="x86-64"
88 + filter-flags '-march=*'
89 + # ugly, ugly, ugly. ugly.
90 + CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
91 + export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
92 + einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
93 + fi
94 + # For compatibility with older binaries at slight performance cost.
95 + use stack-realign && export CFLAGS_x86+=" -mstackrealign"
96 fi
97 ;;
98 mips)
99
100 diff --git a/sys-libs/glibc/glibc-9999.ebuild b/sys-libs/glibc/glibc-9999.ebuild
101 index 2a030e2f9928..b35b2febd192 100644
102 --- a/sys-libs/glibc/glibc-9999.ebuild
103 +++ b/sys-libs/glibc/glibc-9999.ebuild
104 @@ -44,7 +44,7 @@ SRC_URI+=" https://gitweb.gentoo.org/proj/locale-gen.git/snapshot/locale-gen-${L
105 SRC_URI+=" multilib-bootstrap? ( https://dev.gentoo.org/~dilfridge/distfiles/gcc-multilib-bootstrap-${GCC_BOOTSTRAP_VER}.tar.xz )"
106 SRC_URI+=" systemd? ( https://gitweb.gentoo.org/proj/toolchain/glibc-systemd.git/snapshot/glibc-systemd-${GLIBC_SYSTEMD_VER}.tar.gz )"
107
108 -IUSE="audit caps cet compile-locales +crypt custom-cflags doc gd headers-only +multiarch multilib multilib-bootstrap nscd profile selinux +ssp +static-libs suid systemd systemtap test vanilla"
109 +IUSE="audit caps cet compile-locales +crypt custom-cflags doc gd headers-only +multiarch multilib multilib-bootstrap nscd profile selinux +ssp stack-realign +static-libs suid systemd systemtap test vanilla"
110
111 # Minimum kernel version that glibc requires
112 MIN_KERN_VER="3.2.0"
113 @@ -305,22 +305,27 @@ setup_target_flags() {
114 export CFLAGS="-march=${t} ${CFLAGS}"
115 einfo "Auto adding -march=${t} to CFLAGS #185404"
116 fi
117 + # For compatibility with older binaries at slight performance cost.
118 + use stack-realign && export CFLAGS+=" -mstackrealign"
119 ;;
120 amd64)
121 # -march needed for #185404 #199334
122 # TODO: See cross-compile issues listed above for x86.
123 - [[ ${ABI} == x86 ]] &&
124 - if ! do_compile_test "${CFLAGS_x86}" 'void f(int i, void *p) {if (__sync_fetch_and_add(&i, 1)) f(i, p);}\nint main(){return 0;}\n'; then
125 - local t=${CTARGET_OPT:-${CTARGET}}
126 - t=${t%%-*}
127 - # Normally the target is x86_64-xxx, so turn that into the -march that
128 - # gcc actually accepts. #528708
129 - [[ ${t} == "x86_64" ]] && t="x86-64"
130 - filter-flags '-march=*'
131 - # ugly, ugly, ugly. ugly.
132 - CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
133 - export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
134 - einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
135 + if [[ ${ABI} == x86 ]]; then
136 + if ! do_compile_test "${CFLAGS_x86}" 'void f(int i, void *p) {if (__sync_fetch_and_add(&i, 1)) f(i, p);}\nint main(){return 0;}\n'; then
137 + local t=${CTARGET_OPT:-${CTARGET}}
138 + t=${t%%-*}
139 + # Normally the target is x86_64-xxx, so turn that into the -march that
140 + # gcc actually accepts. #528708
141 + [[ ${t} == "x86_64" ]] && t="x86-64"
142 + filter-flags '-march=*'
143 + # ugly, ugly, ugly. ugly.
144 + CFLAGS_x86=$(CFLAGS=${CFLAGS_x86} filter-flags '-march=*'; echo "${CFLAGS}")
145 + export CFLAGS_x86="${CFLAGS_x86} -march=${t}"
146 + einfo "Auto adding -march=${t} to CFLAGS_x86 #185404 (ABI=${ABI})"
147 + fi
148 + # For compatibility with older binaries at slight performance cost.
149 + use stack-realign && export CFLAGS_x86+=" -mstackrealign"
150 fi
151 ;;
152 mips)
153
154 diff --git a/sys-libs/glibc/metadata.xml b/sys-libs/glibc/metadata.xml
155 index e00a008ac5c3..bcaf604fa542 100644
156 --- a/sys-libs/glibc/metadata.xml
157 +++ b/sys-libs/glibc/metadata.xml
158 @@ -17,6 +17,7 @@
159 <flag name="multilib-bootstrap">Provide prebuilt libgcc.a and crt files if missing. Only needed for ABI switch.</flag>
160 <flag name="nscd">Build, and enable support for, the Name Service Cache Daemon</flag>
161 <flag name="ssp">protect stack of glibc internals</flag>
162 + <flag name="stack-realign">Realign the stack in the 32-bit build for compatibility with older binaries at slight performance cost</flag>
163 <flag name="static-pie">Enable static PIE support (runtime files for -static-pie gcc option).</flag>
164 <flag name="suid">Make internal pt_chown helper setuid -- not needed if using Linux and have /dev/pts mounted with gid=5</flag>
165 <flag name="systemtap">enable systemtap static probe points</flag>