Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 690322 - sys-libs/pam[-split-usr] creates broken symlinks in /lib
Summary: sys-libs/pam[-split-usr] creates broken symlinks in /lib
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Mikle Kolyada (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: usrmerge, usrmerge-fixes
  Show dependency tree
 
Reported: 2019-07-20 23:39 UTC by Garry Filakhtov
Modified: 2019-08-16 11:26 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
ebuild patch (pam.patch,376 bytes, text/plain)
2019-07-21 00:41 UTC, Alexander Tsoy
Details
Patch (pam.patch,1.27 KB, patch)
2019-08-15 00:09 UTC, Arfrever Frehtes Taifersar Arahesis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Garry Filakhtov 2019-07-20 23:39:45 UTC
Installing the sys-libs/pam package with the split-usr flag disabled produces broken symlinks inside of the /lib(64) directory:

$ ls -la /lib64/libpam*
lrwxrwxrwx 1 root root 12 Jul 21 09:33 /lib64/libpamc.so -> libpamc.so.0
lrwxrwxrwx 1 root root 16 Jul 21 09:33 /lib64/libpam_misc.so -> libpam_misc.so.0
lrwxrwxrwx 1 root root 11 Jul 21 09:33 /lib64/libpam.so -> libpam.so.0

the /usr/lib(64) directory, in contrast, has all symlinks properly set-up:

$ ls -la /usr/lib64/libpam*
lrwxrwxrwx 1 root root    17 Jul 21 09:33 /usr/lib64/libpamc.so -> libpamc.so.0.82.1
lrwxrwxrwx 1 root root    17 Jul 21 09:33 /usr/lib64/libpamc.so.0 -> libpamc.so.0.82.1
-rwxr-xr-x 1 root root 14464 Jul 21 09:33 /usr/lib64/libpamc.so.0.82.1
lrwxrwxrwx 1 root root    21 Jul 21 09:33 /usr/lib64/libpam_misc.so -> libpam_misc.so.0.82.1
lrwxrwxrwx 1 root root    21 Jul 21 09:33 /usr/lib64/libpam_misc.so.0 -> libpam_misc.so.0.82.1
-rwxr-xr-x 1 root root 14456 Jul 21 09:33 /usr/lib64/libpam_misc.so.0.82.1
lrwxrwxrwx 1 root root    16 Jul 21 09:33 /usr/lib64/libpam.so -> libpam.so.0.84.2
lrwxrwxrwx 1 root root    16 Jul 21 09:33 /usr/lib64/libpam.so.0 -> libpam.so.0.84.2
-rwxr-xr-x 1 root root 55832 Jul 21 09:33 /usr/lib64/libpam.so.0.84.2
Comment 1 Garry Filakhtov 2019-07-20 23:48:30 UTC
Apologies, that report is misleading. Under further investigation I realized that libraries come from sys-libs/e2fsprogs-libs, so the problem is that split-usr flag should be synchronized between these two packages.
Comment 2 Garry Filakhtov 2019-07-20 23:50:16 UTC
Sorry above message is meant for a different bug report.
Comment 3 Alexander Tsoy 2019-07-21 00:02:00 UTC
I also noticed this when migrating to merged /usr layout.
Comment 4 Alexander Tsoy 2019-07-21 00:41:34 UTC
Created attachment 583812 [details]
ebuild patch
Comment 5 Arfrever Frehtes Taifersar Arahesis 2019-07-22 08:22:29 UTC
Patch from comment #4 does not look like an optimal solution.

Most of code in multilib_src_install() is unnecessary.

Build system already installs libpam.so, libpam_misc.so, libpamc.so symlinks.

gen_usr_ldscript() already internally calls multilib_is_native_abi() and does nothing for non-native ABIs.

I suggest:

--- pam-1.3.1-r1.ebuild
+++ pam-1.3.1-r1.ebuild
@@ -80,23 +80,9 @@
 multilib_src_install() {
        emake DESTDIR="${D}" install \
                sepermitlockdir="${EPREFIX}/run/sepermit"
 
-       local prefix
-       if multilib_is_native_abi; then
-               prefix=
-               gen_usr_ldscript -a pam pamc pam_misc
-       else
-               prefix=/usr
-       fi
-
-       # create extra symlinks just in case something depends on them...
-       local lib
-       for lib in pam pamc pam_misc; do
-               if ! [[ -f "${ED}"${prefix}/$(get_libdir)/lib${lib}$(get_libname) ]]; then
-                       dosym lib${lib}$(get_libname 0) ${prefix}/$(get_libdir)/lib${lib}$(get_libname)
-               fi
-       done
+       gen_usr_ldscript -a pam pam_misc pamc
 }
 
 multilib_src_install_all() {
        find "${ED}" -type f -name '*.la' -delete || die
Comment 6 Alexander Tsoy 2019-07-22 08:54:05 UTC
(In reply to Arfrever Frehtes Taifersar Arahesis from comment #5)
Yes, bet the whole point of this code (In reply to Arfrever Frehtes Taifersar Arahesis from comment #5)
> Patch from comment #4 does not look like an optimal solution.
> 
> Most of code in multilib_src_install() is unnecessary.
> 
> Build system already installs libpam.so, libpam_misc.so, libpamc.so symlinks.
*.so symlinks are removed by gen_usr_ldscript(), that's why I didn't remove that code. See this comment:
>     # create extra symlinks just in case something depends on them...
Though I'm not sure they are really needed.
Comment 7 Arfrever Frehtes Taifersar Arahesis 2019-07-22 10:24:34 UTC
(In reply to Alexander Tsoy from comment #6)
> (In reply to Arfrever Frehtes Taifersar Arahesis from comment #5)
> Yes, bet the whole point of this code (In reply to Arfrever Frehtes
> Taifersar Arahesis from comment #5)
> > Patch from comment #4 does not look like an optimal solution.
> > 
> > Most of code in multilib_src_install() is unnecessary.
> > 
> > Build system already installs libpam.so, libpam_misc.so, libpamc.so symlinks.
> *.so symlinks are removed by gen_usr_ldscript(), that's why I didn't remove
> that code. See this comment:
> >     # create extra symlinks just in case something depends on them...
> Though I'm not sure they are really needed.

For non-native ABIs gen_usr_ldscript() does not delete anything, does not create anything, does not move anything.

For native ABI gen_usr_ldscript():
- Moves actual library (e.g. "libpam.so.0.84.2") and soname-versioned symlink (e.g. "libpam.so.0") from /usr/lib(64) to /lib(64)
- Replaces unversioned symlink (e.g. "libpam.so") in /usr/lib(64) with linker script

Either symlink to actual library, or linker script (with correct "GROUP ( /path/to/library )" line) is sufficient for linker.

When -lpam is passed to linker, then linker searches for "libpam.so" and "libpam.a", but not e.g. "libpam.so.0".
(Passing -l:libpam.so.0 would result in searching explicitlly for "libpam.so.0".)
Linker reads soname of library (e.g. "libpam.so.0") and hardcodes it in NEEDED section of created file.

At run time, ld.so searches for file which matches entry in NEEDED section (e.g. "libpam.so.0", not "libpam.so").
"libpam.so" is not used at run time.
Comment 8 Arfrever Frehtes Taifersar Arahesis 2019-07-23 03:47:36 UTC
(In reply to Arfrever Frehtes Taifersar Arahesis from comment #7)
> For non-native ABIs gen_usr_ldscript() does not delete anything, does not
> create anything, does not move anything.
> 
> For native ABI gen_usr_ldscript():
> - Moves actual library (e.g. "libpam.so.0.84.2") and soname-versioned
> symlink (e.g. "libpam.so.0") from /usr/lib(64) to /lib(64)
> - Replaces unversioned symlink (e.g. "libpam.so") in /usr/lib(64) with
> linker script

Maybe I should have also mentioned that gen_usr_ldscript() does not do anything also when USE="-split-usr" is used:
https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=cc8063d4318a6594ac8ae94e99c2a6fe484198bd

So a 'use split-usr' check in ebuild is not needed before calling gen_usr_ldscript().
Comment 9 Mikle Kolyada (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2019-08-01 10:49:43 UTC
(In reply to Arfrever Frehtes Taifersar Arahesis from comment #7)
> (In reply to Alexander Tsoy from comment #6)
> > (In reply to Arfrever Frehtes Taifersar Arahesis from comment #5)
> > Yes, bet the whole point of this code (In reply to Arfrever Frehtes
> > Taifersar Arahesis from comment #5)
> > > Patch from comment #4 does not look like an optimal solution.
> > > 
> > > Most of code in multilib_src_install() is unnecessary.
> > > 
> > > Build system already installs libpam.so, libpam_misc.so, libpamc.so symlinks.
> > *.so symlinks are removed by gen_usr_ldscript(), that's why I didn't remove
> > that code. See this comment:
> > >     # create extra symlinks just in case something depends on them...
> > Though I'm not sure they are really needed.
> 
> For non-native ABIs gen_usr_ldscript() does not delete anything, does not
> create anything, does not move anything.
> 
> For native ABI gen_usr_ldscript():
> - Moves actual library (e.g. "libpam.so.0.84.2") and soname-versioned
> symlink (e.g. "libpam.so.0") from /usr/lib(64) to /lib(64)
> - Replaces unversioned symlink (e.g. "libpam.so") in /usr/lib(64) with
> linker script
> 
> Either symlink to actual library, or linker script (with correct "GROUP (
> /path/to/library )" line) is sufficient for linker.
> 
> When -lpam is passed to linker, then linker searches for "libpam.so" and
> "libpam.a", but not e.g. "libpam.so.0".
> (Passing -l:libpam.so.0 would result in searching explicitlly for
> "libpam.so.0".)
> Linker reads soname of library (e.g. "libpam.so.0") and hardcodes it in
> NEEDED section of created file.
> 
> At run time, ld.so searches for file which matches entry in NEEDED section
> (e.g. "libpam.so.0", not "libpam.so").
> "libpam.so" is not used at run time.

Well, symlinks these days are not needed just because SONAME is a major one field during linking, which is '.0' in anyway.
Comment 10 Arfrever Frehtes Taifersar Arahesis 2019-08-01 19:59:54 UTC
(In reply to Mikle Kolyada from comment #9)

Your comment is unclear about whether you have understood what I had said, so I will add more explanation.

soname != filename
soname and filename of a library are independent of each other, and neither of them needs to be a subset or a superset of the other one.
soname is searched for only at run time (by ld.so).

A library called "libA.so" in filesystem can have soname = "libB.so".
This just means that a "libB.so" needs to exist somewhere at run time.
(Potentially it can be a symlink to "libA.so".)

$ cd /tmp
$ gcc -shared -fPIC -Wl,--soname,libB.so -o libA.so -x c - </dev/null
$ scanelf --soname libA.so
 TYPE   SONAME FILE 
ET_DYN libB.so libA.so 
$ gcc -o test -x c - <<< "int main(){}" -Wl,-rpath,. -L. -lA
$ scanelf --needed test
 TYPE   NEEDED FILE 
ET_DYN libB.so,libc.so.6 test
$ ./test
./test: error while loading shared libraries: libB.so: cannot open shared object file: No such file or directory
$ ln -s libA.so libB.so
$ ./test
$
Comment 11 Mikle Kolyada (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2019-08-01 20:03:29 UTC
(In reply to Arfrever Frehtes Taifersar Arahesis from comment #10)
> (In reply to Mikle Kolyada from comment #9)
> 
> Your comment is unclear about whether you have understood what I had said,
> so I will add more explanation.
> 
> soname != filename
> soname and filename of a library are independent of each other, and neither
> of them needs to be a subset or a superset of the other one.
> soname is searched for only at run time (by ld.so).
> 
> A library called "libA.so" in filesystem can have soname = "libB.so".
> This just means that a "libB.so" needs to exist somewhere at run time.
> (Potentially it can be a symlink to "libA.so".)
> 
> $ cd /tmp
> $ gcc -shared -fPIC -Wl,--soname,libB.so -o libA.so -x c - </dev/null
> $ scanelf --soname libA.so
>  TYPE   SONAME FILE 
> ET_DYN libB.so libA.so 
> $ gcc -o test -x c - <<< "int main(){}" -Wl,-rpath,. -L. -lA
> $ scanelf --needed test
>  TYPE   NEEDED FILE 
> ET_DYN libB.so,libc.so.6 test
> $ ./test
> ./test: error while loading shared libraries: libB.so: cannot open shared
> object file: No such file or directory
> $ ln -s libA.so libB.so
> $ ./test
> $

I know what soname is, there is no need to waste everybody's time with this offtopic (in the scope of this bug).
Comment 12 Arfrever Frehtes Taifersar Arahesis 2019-08-15 00:09:47 UTC
Created attachment 586804 [details, diff]
Patch
Comment 13 Larry the Git Cow gentoo-dev 2019-08-16 11:25:11 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9b8c9d3b0871206e6f6f984213c493efadea297a

commit 9b8c9d3b0871206e6f6f984213c493efadea297a
Author:     Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
AuthorDate: 2019-08-15 00:06:27 +0000
Commit:     Mikle Kolyada <zlogene@gentoo.org>
CommitDate: 2019-08-16 11:25:08 +0000

    sys-libs/pam: Drop unnecessary code for creation of symlinks.
    
    Closes: https://bugs.gentoo.org/690322
    Signed-off-by: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
    Signed-off-by: Mikle Kolyada <zlogene@gentoo.org>

 sys-libs/pam/pam-1.3.1-r1.ebuild | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)
Comment 14 Mikle Kolyada (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2019-08-16 11:26:49 UTC
But next time please use either 'Bug:' or 'Closes:', not 'Fixes:' (I've corrected this on the way).