ORIGIN-based runpaths in Bison

Jeffrey Walton <[email protected]>
Newsgroups gmane.comp.parsers.bison.bugs
Message-ID <CAH8yC8=351b_y5HiZD06OYLifZSW1yAGta9Ww_FZmV2OOM0RTQ@mail.gmail.com>
Hi Everyone/Akim,

I noticed Bison does not handle ORIGIN-based rpaths and runpaths properly.

Here's a test case you can use:

    CFLAGS="-I/usr/local/include"
    LDFLAGS="-L/usr/local/lib -Wl,-R,'$ORIGIN/../lib'
-Wl,--enable-new-dtags -Wl,-z,origin"
    export CFLAGS LDFLAGS
    ./configure ...

After building an executable or a lib, perform the following to see if
it is munged:

    readelf -d <file> | grep -E 'RPATH|RUNPATH'

The '$' should be intact:

    readelf -d /usr/local/bin/openssl | grep -E 'RPATH|RUNPATH'
    ... Library runpath: [$ORIGIN/../lib]

In general, one of the munges is the "$O" in "$ORIGIN" will be
interpreted as a make variable. I have seen this with Bison, too. You
will see:

    readelf -d /usr/local/bin/openssl | grep -E 'RPATH|RUNPATH'
    ... Library runpath: [RIGIN/../lib]

Another munge I have seen is a number getting added to the rpath or
runpath. I have _not_ seen this with Bison. I'm not sure where the
number comes from, but I believe it has to do with using a slash to
[try] preserve the dollar sign in the makefile.

    readelf -d /usr/local/bin/openssl | grep -E 'RPATH|RUNPATH'
    ... Library runpath: [312946ORIGIN/../lib]

Or maybe:

    readelf -d /usr/local/bin/openssl | grep -E 'RPATH|RUNPATH'
    ... Library runpath: [312946$ORIGIN/../lib]

Getting '$ORIGIN/../lib' to pass through configure and the makefile is
tricky. During configure, the '$' is not escaped and you use
'$ORIGIN/../lib'. Otherwise you fail feature tests. During make, '$'
needs to be escaped so you need '$$ORIGIN/../lib' written in the
makefile. Otherwise compilation fails or the runpath gets munged.

ORIGIN-based rpaths (without --enable-new-dtags) and runpaths (with
--enable-new-dtags) are actually covered in the ld(1) man page. There
are three special tokens recognized by ld - $ORIGIN, $LIB and
$PLATFORM. Also see https://man7.org/linux/man-pages/man1/ld.1.html.

Jeff
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.