Bug 207980 - /usr/lib/libc.so not compatible with lld due to path stripping
Summary: /usr/lib/libc.so not compatible with lld due to path stripping
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL: https://reviews.freebsd.org/D5637
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-14 16:03 UTC by Ed Maste
Modified: 2016-03-15 22:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2016-03-14 16:03:25 UTC
/usr/lib/libc.so is a linker script that used to contain:
GROUP ( /lib/libc.so.7 /usr/lib/libc_nonshared.a /usr/lib/libssp_nonshared.a )

In r266227 /usr/lib/libc.so was changed to avoid including full paths:
GROUP ( libc.so.7 libc_nonshared.a libssp_nonshared.a )

Using lld (LLVM's linker) on FreeBSD fails due to this, as it does not have built-in search paths and relies on the compiler driver to pass in the expected paths via -L arguments. Clang currently passes only -L /usr/lib, as this is the only path that "should" be required at link time.

We may be able to restore the paths and use the --sysroot argument to ld.
Comment 1 Ed Maste freebsd_committer freebsd_triage 2016-03-14 18:01:05 UTC
Most recent buildworld-with-lld attempt was reported here: http://lists.llvm.org/pipermail/llvm-dev/2016-March/096449.html

> 3. Library search paths
>
> In FreeBSD /usr/lib/libc.so is a linker script that contains
> "GROUP ( libc.so.7 libc_nonshared.a libssp_nonshared.a )". ld.bfd
> includes a built-in /lib search path and finds /lib/libc.so.7 there.
> lld relies only on the -L paths specified on the command line, and
> cannot locate libc.so.7. As a workaround I've changed /usr/lib/libc.so
> to include the full path.
Comment 2 commit-hook freebsd_committer freebsd_triage 2016-03-15 22:27:46 UTC
A commit references this bug:

Author: bdrewery
Date: Tue Mar 15 22:27:30 UTC 2016
New revision: 296921
URL: https://svnweb.freebsd.org/changeset/base/296921

Log:
  Partially revert r266227 and stop stripping paths in ldscripts.

  Specifically this fixes /usr/lib/libc.so stripping the paths to the
  libraries.  The reason for this in r266227 was both likely because ld(1) did
  not fully respect --sysroot until r291226 and because of the lib32
  build.  The lib32 build does not use --sysroot into the /usr/lib32 path,
  rather it only uses -L and -B into the /usr/lib32 path and --sysroot
  into the normal (64bit) /usr/lib.  The _LDSCRIPTROOT was added with
  the ldscript support in bsd.lib.mk so that it builds a 32-bit-sysrooted pathed
  ldscript in the object directory and then installs a normal unprefixed
  version in installworld.  This commit also fixes the rebuild during
  install which was broken in r266227.  This commit would break DIRDEPS_BUILD
  build of lib32 but it does not currently have a way to build it anyhow.

  For example, before this change we had in /usr/lib/libc.so:
    GROUP ( libc.so.7 libc_nonshared.a libssp_nonshared.a )
  Now it is restored to pre-r266227:
    GROUP ( /lib/libc.so.7 /usr/lib/libc_nonshared.a /usr/lib/libssp_nonshared.a )

  The motivation for this is in testing of lld.
  From emaste:
    lld does not have built-in search paths (e.g. /lib, /usr/lib) and relies on
    -L arguments passed by the caller.  As the linker is nearly always invoked
    from the clang driver this is fine other than the fact that /usr/lib/libc.so
    is an ldscript that refers to libc.so.7 which is in /lib, not /usr/lib.

  PR:		207980
  Reported by:	emaste
  Submitted by:	emaste (based on)
  Differential Revision:	https://reviews.freebsd.org/D5637

Changes:
  head/share/mk/bsd.lib.mk
  head/share/mk/bsd.sys.mk