Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 664100 - sys-apps/portage: QA Notice needed for rpath containing bad substitution like $$ORIGIN
Summary: sys-apps/portage: QA Notice needed for rpath containing bad substitution like...
Status: RESOLVED OBSOLETE
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Unclassified (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
URL: https://github.com/gentoo/gentoo/pull...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-20 09:41 UTC by David Hallas
Modified: 2023-10-27 10:07 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Hallas 2018-08-20 09:41:03 UTC
Portage outputs several bad substitution errors:

/var/db/pkg/dev-cpp/sourcetrail-2018.3.13/NEEDED.ELF.2: $: bad substitution
/var/db/pkg/dev-cpp/sourcetrail-2018.3.13/NEEDED.ELF.2: $: bad substitution

This seems to be the same root cause as the following bug reports:

#547520
#542796

But both bugs where closed stating that this is fixed in portage-2.2.19, but I am running portage-2.3.40-r1 and still see the problem.

I have run into this issue while writing an ebuild for a binary package called Sourcetrail, see https://github.com/gentoo/gentoo/pull/9513 for details. In the ebuild I have used the workaround suggested in one of the bug reports above, but mgorny suggested to report this as a Portage bug, so here we go :)


Reproducible: Always
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2018-08-20 11:21:57 UTC
Long story short, rpath contains $$ORIGIN (in addition to $ORIGIN).
Comment 2 Zac Medico gentoo-dev 2018-08-20 16:20:37 UTC
It seems that $$ORIGIN is not resolved by ldd either. Test case with /opt/firefox/libxul.so from firefox-bin:

> # cp -a /opt/firefox/libxul.so /opt/firefox/libxul_.so
> # ldd /opt/firefox/libxul_.so | grep 'not found'
> /opt/firefox/libxul_.so: /usr/lib64/libnss3.so: version `NSS_3.30' not found (required by /opt/firefox/libxul_.so)
> 	libmozsandbox.so => not found
> 	liblgpllibs.so => not found
> 	libmozsqlite3.so => not found
> 	libmozgtk.so => not found
> # patchelf --set-rpath '$$ORIGIN' /opt/firefox/libxul_.so
> # ldd /opt/firefox/libxul_.so | grep 'not found'
> /opt/firefox/libxul_.so: /usr/lib64/libnss3.so: version `NSS_3.30' not found (required by /opt/firefox/libxul_.so)
> 	libmozsandbox.so => not found
> 	liblgpllibs.so => not found
> 	libmozsqlite3.so => not found
> 	libmozgtk.so => not found
> # patchelf --set-rpath '$ORIGIN' /opt/firefox/libxul_.so
> # ldd /opt/firefox/libxul_.so | grep 'not found'

So $ORIGIN works with ldd, while $$ORIGIN does not. Portage behavior is consistent with ldd.
Comment 3 Zac Medico gentoo-dev 2018-08-20 16:30:35 UTC
(In reply to David Hallas from comment #0)
> I have run into this issue while writing an ebuild for a binary package
> called Sourcetrail, see https://github.com/gentoo/gentoo/pull/9513 for
> details. In the ebuild I have used the workaround suggested in one of the
> bug reports above, but mgorny suggested to report this as a Portage bug, so
> here we go :)

The portage "bad substitution" message is valid and useful. You probably want the Sourcetrail ebuild to use patchelf as described in bug 542796, comment 41.
Comment 4 Zac Medico gentoo-dev 2018-08-20 17:42:21 UTC
It would be nice to trigger a QA Notice for cases like this.
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2018-08-20 18:02:22 UTC
No, it wouldn't.  There's no point in editing a lot of prebuilt files for the sake of removing harmless '$$ORIGIN'.
Comment 6 Zac Medico gentoo-dev 2018-08-20 18:10:17 UTC
Portage uses $ORIGIN to resolve library dependencies for preserve-libs, so if the rpath contains $$ORIGIN instead then it can lead to inappropriately preserved libraries.
Comment 7 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2018-08-20 18:11:02 UTC
Not if it contains both $ORIGIN and $$ORIGIN, as it the result of working around buggy CMake behavior.
Comment 8 Zac Medico gentoo-dev 2018-08-20 18:14:58 UTC
Okay, so we can silence the "bad substitution" warning for $$ORIGIN if rpath also contains $ORIGIN.
Comment 9 Zac Medico gentoo-dev 2018-08-21 03:54:42 UTC
<[Arfrever]> zmedico: Re $ORIGIN : libc supports also $LIB (e.g. "lib" or "lib64") and $PLATFORM, but they are not expanded in Portage.
Comment 10 Zac Medico gentoo-dev 2018-08-21 04:01:56 UTC
(In reply to Zac Medico from comment #9)
> <[Arfrever]> zmedico: Re $ORIGIN : libc supports also $LIB (e.g. "lib" or
> "lib64") and $PLATFORM, but they are not expanded in Portage.

They're documented in the ld.so man page. Also see:

https://sourceware.org/bugzilla/show_bug.cgi?id=4177

http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#shobj_dependencies
Comment 11 David Hallas 2018-08-24 10:33:02 UTC
Is there any update on this?

Can I help out in anyway?

If you throw me some pointers I don't mind trying to fix this in portage, but I have never done portage changes before so I would need some guidance :)

I guess I should keep the patchelf workaround in the ebuild for now?

BTW: Here is the original rpath from the Sourcetrail binary:

patchelf --print-rpath Sourcetrail
$ORIGIN/lib/:$$ORIGIN/lib/:/opt/llvm/lib:/opt/boost/lib:/opt/qt5.10.1/lib
Comment 12 Zac Medico gentoo-dev 2018-08-24 10:55:09 UTC
How about something like this:

> diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
> index 34492e086..c131408ac 100755
> --- a/bin/misc-functions.sh
> +++ b/bin/misc-functions.sh
> @@ -245,2 +245,3 @@ install_qa_check() {
>                         needed=${l%%;*}; l=${l#*;}
> +                       needed=${needed//\$\$ORIGIN/\$ORIGIN}
>                         echo "${obj} ${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED^
Comment 13 David Hallas 2018-08-24 11:56:32 UTC
Hi Zac,

thanks for the quick turn-around :D

Your quick fix almost worked, it seems like this information ends up in the rpath variable and not the needed variable, so if I simply do

rpath=${rpath//\$\$ORIGIN/\$ORIGIN}

then the bad substitution error goes away. So would this be the way to fix this? If you want you can pull the ebuild from the pull request and play around with it, then can see what exactly ends up in the NEEDED.ELF.2 file. Or I can attach some before and after dumps if needed.
Comment 14 Arfrever Frehtes Taifersar Arahesis 2018-08-26 22:29:30 UTC
Silencing "bad substitution" warning is good idea (or better to replace it with a more informative warning).

However Portage should not record the corrected value of RPATH into NEEDED.ELF.2 when actually installed executables / libraries still have broken value of RPATH.
Comment 15 David Hallas 2023-10-27 10:07:42 UTC
Since SourceTrail was removed from Gentoo quite a while ago I am going to close this ticket.