Bug 1223967 - %suse_build_hwcaps_libs fails to generate -x86_64-v3 packages when shared library is an update-alternatives link
Summary: %suse_build_hwcaps_libs fails to generate -x86_64-v3 packages when shared lib...
Status: NEW
Alias: None
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Basesystem (show other bugs)
Version: Current
Hardware: x86-64 openSUSE Tumbleweed
: P5 - None : Normal (vote)
Target Milestone: ---
Assignee: Michael Schröder
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-06 13:12 UTC by Atri Bhattacharya
Modified: 2024-06-20 03:20 UTC (History)
4 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
Build log showing exactly where the failure occurs (566.97 KB, application/gzip)
2024-05-06 13:12 UTC, Atri Bhattacharya
Details
baselibs.conf - for comment #9. (2.57 KB, text/plain)
2024-05-11 13:55 UTC, Egbert Eich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Atri Bhattacharya 2024-05-06 13:12:28 UTC
## Originally reported on GitHub: https://github.com/openSUSE/obs-build/issues/1001

This came up when trying to enable -v3 hwcaps enhanced libs for `lapack`. As it turns out, `lapack` uses update-alternatives to create a symlink `/usr/lib64/libblas.so.3` pointing to the real library `/usr/lib64/blas/libblas.so.3` via `update-alternatives` called during `post`. The file `/usr/lib64/libblas.so.3` does not exist a build-time, but created by update-alternatives during `post` install. It is also marked as `%ghost` in the package. 

Apparently `%{?suse_build_hwcaps_libs}` cannot handle this. It tries to copy the non-existent — at build time — `/usr/lib64/libblas.so.3` and fails catastrophically _after_ actually generating the hwaps libs. This is what I see in the log. Note the error: `mv: cannot stat '.cfiles/usr/lib64/liblapack.so.3': No such file or directory` which suggests it is trying to move a non-existent file which will be created during `post` install:


> [  218s] RPMLINT report:
> [  218s] ===============
> [  220s] ============================ rpmlint session starts ============================
> [  220s] rpmlint: 2.5.0
> [  220s] configuration:
> [  220s]     /opt/testing/lib64/python3.11/rpmlint/configdefaults.toml
> [  220s]     /opt/testing/share/rpmlint/cron-whitelist.toml
> [  220s]     /opt/testing/share/rpmlint/dbus-services.toml
> [  220s]     /opt/testing/share/rpmlint/device-files-whitelist.toml
> [  220s]     /opt/testing/share/rpmlint/licenses.toml
> [  220s]     /opt/testing/share/rpmlint/opensuse.toml
> [  220s]     /opt/testing/share/rpmlint/pam-modules.toml
> [  220s]     /opt/testing/share/rpmlint/permissions-whitelist.toml
> [  220s]     /opt/testing/share/rpmlint/pie-executables.toml
> [  220s]     /opt/testing/share/rpmlint/polkit-rules-whitelist.toml
> [  220s]     /opt/testing/share/rpmlint/scoring.toml
> [  220s]     /opt/testing/share/rpmlint/security.toml
> [  220s]     /opt/testing/share/rpmlint/sudoers-whitelist.toml
> [  220s]     /opt/testing/share/rpmlint/sysctl-whitelist.toml
> [  220s]     /opt/testing/share/rpmlint/systemd-tmpfiles.toml
> [  220s]     /opt/testing/share/rpmlint/users-groups.toml
> [  220s]     /opt/testing/share/rpmlint/world-writable-whitelist.toml
> [  220s]     /opt/testing/share/rpmlint/zypper-plugins.toml
> [  220s] rpmlintrc:
> [  220s]     /home/abuild/rpmbuild/SOURCES/lapack.rpmlintrc
> [  220s] checks: 41, packages: 21
> [  220s] 
> [  220s] libblas3.x86_64: I: package-supports-update-alternatives
> [  220s] libcblas3.x86_64: I: package-supports-update-alternatives
> [  220s] liblapack3.x86_64: I: package-supports-update-alternatives
> [  220s] liblapacke3.x86_64: I: package-supports-update-alternatives
> [  220s] libblas3.x86_64_v3: I: package-supports-update-alternatives
> [  220s] libcblas3.x86_64_v3: I: package-supports-update-alternatives
> [  220s] liblapack3.x86_64_v3: I: package-supports-update-alternatives
> [  220s] liblapacke3.x86_64_v3: I: package-supports-update-alternatives
> [  220s] Check time report (>1% & >0.1s):
> [  220s]     Check                            Duration (in s)   Fraction (in %)  Checked files
> [  220s]     ExtractRpm                                   0.3              30.3               
> [  220s]     SignatureCheck                               0.2              19.6               
> [  220s]     BinariesCheck                                0.2              19.2               
> [  220s]     SharedLibraryPolicyCheck                     0.2              16.2               
> [  220s]     TOTAL                                        1.0             100.0               
> [  220s] 
> [  220s]  21 packages and 0 specfiles checked; 0 errors, 0 warnings, 131 filtered, 0 badness; has taken 1.1 s 
> [  220s] 
> [  220s] ... cleaning ccache
> [  220s] setting SOURCE_DATE_EPOCH_MTIME to 1714856125
> [  220s] 1
> [  220s] ... saving ccache archive
> [  220s] ... creating baselibs
> [  220s] setting SOURCE_DATE_EPOCH_MTIME to 1714856125
> [  220s] no targets for arch x86_64, skipping lapack-devel
> [  220s] no targets for arch x86_64, skipping liblapack3
> [  220s] no targets for arch x86_64, skipping lapacke-devel
> [  220s] no targets for arch x86_64, skipping libblas3
> [  220s] no targets for arch x86_64, skipping liblapacke3
> [  220s] no targets for arch x86_64, skipping libcblas3
> [  220s] no targets for arch x86_64, skipping cblas-devel
> [  220s] no targets for arch x86_64, skipping blas-devel
> [  220s] liblapack3(x86_64:x86-64-v3): writing specfile...
> [  220s] liblapack3(x86_64:x86-64-v3): running build...
> [  220s] rpmbuild failed: 256
> [  220s] re-running in verbose mode:
> [  220s] using SOURCE_DATE_EPOCH with value 1714856124 as build time
> [  220s] Executing(%prep): /usr/bin/bash -e /var/tmp/rpm-tmp.r51odx
> [  220s] + umask 022
> [  220s] + cd /home/abuild/rpmbuild/BUILD
> [  220s] + RPM_EC=0
> [  220s] ++ jobs -p
> [  220s] + exit 0
> [  220s] Executing(%build): /usr/bin/bash -e /var/tmp/rpm-tmp.dHOH58
> [  220s] + umask 022
> [  220s] + cd /home/abuild/rpmbuild/BUILD
> [  220s] + /usr/bin/rm -rf /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  220s] ++ dirname /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  220s] + /usr/bin/mkdir -p /home/abuild/rpmbuild/BUILDROOT
> [  220s] + /usr/bin/mkdir /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  220s] + RPM_EC=0
> [  220s] ++ jobs -p
> [  220s] + exit 0
> [  220s] Executing(%install): /usr/bin/bash -e /var/tmp/rpm-tmp.Aiq5Zt
> [  220s] + umask 022
> [  220s] + cd /home/abuild/rpmbuild/BUILD
> [  220s] + /usr/bin/rm -rf /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  220s] + /usr/bin/mkdir -p /home/abuild/rpmbuild/BUILDROOT
> [  220s] + /usr/bin/mkdir /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  220s] + rm -rf /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  220s] + mkdir /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  220s] + cd /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  220s] + mkdir -p .cfiles
> [  220s] + pushd .cfiles
> [  220s] ~/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64/.cfiles ~/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  220s] + cat
> [  220s] + rpm2cpio //home/abuild/rpmbuild/RPMS/x86_64_v3/liblapack3-3.12.0-94.1.x86_64_v3.rpm
> [  220s] + cpio -i -d -v -E .filelist
> [  220s] ./usr/lib64/lapack/liblapack.so.3
> [  221s] ./usr/lib64/lapack/liblapack.so.3.12.0
> [  221s] 15311 blocks
> [  221s] + popd
> [  221s] ~/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64
> [  221s] + mkdir -p /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64/usr/lib64/glibc-hwcaps/x86-64-v3/lapack
> [  221s] + mv .cfiles/usr/lib64/lapack/liblapack.so.3 /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64/usr/lib64/glibc-hwcaps/x86-64-v3/lapack/liblapack.so.3
> [  221s] + mkdir -p /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64/usr/lib64/glibc-hwcaps/x86-64-v3/lapack
> [  221s] + mv .cfiles/usr/lib64/lapack/liblapack.so.3.12.0 /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64/usr/lib64/glibc-hwcaps/x86-64-v3/lapack/liblapack.so.3.12.0
> [  221s] + mkdir -p /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64/usr/lib64/glibc-hwcaps/x86-64-v3
> [  221s] + mv .cfiles/usr/lib64/liblapack.so.3 /home/abuild/rpmbuild/BUILDROOT/lapack-3.12.0-94.1.x86_64/usr/lib64/glibc-hwcaps/x86-64-v3/liblapack.so.3
> [  221s] mv: cannot stat '.cfiles/usr/lib64/liblapack.so.3': No such file or directory
> [  221s] error: Bad exit status from /var/tmp/rpm-tmp.Aiq5Zt (%install)
> [  221s] 
> [  221s] RPM build errors:
> [  221s]     Bad exit status from /var/tmp/rpm-tmp.Aiq5Zt (%install)
> [  221s] ### VM INTERACTION START ###
> [  221s] [  217.139930][    T1] sysrq: Power Off
> [  221s] [  217.141087][   T10] reboot: Power down
> [  221s] ### VM INTERACTION END ###
> [  221s] 
> [  221s] i01-ch1d failed "build lapack.spec" at Mon May  6 11:51:16 UTC 2024.
> [  221s] 



FWIW, here is the baselibs.conf:

> ...
> 
> liblapack3
>   -/usr/lib(64)?/liblapack.so.3
>   requires "update-alternatives"
>   postin "ln -sf /etc/alternatives/liblapack.so.3_<targettype> /usr/%_lib/liblapack.so.3"
>   postin "/usr/sbin/update-alternatives --force --install /usr/%_lib/liblapack.so.3 liblapack.so.3_<targettype> /usr/%_lib/lapack/liblapack.so.3  50"
>   postun "/usr/sbin/update-alternatives --remove liblapack.so.3_<targettype> /usr/%_lib/lapack/liblapack.so.3"
> 
> ...


And attached is the full build log if it helps (from https://build.opensuse.org/package/show/home:badshah400:lapackv3/lapack).
Comment 1 Atri Bhattacharya 2024-05-06 13:12:57 UTC
Created attachment 874694 [details]
Build log showing exactly where the failure occurs
Comment 2 Atri Bhattacharya 2024-05-09 12:58:59 UTC
Dominique, would you please have a look (in your own time, no hurry).

Thanks in advance.
Comment 3 Richard Biener 2024-05-10 07:02:13 UTC
Hmm, but the dynamic loader relies on the shared library to be present in
/usr/lib64/hwcaps/x86-64-v3/ (IIRC).  So to work the alternatives link
would need to be present there, pointing to the actual hwcaps library
in /usr/lib64/blas/hwcaps/x86-64-v3/... (or another directory or a changed
library name).

So I don't see how the generic hwcaps mechanism can be made work for the
case of lapack.  To me it seems the library copying would need to be
done manually in lapack and only the multibuild part of the hwcaps
mechanism preserved?

That said, IMO having "alternatives" for shared libraries is a red herring...
(but yeah, I understand why we have it, but then there's nothing wrong
with Conflicts and multiple providers of liblapack.so.3)
Comment 4 Atri Bhattacharya 2024-05-10 11:50:11 UTC
(In reply to Richard Biener from comment #3)
> Hmm, but the dynamic loader relies on the shared library to be present in
> /usr/lib64/hwcaps/x86-64-v3/ (IIRC).  So to work the alternatives link
> would need to be present there, pointing to the actual hwcaps library
> in /usr/lib64/blas/hwcaps/x86-64-v3/... (or another directory or a changed
> library name).
> 
> So I don't see how the generic hwcaps mechanism can be made work for the
> case of lapack.  To me it seems the library copying would need to be
> done manually in lapack and only the multibuild part of the hwcaps
> mechanism preserved?

I see, thanks for the explanation.

> 
> That said, IMO having "alternatives" for shared libraries is a red herring...
> (but yeah, I understand why we have it, but then there's nothing wrong
> with Conflicts and multiple providers of liblapack.so.3)

Alternatively, is there a way to directly generate the -v3 tuned libs using a multibuild flavour specifically for this? I mean, we could give using the right flags to generate the v3 libs, move them to the appropriate location and package them as part of a package manually named to liblapack-x86_64-v3 or similar. However, I do not know what the macro does in step-by-step detail.
Comment 5 Egbert Eich 2024-05-10 18:51:10 UTC
On top of this, I believe I found a bug in /usr/lib/build/mkbaselibs which prevents 
 liblapacke3
   -/usr/lib(64)?/liblapacke.so.3
to work correctly. This change would fix it:
      } elsif (substr($r, 0, 1) eq '-') {
        delete $files{$_} for grep {/$rr/} keys %files;
+       delete $moves{$_} for grep {/$rr/} keys %moves;
      } elsif (substr($r, 0, 1) eq '"') {

However, this is moot since baselibs is too limited anyway.

Of course, you could use _multibuild to create the entire set of libraries as v3 libs. %_libdir would have to point to /usr/lib64/hwcaps/x86-64-v3/ and you may want to append a '_v3' to the names of the blas, cblas, lapack and lapacke subdirectories where the 'real' versions of the libraries reside.
Moreover, since this is for x86_64 only, you need to make sure to prevent the build of the v3 flavor on other arches.
Of course, this will not make the spec file more readable.
Comment 6 Atri Bhattacharya 2024-05-10 19:43:05 UTC
(In reply to Egbert Eich from comment #5)
> On top of this, I believe I found a bug in /usr/lib/build/mkbaselibs which
> prevents 
>  liblapacke3
>    -/usr/lib(64)?/liblapacke.so.3
> to work correctly. This change would fix it:
>       } elsif (substr($r, 0, 1) eq '-') {
>         delete $files{$_} for grep {/$rr/} keys %files;
> +       delete $moves{$_} for grep {/$rr/} keys %moves;
>       } elsif (substr($r, 0, 1) eq '"') {
> 
> However, this is moot since baselibs is too limited anyway.
> 
> Of course, you could use _multibuild to create the entire set of libraries
> as v3 libs. %_libdir would have to point to /usr/lib64/hwcaps/x86-64-v3/ and
> you may want to append a '_v3' to the names of the blas, cblas, lapack and
> lapacke subdirectories where the 'real' versions of the libraries reside.
> Moreover, since this is for x86_64 only, you need to make sure to prevent
> the build of the v3 flavor on other arches.
> Of course, this will not make the spec file more readable.

Thanks Egbert, I will try to make this multibuild work. You can review it and see how it looks and we can discard it if the specfile becomes too unwieldy. Complex specfiles will turn off potential new contributors, but AVX/AVX2 enhanced lapack might be too good to miss out on... tricky balancing act.

Correct me if I am wrong, but the GCC `-march` I would use for the new flavour is just `x86-64-v3`, right? That's it, no other additional flags?
Comment 7 Atri Bhattacharya 2024-05-11 07:43:23 UTC
So, what do we think:
<https://build.opensuse.org/package/show/home:badshah400:lapackv3/lapack>

> ~> cat _multibuild
> <multibuild>
>   <package>static</package>
>   <package>x86-64-v3</package>
> </multibuild>


> ~> ls -1 *x86-64-v3*.rpm
> libblas3-x86-64-v3-3.12.0-97.1.x86_64.rpm
> libcblas3-x86-64-v3-3.12.0-97.1.x86_64.rpm
> liblapack3-x86-64-v3-3.12.0-97.1.x86_64.rpm
> liblapacke3-x86-64-v3-3.12.0-97.1.x86_64.rpm
> libtmglib3-x86-64-v3-3.12.0-97.1.x86_64.rpm


> ~> rpm -qvlp ./libblas3-x86-64-v3-3.12.0-97.1.x86_64.rpm 
> ----------    1 root     root                        0 May  5 02:25 /etc/alternatives/libblas.so.3-x86-64-v3_x86_64
> drwxr-xr-x    2 root     root                        0 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/blas
> lrwxrwxrwx    1 root     root                       17 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/blas/libblas.so.3 -> libblas.so.3.12.0
> -rwxr-xr-x    1 root     root                  1050584 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/blas/libblas.so.3.12.0
> lrwxrwxrwx    1 root     root                       37 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/libblas.so.3 -> /etc/alternatives/libblas.so.3_x86_64
> drwxr-xr-x    2 root     root                        0 May  5 02:25 /usr/share/doc/packages/libblas3-x86-64-v3
> -rw-r--r--    1 root     root                     6175 May  5 02:25 /usr/share/doc/packages/libblas3-x86-64-v3/README.md
> drwxr-xr-x    2 root     root                        0 May  5 02:25 /usr/share/licenses/libblas3-x86-64-v3
> -rw-r--r--    1 root     root                     2266 May  5 02:25 /usr/share/licenses/libblas3-x86-64-v3/LICENSE

Most of the hwcaps related definitions are in the preamble. I tried to preserve the maintainability/readability of the specfile to the extent I think is possible.

Suggestions welcome.
Comment 8 Atri Bhattacharya 2024-05-11 10:27:04 UTC
(In reply to Atri Bhattacharya from comment #7)
> 
> 
> > ~> rpm -qvlp ./libblas3-x86-64-v3-3.12.0-97.1.x86_64.rpm 
> > ----------    1 root     root                        0 May  5 02:25 /etc/alternatives/libblas.so.3-x86-64-v3_x86_64
> > drwxr-xr-x    2 root     root                        0 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/blas
> > lrwxrwxrwx    1 root     root                       17 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/blas/libblas.so.3 -> libblas.so.3.12.0
> > -rwxr-xr-x    1 root     root                  1050584 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/blas/libblas.so.3.12.0
> > lrwxrwxrwx    1 root     root                       37 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/libblas.so.3 -> /etc/alternatives/libblas.so.3_x86_64
> > drwxr-xr-x    2 root     root                        0 May  5 02:25 /usr/share/doc/packages/libblas3-x86-64-v3
> > -rw-r--r--    1 root     root                     6175 May  5 02:25 /usr/share/doc/packages/libblas3-x86-64-v3/README.md
> > drwxr-xr-x    2 root     root                        0 May  5 02:25 /usr/share/licenses/libblas3-x86-64-v3
> > -rw-r--r--    1 root     root                     2266 May  5 02:25 /usr/share/licenses/libblas3-x86-64-v3/LICENSE
> 

Bit of a bug in the link to /etc/alternatives there, which I have already fixed since:

> ~> rpm -qvlp RPM/libblas3-x86-64-v3-3.12.0-101.1.x86_64.rpm 
> ----------    1 root     root                        0 May  5 02:25 /etc/alternatives/libblas.so.3-x86-64-v3_x86_64
> drwxr-xr-x    2 root     root                        0 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/blas
> lrwxrwxrwx    1 root     root                       17 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/blas/libblas.so.3 -> libblas.so.3.12.0
> -rwxr-xr-x    1 root     root                  1050584 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/blas/libblas.so.3.12.0
> lrwxrwxrwx    1 root     root                       47 May  5 02:25 /usr/lib64/glibc-hwcaps/x86-64-v3/libblas.so.3 -> /etc/alternatives/libblas.so.3-x86-64-v3_x86_64
> drwxr-xr-x    2 root     root                        0 May  5 02:25 /usr/share/doc/packages/libblas3-x86-64-v3
> -rw-r--r--    1 root     root                     6175 May  5 02:25 /usr/share/doc/packages/libblas3-x86-64-v3/README.md
> drwxr-xr-x    2 root     root                        0 May  5 02:25 /usr/share/licenses/libblas3-x86-64-v3
> -rw-r--r--    1 root     root                     2266 May  5 02:25 /usr/share/licenses/libblas3-x86-64-v3/LICENSE
> 


Apologies for the noise.
Comment 9 Egbert Eich 2024-05-11 13:53:09 UTC
Actually, I believe I got baselibs.conf to work - at least the library part, haven't looked into the devel packages, yet - also a master/slave mechanism for the update alternatives may be needed.
This will work only if the fix from comment #5 is applied to /usr/lib/build/mkbaselibs. I will try to discuss this with the maintainer on Monday.
Comment 10 Egbert Eich 2024-05-11 13:55:26 UTC
Created attachment 874823 [details]
baselibs.conf - for comment #9.
Comment 11 Atri Bhattacharya 2024-05-11 14:02:53 UTC
(In reply to Egbert Eich from comment #9)
> Actually, I believe I got baselibs.conf to work - at least the library part,
> haven't looked into the devel packages, yet - also a master/slave mechanism
> for the update alternatives may be needed.
> This will work only if the fix from comment #5 is applied to
> /usr/lib/build/mkbaselibs. I will try to discuss this with the maintainer on
> Monday.

Wow, that's just wow. Colour me impressed!
Comment 12 Atri Bhattacharya 2024-05-11 18:33:59 UTC
(In reply to Egbert Eich from comment #9)
> Actually, I believe I got baselibs.conf to work - at least the library part,
> haven't looked into the devel packages, yet

My understanding is that devel pkgs do not need to be administered the hwcaps treatment: What happens is that glibc automatically points the .so link in the devel pkg to the hwcaps dir `/usr/lib64/glibc-hwcaps/x86-64-v3/` target should both that dir and `/usr/lib64` contain the same name shared object even if the devel .so link target is to the latter. At least that is my reading of how it works with the zlib pkg anyway.
Comment 13 Egbert Eich 2024-05-13 04:57:48 UTC
(In reply to Atri Bhattacharya from comment #12)
> (In reply to Egbert Eich from comment #9)
> > Actually, I believe I got baselibs.conf to work - at least the library part,
> > haven't looked into the devel packages, yet
> 
> My understanding is that devel pkgs do not need to be administered the
> hwcaps treatment: What happens is that glibc automatically points the .so
> link in the devel pkg to the hwcaps dir `/usr/lib64/glibc-hwcaps/x86-64-v3/`
> target should both that dir and `/usr/lib64` contain the same name shared
> object even if the devel .so link target is to the latter. At least that is
> my reading of how it works with the zlib pkg anyway.

This would mean that we still need a link from glibc-hwcaps/x86-64-v3/liblapack.so.3.12.0 to glibc-hwcaps/x86-64-v3/lapack/liblapack.so.3.12.0. Since this would have to be created from within baselibs.conf, there is the challenge how to obtain the .so version. This could be added to baselibs.conf if it was auto-generated from the main spec file.
Comment 14 Richard Biener 2024-05-13 08:44:53 UTC
(In reply to Atri Bhattacharya from comment #12)
> (In reply to Egbert Eich from comment #9)
> > Actually, I believe I got baselibs.conf to work - at least the library part,
> > haven't looked into the devel packages, yet
> 
> My understanding is that devel pkgs do not need to be administered the
> hwcaps treatment: What happens is that glibc automatically points the .so
> link in the devel pkg to the hwcaps dir `/usr/lib64/glibc-hwcaps/x86-64-v3/`
> target should both that dir and `/usr/lib64` contain the same name shared
> object even if the devel .so link target is to the latter. At least that is
> my reading of how it works with the zlib pkg anyway.

The link editor (/usr/bin/ld) processes the /usr/lib64/lib*.so link, hwcaps
do not come into play at all here.  The hwcaps variant is expected to have
the same ABI as the "standard" variant so it doesn't make a difference which
to use at link time.

The dynamic loader upon execution of the linked program will then pick
the hwcaps variant if the hardware matches.

Note this is where it might be important that the hwcaps and non-hwcaps
variant alternatives come from the same implementation unless the ABIs
are 100% the same.  So I think ideally the alternatives setup would
have a link group and a single config to adjust.  Not sure if it's done
this way and whether it's possible at all if the group is split between
two packages.
Comment 15 Atri Bhattacharya 2024-05-13 13:02:41 UTC
(In reply to Egbert Eich from comment #13)
> (In reply to Atri Bhattacharya from comment #12)
> > (In reply to Egbert Eich from comment #9)
> > > Actually, I believe I got baselibs.conf to work - at least the library part,
> > > haven't looked into the devel packages, yet
> > 
> > My understanding is that devel pkgs do not need to be administered the
> > hwcaps treatment: What happens is that glibc automatically points the .so
> > link in the devel pkg to the hwcaps dir `/usr/lib64/glibc-hwcaps/x86-64-v3/`
> > target should both that dir and `/usr/lib64` contain the same name shared
> > object even if the devel .so link target is to the latter. At least that is
> > my reading of how it works with the zlib pkg anyway.
> 
> This would mean that we still need a link from
> glibc-hwcaps/x86-64-v3/liblapack.so.3.12.0 to
> glibc-hwcaps/x86-64-v3/lapack/liblapack.so.3.12.0. Since this would have to
> be created from within baselibs.conf, there is the challenge how to obtain
> the .so version. This could be added to baselibs.conf if it was
> auto-generated from the main spec file.

Yes, we could do with lapack's baselibs.conf the same as we did with openblas's i.e. generate it dynamically from inside the specfile. I think we are slowly approaching the point where the baselibs.conf becomes difficult to read as well, though.

What do we think about doing it the multibuild way instead, something like my trial in <https://build.opensuse.org/package/show/home:badshah400:lapackv3/lapack> goes? Looks more transparent, to me anyway.
Comment 16 Atri Bhattacharya 2024-05-23 08:53:17 UTC
(In reply to Richard Biener from comment #14)
> 
> Note this is where it might be important that the hwcaps and non-hwcaps
> variant alternatives come from the same implementation unless the ABIs
> are 100% the same.  So I think ideally the alternatives setup would
> have a link group and a single config to adjust.  Not sure if it's done
> this way and whether it's possible at all if the group is split between
> two packages.

We should probably implement a main and slave alternatives setup anyway so that both libblas.so.* and liblapack.so.* come from the same implementation. At the moment, my understanding is that one could theoretically use blas from implementation A (say, openblas) while still using cblas and lapack from the implementation B (reference netlib library, for example). I do not know whether this kind of usage is advisable.
Comment 17 Egbert Eich 2024-06-12 05:35:13 UTC
The current baselibs.conf still uses the apparently broken
| liblapack3
|   -/usr/lib(64)?/liblapack.so.3
directive

I've therefore created https://github.com/openSUSE/obs-build/issues/1010
Comment 18 Atri Bhattacharya 2024-06-12 06:48:02 UTC
(In reply to Egbert Eich from comment #17)
> The current baselibs.conf still uses the apparently broken
> | liblapack3
> |   -/usr/lib(64)?/liblapack.so.3
> directive
> 
> I've therefore created https://github.com/openSUSE/obs-build/issues/1010

Thanks, yes we need this fix in mkbaselibs.
Comment 19 Egbert Eich 2024-06-12 13:07:22 UTC
(In reply to Atri Bhattacharya from comment #18)
> (In reply to Egbert Eich from comment #17)
> > The current baselibs.conf still uses the apparently broken
> > | liblapack3
> > |   -/usr/lib(64)?/liblapack.so.3
> > directive
> > 
> > I've therefore created https://github.com/openSUSE/obs-build/issues/1010
> 
> Thanks, yes we need this fix in mkbaselibs.

Good news, after creating the github ticket, this got addressed.

@Atri, could you check if things are starting to work for you (it may take a while until the update has arrived in Factory/TW)? If so, we may be able to close this ticket.
Comment 20 Atri Bhattacharya 2024-06-12 16:30:54 UTC
(In reply to Egbert Eich from comment #19)
> (In reply to Atri Bhattacharya from comment #18)
> > (In reply to Egbert Eich from comment #17)
> > > The current baselibs.conf still uses the apparently broken
> > > | liblapack3
> > > |   -/usr/lib(64)?/liblapack.so.3
> > > directive
> > > 
> > > I've therefore created https://github.com/openSUSE/obs-build/issues/1010
> > 
> > Thanks, yes we need this fix in mkbaselibs.
> 
> Good news, after creating the github ticket, this got addressed.
> 
> @Atri, could you check if things are starting to work for you (it may take a
> while until the update has arrived in Factory/TW)? If so, we may be able to
> close this ticket.

Thanks Egbert, this works great. Checkout rev 35 in obs://home:badshah400:lapack2023/lapack, where I have enabled the -v3 libs. In the same project I have patched the `build` package to add the mkbaselibs commit referenced in the github issue to get this working.

This is just for testing now, I shall revert the hwcaps change in lapack before making the sr for boo#1223783 (since, as you have noted, we need to wait until Factory catches up with the mkbaselibs fix for this).
Comment 21 Atri Bhattacharya 2024-06-12 16:31:44 UTC
Also kudos for the great catch as to where the problem lay!
Comment 22 Atri Bhattacharya 2024-06-12 17:54:25 UTC
(In reply to Atri Bhattacharya from comment #20)
> 
> Thanks Egbert, this works great. Checkout rev 35 in
> obs://home:badshah400:lapack2023/lapack, where I have enabled the -v3 libs.
> In the same project I have patched the `build` package to add the mkbaselibs
> commit referenced in the github issue to get this working.

This has now moved to a new project: https://build.opensuse.org/project/show/home:badshah400:lapack-hwcaps
so that I can go ahead and submit the fix to boo#1223783 from the old (home:badshah400:lapack2023) project where I have reverted the hwcaps generation.

Sorry for the confusion.
Comment 23 Egbert Eich 2024-06-13 10:37:12 UTC
@Atri: the major issues I'm seeing with the approach in home:badshah400:lapackv3/lapack are lines in baselib.conf like this:
  postin "ln -sf /etc/alternatives/libblas.so.3_<targettype> /usr/%_lib/libblas.so.3"
  postin "/usr/sbin/update-alternatives --force --install /usr/%_lib/libblas.so.3 libblas.so.3_<targettype> /usr/%_lib/blas/libblas.so.3  50"
  postun "/usr/sbin/update-alternatives --remove libblas.so.3_<targettype> /usr/%_lib/blas/libblas.so.3"

%_lib is a standard define which expands to /usr/lib or /usr/lib64. It doesn't expand to /usr/lib64/glibc-hwcaps/<targettype>:

home:badshah400:lapack-hwcaps/lapack/binaries$ rpm -q --scripts -p libcblas3-x86-64-v3-3.12.0-1.1.x86_64.rpm
warning: libcblas3-x86-64-v3-3.12.0-1.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 4aeaf2b5: NOKEY
postinstall scriptlet (using /bin/sh):
/sbin/ldconfig
ln -sf /etc/alternatives/libcblas.so.3_x86-64-v3 /usr/lib64/libcblas.so.3
/usr/sbin/update-alternatives --force --install /usr/lib64/libcblas.so.3 libcblas.so.3_x86-64-v3 /usr/lib64/blas/libcblas.so.3  50
preuninstall scriptlet (using /bin/sh):
/usr/sbin/update-alternatives --remove libcblas.so.3_x86-64-v3 /usr/lib64/blas/libcblas.so.3

The only way to handle this I can think of would be to do something like this:

  postin "ldconfig -n /usr/%_lib/glibc-hwcaps/<targettype>/blas"
  postin "case <targettype> in x86-64-v*) p=glibc-hwcaps/<targettype> ;; esac"
  postin "/usr/sbin/update-alternatives --force --install /usr/%_lib/$p/libblas.so.3 libblas.so.3_<targettype> /usr/%_\
lib/$p/blas/libblas.so.3  50"
  postun "case <targettype> in x86-64-v*) p=glibc-hwcaps/<targettype> ;; esac"
  postun "/usr/sbin/update-alternatives --remove libblas.so.3_<targettype> /usr/%_lib/$p/libblas.so.3"

Disclaimer: I haven't tested this.
Comment 24 Atri Bhattacharya 2024-06-13 15:35:38 UTC
(In reply to Egbert Eich from comment #23)
> @Atri: the major issues I'm seeing with the approach in
> home:badshah400:lapackv3/lapack are lines in baselib.conf like this:
>   postin "ln -sf /etc/alternatives/libblas.so.3_<targettype>
> /usr/%_lib/libblas.so.3"
>   postin "/usr/sbin/update-alternatives --force --install
> /usr/%_lib/libblas.so.3 libblas.so.3_<targettype>
> /usr/%_lib/blas/libblas.so.3  50"
>   postun "/usr/sbin/update-alternatives --remove libblas.so.3_<targettype>
> /usr/%_lib/blas/libblas.so.3"
> 
> %_lib is a standard define which expands to /usr/lib or /usr/lib64. It
> doesn't expand to /usr/lib64/glibc-hwcaps/<targettype>:
> 
> home:badshah400:lapack-hwcaps/lapack/binaries$ rpm -q --scripts -p
> libcblas3-x86-64-v3-3.12.0-1.1.x86_64.rpm
> warning: libcblas3-x86-64-v3-3.12.0-1.1.x86_64.rpm: Header V3 RSA/SHA256
> Signature, key ID 4aeaf2b5: NOKEY
> postinstall scriptlet (using /bin/sh):
> /sbin/ldconfig
> ln -sf /etc/alternatives/libcblas.so.3_x86-64-v3 /usr/lib64/libcblas.so.3
> /usr/sbin/update-alternatives --force --install /usr/lib64/libcblas.so.3
> libcblas.so.3_x86-64-v3 /usr/lib64/blas/libcblas.so.3  50
> preuninstall scriptlet (using /bin/sh):
> /usr/sbin/update-alternatives --remove libcblas.so.3_x86-64-v3
> /usr/lib64/blas/libcblas.so.3
> 
> The only way to handle this I can think of would be to do something like
> this:
> 
>   postin "ldconfig -n /usr/%_lib/glibc-hwcaps/<targettype>/blas"
>   postin "case <targettype> in x86-64-v*) p=glibc-hwcaps/<targettype> ;;
> esac"
>   postin "/usr/sbin/update-alternatives --force --install
> /usr/%_lib/$p/libblas.so.3 libblas.so.3_<targettype> /usr/%_\
> lib/$p/blas/libblas.so.3  50"
>   postun "case <targettype> in x86-64-v*) p=glibc-hwcaps/<targettype> ;;
> esac"
>   postun "/usr/sbin/update-alternatives --remove libblas.so.3_<targettype>
> /usr/%_lib/$p/libblas.so.3"
> 
> Disclaimer: I haven't tested this.

The attempt in obs://home:badshah400:lapackv3/lapack is to generate the x86-64-v3 libs purely as a separate flavour, *without* the baselibs.conf coming into play at all in so far as these -v3 libs are concerned.

Baselibs.conf is still used to produce 32-bit biarch packages for pure x86_64 in this case, but it simply does not matter for x86-64-v3 flavour since there aren't i586-v3 equivalents.

But perhaps I misunderstand your question?
Comment 25 Atri Bhattacharya 2024-06-13 15:42:11 UTC
In other words, for no-name flavour:

> ~> osc ls -b home:badshah400:lapackv3 lapack -r openSUSE_Tumbleweed -a x86_64
> ::import::i586::blas-devel-32bit-3.12.0-117.1.x86_64.rpm
> ::import::i586::cblas-devel-32bit-3.12.0-117.1.x86_64.rpm
> ::import::i586::lapack-devel-32bit-3.12.0-117.1.x86_64.rpm
> ::import::i586::lapacke-devel-32bit-3.12.0-117.1.x86_64.rpm
> ::import::i586::libblas3-32bit-3.12.0-117.1.x86_64.rpm
> ::import::i586::libblas3-32bit-debuginfo-3.12.0-117.1.x86_64.rpm
> ::import::i586::libcblas3-32bit-3.12.0-117.1.x86_64.rpm
> ::import::i586::libcblas3-32bit-debuginfo-3.12.0-117.1.x86_64.rpm
> ::import::i586::liblapack3-32bit-3.12.0-117.1.x86_64.rpm
> ::import::i586::liblapack3-32bit-debuginfo-3.12.0-117.1.x86_64.rpm
> ::import::i586::liblapacke3-32bit-3.12.0-117.1.x86_64.rpm
> ::import::i586::liblapacke3-32bit-debuginfo-3.12.0-117.1.x86_64.rpm
> _buildenv
> _statistics
> blas-devel-3.12.0-117.1.x86_64.rpm
> cblas-devel-3.12.0-117.1.x86_64.rpm
> lapack-3.12.0-117.1.src.rpm
> lapack-debugsource-3.12.0-117.1.x86_64.rpm
> lapack-devel-3.12.0-117.1.x86_64.rpm
> lapacke-devel-3.12.0-117.1.x86_64.rpm
> libblas3-3.12.0-117.1.x86_64.rpm
> libblas3-debuginfo-3.12.0-117.1.x86_64.rpm
> libcblas3-3.12.0-117.1.x86_64.rpm
> libcblas3-debuginfo-3.12.0-117.1.x86_64.rpm
> liblapack3-3.12.0-117.1.x86_64.rpm
> liblapack3-debuginfo-3.12.0-117.1.x86_64.rpm
> liblapacke3-3.12.0-117.1.x86_64.rpm
> liblapacke3-debuginfo-3.12.0-117.1.x86_64.rpm
> libtmglib3-3.12.0-117.1.x86_64.rpm
> libtmglib3-debuginfo-3.12.0-117.1.x86_64.rpm
> rpmlint.log
> tmglib-devel-3.12.0-117.1.x86_64.rpm

while no baselibs-based biarch RPMs for the "x86-64-v3" flavour:

> ~> osc ls -b home:badshah400:lapackv3 lapack:x86-64-v3 -r openSUSE_Tumbleweed -a x86_64 
> _buildenv
> _statistics
> lapack-x86-64-v3-3.12.0-117.1.src.rpm
> lapack-x86-64-v3-debugsource-3.12.0-117.1.x86_64.rpm
> libblas3-x86-64-v3-3.12.0-117.1.x86_64.rpm
> libblas3-x86-64-v3-debuginfo-3.12.0-117.1.x86_64.rpm
> libcblas3-x86-64-v3-3.12.0-117.1.x86_64.rpm
> libcblas3-x86-64-v3-debuginfo-3.12.0-117.1.x86_64.rpm
> liblapack3-x86-64-v3-3.12.0-117.1.x86_64.rpm
> liblapack3-x86-64-v3-debuginfo-3.12.0-117.1.x86_64.rpm
> liblapacke3-x86-64-v3-3.12.0-117.1.x86_64.rpm
> liblapacke3-x86-64-v3-debuginfo-3.12.0-117.1.x86_64.rpm
> libtmglib3-x86-64-v3-3.12.0-117.1.x86_64.rpm
> libtmglib3-x86-64-v3-debuginfo-3.12.0-117.1.x86_64.rpm
> rpmlint.log
Comment 26 Egbert Eich 2024-06-19 11:14:41 UTC
(In reply to Atri Bhattacharya from comment #24)
> 
> The attempt in obs://home:badshah400:lapackv3/lapack is to generate the
> x86-64-v3 libs purely as a separate flavour, *without* the baselibs.conf
> coming into play at all in so far as these -v3 libs are concerned.
> 
> Baselibs.conf is still used to produce 32-bit biarch packages for pure
> x86_64 in this case, but it simply does not matter for x86-64-v3 flavour
> since there aren't i586-v3 equivalents.
> 
> But perhaps I misunderstand your question?

No, you don't. What confused me: you were using the %suse_build_hwcaps macro - which you have removed since. The problem I see is: this macro is crafted to add the right 'magic' to the spec file (see https://en.opensuse.org/openSUSE:Packaging_Conventions_RPM_Macros#%{?suse_build_hwcaps_libs}). This magic is "to automatically set specific build targets and schedule the job on workers which match the intended buildconstraint". Unfortunately, one can only guess how this works. Without baselibs.conf, two arch flavors will be built: x86_64 and x86_x6_v3. So I would think if you want to use flavors, you'd need to add:
#!BuildTarget: x86_64_v3-linux
#!BuildConstraint: hardware:cpu:flag x86-64-v3
to the spec file in the -v3 flavor on x86_64. When using baselibs.conf for -v3,  mkbaselibs will create a spec file which consumes these packages and 'repackages them into the main architecture'. You may need to do all this manually.
I'm currently trying to figure out how all this works.
Comment 27 Atri Bhattacharya 2024-06-20 03:20:04 UTC
(In reply to Egbert Eich from comment #26)
> (In reply to Atri Bhattacharya from comment #24)
> > 
> > The attempt in obs://home:badshah400:lapackv3/lapack is to generate the
> > x86-64-v3 libs purely as a separate flavour, *without* the baselibs.conf
> > coming into play at all in so far as these -v3 libs are concerned.
> > 
> > Baselibs.conf is still used to produce 32-bit biarch packages for pure
> > x86_64 in this case, but it simply does not matter for x86-64-v3 flavour
> > since there aren't i586-v3 equivalents.
> > 
> > But perhaps I misunderstand your question?
> 
> No, you don't. What confused me: you were using the %suse_build_hwcaps macro
> - which you have removed since.

Yes, this macro should not be used if we want to use flavours to manually produce the -v3 libs instead of their generation via baselibs.

> The problem I see is: this macro is crafted
> to add the right 'magic' to the spec file (see
> https://en.opensuse.org/openSUSE:
> Packaging_Conventions_RPM_Macros#%{?suse_build_hwcaps_libs}). This magic is
> "to automatically set specific build targets and schedule the job on workers
> which match the intended buildconstraint". Unfortunately, one can only guess
> how this works. 

My understanding is that it pretty much checks for the avx/avx2 instruction support on the build host's CPU. Similar to having a _constraint file that limits the build to the avx2 supporting CPUs:

> ~> cat _constraints
> <constraints>
>   <hardware><cpu>
>     <flag>sse3</flag>
>     <flag>avx2</flag>
>   </cpu></hardware>
> </constraints>

> Without baselibs.conf, two arch flavors will be built:
> x86_64 and x86_x6_v3. So I would think if you want to use flavors, you'd
> need to add:
> #!BuildTarget: x86_64_v3-linux
> #!BuildConstraint: hardware:cpu:flag x86-64-v3
> to the spec file in the -v3 flavor on x86_64. 

Yes, this is true. I have been only trying this out on my local machine (which supports x86-64-v3) but for a final version for OBS, my plan is to include a _constraints file to do this as documented here (or, equivalently, add the comments to specfile as you have noted):
<https://openbuildservice.org/help/manuals/obs-user-guide/cha.obs.build_constraints#id-1.5.10.16.8.6.3.3>

> When using baselibs.conf for
> -v3,  mkbaselibs will create a spec file which consumes these packages and
> 'repackages them into the main architecture'. You may need to do all this
> manually.
> I'm currently trying to figure out how all this works.

Same here: home:badshah400:lapackv3 is an early experiment about using flavours to generate the -v3 libs. Not (yet) ready for prime time :) Thanks for your reviews/advice.

Side note: I also learnt that RPM natively supports generating actual x86_64_v3 arch packages since version 4.19.0 (i.e. already in Factory). Perhaps we can have a look at how it does so:
<https://github.com/rpm-software-management/rpm/commit/cd46c1704ccd8eeb9b600729a0a1c8738b66b847>