Bug 31867 - "CPU ISA level is lower than required" on SSE2-free CPUs
Summary: "CPU ISA level is lower than required" on SSE2-free CPUs
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: build (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: 2.40
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-09 08:36 UTC by Sam James
Modified: 2024-06-15 10:14 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A patch (846 bytes, patch)
2024-06-09 20:50 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2024-06-09 08:36:09 UTC
Initially reported downstream in Gentoo at https://bugs.gentoo.org/933764.

We found that our release media ("stage3" builds - tarballs of a rootfs) couldn't be chrooted into on x86 (32-bit) systems without SSE2.

e.g. using https://distfiles.gentoo.org/releases/x86/autobuilds/current-stage3-i686-openrc/stage3-i686-openrc-20240603T164904Z.tar.xz:
```
$ chroot /mnt/gentoo
/usr/lib/libc.so.6: CPU ISA level is lower than required
```

Upon further investigation, it looks like this got exposed by 46c999741340ea559784c20a45077955b50aca43 for PR31676, which also got backported for 2.39.

I _think_ what's happening here is that libc_cv_have_x86_isa_level gets set to 'baseline' for both 32-bit and 64-bit (even with -march=i686 on a pure, non-multilib i686-* setup) and then the ISA marker gets added.
Comment 1 Sam James 2024-06-09 08:39:54 UTC
In sysdeps/x86/isa-level.h, we correctly do:
```
#if defined __SSE__ && defined __SSE2__
/* NB: ISAs, excluding MMX, in x86-64 ISA level baseline are used.  */
# define __X86_ISA_V1 1
#else
# define __X86_ISA_V1 0
#endif
```

But when we run the configure test, we do...
```
cat > conftest.c <<EOF
#include <sysdeps/x86/isa-level.h>
#if MINIMUM_X86_ISA_LEVEL >= 4
libc_cv_have_x86_isa_level=4
#elif MINIMUM_X86_ISA_LEVEL == 3
libc_cv_have_x86_isa_level=3
#elif MINIMUM_X86_ISA_LEVEL == 2
libc_cv_have_x86_isa_level=2
#else
libc_cv_have_x86_isa_level=baseline
#endif
EOF
```

On a CPU without SSE2, we will get 'baseline', and then...

```
if test $libc_cv_have_x86_isa_level = baseline; then
AC_DEFINE_UNQUOTED(MINIMUM_X86_ISA_LEVEL, 1)
else
AC_DEFINE_UNQUOTED(MINIMUM_X86_ISA_LEVEL, $libc_cv_have_x86_isa_level)
fi
```

We set MINIMUM_X86_ISA_LEVEL to 1, not 0, which seems wrong.
Comment 2 Sam James 2024-06-09 09:41:54 UTC
I still see the v3 marker appearing unexpectedly, so investigating more.
Comment 3 Sam James 2024-06-09 09:50:29 UTC
(In reply to Sam James from comment #2)
> I still see the v3 marker appearing unexpectedly, so investigating more.

(Is there a way to get bfd to print why it's adding a marker? e.g. inherited from X obj)
Comment 4 Sam James 2024-06-09 13:44:08 UTC
(In reply to Sam James from comment #2)
> I still see the v3 marker appearing unexpectedly, so investigating more.

I think ignore the v3 thing. This appears to be a separate issue.

(In reply to Sam James from comment #3)
> (In reply to Sam James from comment #2)
> > I still see the v3 marker appearing unexpectedly, so investigating more.
> 
> (Is there a way to get bfd to print why it's adding a marker? e.g. inherited
> from X obj)

I'll file a bfd bug for discussion.

--

Patch posted by awilfox: https://inbox.sourceware.org/libc-alpha/20240609133933.62366-1-AWilcox@Wilcox-Tech.com/T/#u
Comment 5 H.J. Lu 2024-06-09 20:50:40 UTC
Created attachment 15573 [details]
A patch

Please try this.
Comment 6 H.J. Lu 2024-06-09 20:52:56 UTC
(In reply to Sam James from comment #4)
> 
> Patch posted by awilfox:
> https://inbox.sourceware.org/libc-alpha/20240609133933.62366-1-
> AWilcox@Wilcox-Tech.com/T/#u

This is wrong since the minimum ISA level for x86-64 is 1, not 0.
Comment 7 Sam James 2024-06-10 16:46:05 UTC
(In reply to H.J. Lu from comment #5)
> Created attachment 15573 [details]
> A patch
> 
> Please try this.

This works. Thanks!

Tested-by: Ian Jordan <immoloism@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
Comment 8 Sourceware Commits 2024-06-11 07:10:31 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=09bc68b0ac26331a0109f0578c9368e09176da18

commit 09bc68b0ac26331a0109f0578c9368e09176da18
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Jun 10 13:02:06 2024 -0700

    x86: Properly set MINIMUM_X86_ISA_LEVEL for i386 [BZ #31867]
    
    On i386, set the default minimum ISA level to 0, not 1 (baseline which
    includes SSE2).  There are no changes in config.h nor in config.make on
    x86-64.  This fixes BZ #31867.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Tested-by: Ian Jordan <immoloism@gmail.com>
    Reviewed-by: Sam James <sam@gentoo.org>
    Reviewed-by: Florian Weimer <fweimer@redhat.com>
Comment 9 Sourceware Commits 2024-06-15 10:14:56 UTC
The release/2.39/master branch has been updated by Sam James <sjames@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b7f5b0a7114e29577daf64e68970673b61e5fcba

commit b7f5b0a7114e29577daf64e68970673b61e5fcba
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Jun 10 13:02:06 2024 -0700

    x86: Properly set MINIMUM_X86_ISA_LEVEL for i386 [BZ #31867]
    
    On i386, set the default minimum ISA level to 0, not 1 (baseline which
    includes SSE2).  There are no changes in config.h nor in config.make on
    x86-64.  This fixes BZ #31867.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    Tested-by: Ian Jordan <immoloism@gmail.com>
    Reviewed-by: Sam James <sam@gentoo.org>
    Reviewed-by: Florian Weimer <fweimer@redhat.com>
    (cherry picked from commit 09bc68b0ac26331a0109f0578c9368e09176da18)