-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[META] Using LLD as FreeBSD's system linker #23588
Comments
Do you have a list of missing features for this bug? |
There are the depends-on PRs:
I just closed #23409 as the change was reapplied with a fixed test case, but have found a new issue relating to dependency handling (no PR yet): link main.o -l -l, where libstatic.a depends on libshared.a. LLD reports an undefined symbol from libstatic.a. GNU ld accepts this. Arguably the link order ought to be changed around in our build, but other software will likely encounter this too. For the actual case in FreeBSD the static library was NTP - it builds a libntp.a that depends on libedit, and a binary linked with -ledit -lntp. I also observed one "error: unsupported emulation 'elf_i386_fbsd'." PRs for these two and other issues we find will be added as dependencies of this one. |
We also need linker script support, although I don't have a list of the specific linker script features we rely on just yet. |
Unknown arguments during world (userland) build: warning: ignoring unknown argument: --version-script=Version.map From FreeBSD arm64 kernel link: --- kernel.debug --- |
Note that this meta PR was created based on the first version of LLD ELF support, and needs to be revisited for elf2. |
Trying with ELF2 turned up the issues below; we're not yet at the point in ELF2's development where it makes sense to track individual PRs for them.
ELF2 currently rounds up to a page and stores the data for PT_INTERP Program Headers:
This is the FreeBSD __progname issue fixed in r218259 for the original
These are options that need to be ignored or implemented (excluding --enable-new-dtags
The FreeBSD base system linker scripts use (at least) the following set: (http://lists.llvm.org/pipermail/llvm-dev/2015-October/091072.html) |
--enable/disable-new-dtags is r249428 |
What kind of expressions are used in SECTIONS linker script directive? |
Examples can be found here: https://svnweb.freebsd.org/base/head/sys/conf/ Some examples: kernphys = CONSTANT (MAXPAGESIZE); .init : PROVIDE (__etext = .); .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); .preinit_array : . = ALIGN(. != 0 ? 64 / 8 : 1); .debug_pubtypes 0 : { *(.debug_pubtypes) } |
With the change in http://reviews.llvm.org/D13637 LLD can now link a FreeBSD "hello world." The current userland world build fails due to unhandled R_X86_64_TLSGD: --- libc.so.7 --- The kernel build fails in the linker script parser: --- kernel.full --- |
Michael Spencer is working on it -- there's an initial patch under review so that should be unlocked soon.
|
Update, With the WIP -r patch (http://reviews.llvm.org/D14382) linking static libpam produces a new error: $ ld -o openpam_static_modules.o -r --whole-archive openpam_static.o ../modules/pam_chroot/libpam_chroot.a ../modules/pam_deny/libpam_deny.a [...] If I'm able to investigate and produce a small reproduction case I will submit a new PR. Also, the lack of GNU symbol version support is now becoming a blocking issue for making further progress on FreeBSD - our libc has some cases where it is not usable without a symver-supporting linker. |
Do you keep track of the progress? I'm interested in the numbers of packages we can and can't link with lld (with test success). |
We're not yet at the point of trying to link the ports tree with lld -- I'm working on the base system now. After recent commits and the WIP -r patch I've been able to reduce the set of hacks in my build tree to a small handful:
For now I'm not trying to build the kernel with lld. |
If you can open individual bugs for each one that would be awesome :-) |
Unlike the recent PRs I've opened up I'm not convinced all of these are bugs (in lld):
The clang driver passes -L/usr/lib to ld and we expect to resolve -llib args from there; this issue only happens because /usr/lib/libc.so is a linker script that contains: GROUP ( libc.so.7 libc_nonshared.a libssp_nonshared.a ) I think it should probably be: GROUP ( /lib/libc.so.7 /usr/lib/libc_nonshared.a /usr/lib/libssp_nonshared.a )
This one indeed looks like an lld issue and I'll submit a PR once I have at least some detail.
-N should be easy to implement, but I'm not sure how useful or widely used it is, and it seems reasonable for us to rework our boot components to avoid it.
PR 26729
PR 26730
Will submit a PR referencing specific missing functionality
While I believe -r support is important in lld I'm not sure I can argue for this use, and will probably change the FreeBSD build to use objcopy instead. |
The set of workarounds I'm using to try building FreeBSD world with lld is in my github FreeBSD tree: https://github.com/emaste/freebsd/tree/lld-buildworld The major outstanding issue is lack of expression support in linker scripts - in my tree the kernel is being linked with ld.bfd for this reason. There are also a few other components that are disabled or linked with ld.bfd. I've built a VM image from this tree and large portions work; the system boots to a login prompt, shells work, clang works, etc. Anything linked against libxo (which includes ls and ps) segfaults - PR 26818. ps is used in many places in the startup scripts and thus results in a lot of console spam. Once PR 26818 is fixed I believe enough will be working that we can test lld in a FreeBSD ports experimental run, trying to build the ~25K third party software packages in the ports tree with lld. |
Thank you very much for the updates. Linker script is indeed the next big one (and hopefully the last one), but before start working on it, I'm trying to support versioned symbols. |
Great. For my immediate testing I'm building a full system w/o symver and the lack of support isn't holding me up -- I might have a couple of workarounds that I'll need to apply, but it's not a significant problem for buildworld (userland). Using a ld.bfd-linked kernel fine for testing. Indeed, versioned symbol support will be very important for us if we're to provide a /usr/bin/ld.lld, in order to interoperate with system components -- particularly libc.so -- linked by GNU ld. |
little note about:
That should be fixed in r262590. That message was shown becauses eh_frame sections were proccessed during generating relocatable output and from that revision it is not happens anymore as well as this adds support for generating relocations against local symbols which were sections in that case. |
In r262910, I add /usr and /usr/lib as default search paths. I think that should resolve one issue for FreeBSD. |
Changes have been committed to FreeBSD to address some of these issues:
I'm now starting to test FreeBSD/arm64 (AArch64) buildworld with lld. It currently fails when building libc: /usr/local/aarch64-freebsd/bin/ld: getutxent.So(.debug_info+0x3c): R_AARCH64_ABS64 used with TLS symbol udb Note that patches are open for arm64 TLS relocation work: http://reviews.llvm.org/D16201 |
So, just in case. We are not going to support -N, right ? (otherwise I would take that). |
Because -N option is for compatibility with old Unix systems that have died out in 80s or 90s. If you still want that behavior for some special case (such as bootloader or something), you should use a linker script instead. |
Yes, I assumed that I will be changing the FreeBSD build to implement what's needed via a linker script. I believe lld's linker script support is not yet fully able to implement -N's functionality and I will continue to link these components with GNU ld until it can. |
That's why I asked :) |
Attempting to link FreeBSD/mips64 with lld reports:
I do not yet know why there's an explicit big/little endian argument passed in by Clang. |
It looks like lib/Driver/Tools.cpp always produces -m elf{32,64}{bt,lt}smip flags, so maybe -EB/EL are just redundant? |
Yes, I'm having trouble imagining how -EB/-EL could be used, where endianness is not already determined by either -m or the object file(s). For testing I've just added -EB and -EL as ignored options. |
Moving to "ELF" bugzilla component (instead of generic "All Bugs" for LLD). |
Extended Description
This is a meta-bug to track dependencies needed for LLD to be functional as FreeBSD's system linker.
The text was updated successfully, but these errors were encountered: