Bug 54015 - ld(1) requires "-z origin" when "-rpath" contains $ORIGIN
Summary: ld(1) requires "-z origin" when "-rpath" contains $ORIGIN
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: Other FreeBSD
: medium normal
Assignee: Jung-uk Kim
QA Contact:
URL:
Whiteboard: target:3.7.0
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-24 16:13 UTC by Jung-uk Kim
Modified: 2012-08-30 07:47 UTC (History)
1 user (show)

See Also:


Attachments
Set LD_LIBRARY_PATH for uno_test. (473 bytes, patch)
2012-08-24 16:13 UTC, Jung-uk Kim
Details
Replace -Wl,-rpath with -Wl,-z,origin,-rpath (15.34 KB, patch)
2012-08-29 00:38 UTC, Jung-uk Kim
Details
Fix seamonkey patch. (667 bytes, patch)
2012-08-29 18:03 UTC, Jung-uk Kim
Details
"-Wl,-z,origin -Wl,-rpath," -> "-Wl,-z,origin,-rpath," (663 bytes, patch)
2012-08-29 22:37 UTC, Jung-uk Kim
Details
Patch against head. (14.28 KB, patch)
2012-08-29 23:14 UTC, Jung-uk Kim
Details
Patch against head (with seamonkey patch). (14.78 KB, patch)
2012-08-29 23:19 UTC, Jung-uk Kim
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jung-uk Kim 2012-08-24 16:13:06 UTC
Created attachment 66072 [details]
Set LD_LIBRARY_PATH for uno_test.

I had a build failure related uno, at least for FreeBSD.  It turned out LD_LIBRARY_PATH wasn't set and it failed to load required libraries for uno binary.  It was successfully built with the attached patch.
Comment 1 Stephan Bergmann 2012-08-27 11:33:35 UTC
so FreeBSD still has nothing similar to Linux/Solaris' ELF RPATH=$ORIGIN/... etc., but solely relies on LD_LIBRARY_PATH to find LO's libs?
Comment 2 Jung-uk Kim 2012-08-27 16:56:18 UTC
$ORIGIN is available for about 3 years:

http://svnweb.freebsd.org/base?view=revision&revision=189959

In fact, I am not really sure why this patch is still necessary.  I'll try to reproduce the problem without the patch and let you know the detail.
Comment 3 Jung-uk Kim 2012-08-27 22:33:47 UTC
Okay, I found the root cause of this problem:

% cat main.c
void    hello(void);

int
main(void)
{

        hello();
        return (0);
}
% cat lib/hello.c
#include <stdio.h>

void
hello(void)
{

        printf("Hello, world!\n");
}
% make clean
rm -f lib/libhello.so main
% make
cc -fPIC -shared -o lib/libhello.so lib/hello.c
cc  -Wl,-rpath='$ORIGIN/lib' -Llib -lhello -o main main.c
% ./main
Shared object "libhello.so" not found, required by "main"
% make clean
rm -f lib/libhello.so main
% make LDFLAGS=-Wl,-zorigin
cc -fPIC -shared -o lib/libhello.so lib/hello.c
cc -Wl,-zorigin -Wl,-rpath='$ORIGIN/lib' -Llib -lhello -o main main.c
% ./main
Hello, world!

FreeBSD ld must have "-zorigin" with "-rpath".  Otherwise, $ORIGIN is not translated and it is literal.
Comment 4 Jung-uk Kim 2012-08-28 06:27:51 UTC
To confirm, I did the following before start building:

find . -type f -print0 | \
xargs -0 sed -i '' -e 's#-Wl,-rpath,#-Wl,-z,origin,-rpath,#g'

Now "objdump -p uno" or "readelf --dynamic uno" shows the flag is set correctly.
Comment 5 Stephan Bergmann 2012-08-28 08:17:23 UTC
(In reply to comment #3)
> FreeBSD ld must have "-zorigin" with "-rpath".  Otherwise, $ORIGIN is not
> translated and it is literal.

So the true fix for LO will be to add -zorigin in solenv/{inc,gbuild} for FreeBSD, right?  Will you create a new patch?
Comment 6 Jung-uk Kim 2012-08-28 18:51:51 UTC
(In reply to comment #5)
> (In reply to comment #3)
> > FreeBSD ld must have "-zorigin" with "-rpath".  Otherwise, $ORIGIN is not
> > translated and it is literal.
> 
> So the true fix for LO will be to add -zorigin in solenv/{inc,gbuild} for
> FreeBSD, right?  Will you create a new patch?

It looks like the option is standard option for GNU ld:

http://sourceware.org/binutils/docs-2.22/ld/Options.html#Options

Can't we make that a default for GCC?  Not sure about MinGW, though.
Comment 7 Jung-uk Kim 2012-08-29 00:38:28 UTC
Created attachment 66254 [details]
Replace -Wl,-rpath with -Wl,-z,origin,-rpath

Third-party modules are not thoroughly tested.
Comment 8 Not Assigned 2012-08-29 10:08:39 UTC
Jung-uk Kim committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=34ca8dd9adb62c1154f979887a38483d73da978b

fdo#54015: At least FreeBSD ld requires -z origin when RPATH contains $ORIGIN
Comment 9 Stephan Bergmann 2012-08-29 10:17:24 UTC
<http://cgit.freedesktop.org/libreoffice/core/commit/?id=34ca8dd9adb62c1154f979887a38483d73da978b>:

Signed-off-by: Stephan Bergmann <sbergman@redhat.com>:
* bulk replacement of "-Wl,-z,origin,-rpath,..." with "-Wl,-z,origin -Wl,rpath,..."
* additional hunk for directory/c-sdk/config/FreeBSD.mk in moz/seamonkey-source-1.1.14.patch did not apply and has been dropped

@Jung-uk Kim:  Please either provide a working patch for FreeBSD moz, or close as RESOLVED/FIXED for now.
Comment 10 Jung-uk Kim 2012-08-29 17:39:37 UTC
It looks correct, thanks!
Comment 11 Jung-uk Kim 2012-08-29 18:03:05 UTC
Created attachment 66284 [details]
Fix seamonkey patch.
Comment 12 Jung-uk Kim 2012-08-29 18:04:51 UTC
Sorry, I found the patch was for security/coreconf/FreeBSD.mk.  I have no idea why the hunk was misplaced, though. :-(
Comment 13 Jung-uk Kim 2012-08-29 22:13:50 UTC
Another problem...  '-Wl,-z,origin -Wl,-rpath' is parsed badly, at least for clang on FreeBSD.  For example,

[ build LNK ] Executable/regcompare
/usr/local/bin/ld: warning: -z origin -Wl ignored.

In other words, '-z origin -Wl' is passed to ld(1) and it does not work at all.

% solver/unxfbsd.pro/bin/regcompare
Shared object "libuno_sal.so.3" not found, required by "regcompare"
% env LD_LIBRARY_PATH=solver/unxfbsd.pro/lib solver/unxfbsd.pro/bin/regcompare
solver/unxfbsd.pro/bin/regcompare: missing option '-r1'
Usage: solver/unxfbsd.pro/bin/regcompare -r1<filename> -r2<filename> [-options] | @<filename>
    -r1<filename>  = filename specifies the name of the first registry.
    -r2<filename>  = filename specifies the name of the second registry.
    @<filename>    = filename specifies a command file.
Options:
    -s<name>  = name specifies the name of a start key. If no start key
     |S<name>   is specified the comparison starts with the root key.
    -x<name>  = name specifies the name of a key which won't be compared. All
     |X<name>   subkeys won't be compared also. This option can be used more than once.
    -f|F      = force the detailed output of any diffenrences. Default
                is that only the number of differences is returned.
    -c|C      = make a complete check, that means any differences will be
                detected. Default is only a compatibility check that means
                only UNO typelibrary entries will be checked.
    -t|T      = make an UNO type compatiblity check. This means that registry 2
                will be checked against registry 1. If a interface in r2 contains
                more methods or the methods are in a different order as in r1, r2 is
                incompatible to r1. But if a service in r2 supports more properties as
                in r1 and the new properties are 'optional' it is compatible.
    -u|U      = additionally check types that are unpublished in registry 1.
    -h|-?     = print this help message and exit.

solver/unxfbsd.pro/bin/regcompare Version 1.0

FYI, full build log is available from here:

https://redports.org/~jkim/20120829180932-76536-56265/libreoffice-3.6.0.log

Can you please do "-Wl,-z,origin,-rpath" as I did originally?

Thanks!
Comment 14 Jung-uk Kim 2012-08-29 22:37:34 UTC
Created attachment 66303 [details]
"-Wl,-z,origin -Wl,-rpath," -> "-Wl,-z,origin,-rpath,"
Comment 15 Jung-uk Kim 2012-08-29 23:14:03 UTC
Created attachment 66304 [details]
Patch against head.
Comment 16 Jung-uk Kim 2012-08-29 23:19:35 UTC
Created attachment 66305 [details]
Patch against head (with seamonkey patch).
Comment 17 Stephan Bergmann 2012-08-30 07:22:03 UTC
(In reply to comment #13)
> Another problem...  '-Wl,-z,origin -Wl,-rpath' is parsed badly, at least for
> clang on FreeBSD.

Also for Ubuntu Oneiric, it turned out, so I already fixed that independently as <http://cgit.freedesktop.org/libreoffice/core/commit/?id=b888512fcbff5bf5ae4d30e82ed51a792ceb1839> "Fix -Wl,-z,origin -Wl,-rpath,... quoting" before noticing your patch here.

> Can you please do "-Wl,-z,origin,-rpath" as I did originally?

I prefer to keep it as two -Wl, as it is two independent (though related) options that are passed to the linker.
Comment 18 Not Assigned 2012-08-30 07:42:14 UTC
Jung-uk Kim committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=78d8557aab0046d51d1ee09d11164248dd1d1391

fdo#54015: At least FreeBSD ld requires -z origin, moz redux
Comment 19 Stephan Bergmann 2012-08-30 07:47:01 UTC
Comment on attachment 66305 [details]
Patch against head (with seamonkey patch).

attachment 66305 [details] is now obsoleted via comment 17 and comment 18