The NetBSD target wraps the default Linux/ELF target with OS specific
customization. It is implemented as a light nb.lld program that
mutates arguments in argv[] and spawns ld.lld.
This flavor detects the native/current and target Triple based on
argv[0] parsing. This is prerequisite for cross-compilation, in
particular the NetBSD distribution is cross-built always.
The default configuration of the ELF target is tuned for Linux and
there is no way to costomize in-place for the NetBSD target in the
same way as FreeBSD/OpenBSD. FreeBSD whenever needed can check
emulation name ("*_fbsd") and OpenBSD calls its extensions
"PT_OPENBSD_*".
This distinct flavor is needed for NetBSD as:
- the linker MUST work in the standalone mode
- it must be useful with gcc/pcc/others out of the box
- clang NetBSD driver shall not hardcode LLD specific options
- the linker must have support for cross-building
- LLD shall be a drop-in replacement for (NetBSD-patched) GNU ld
nb.lld calls internally ld.lld and there is no code-duplication
between nb.lld and ld.lld. There is no functional or code
maintenance change for other Operating Systems, especially the ELF
ones.
Equivalent customization is already done for the Darwin mode. For
instance there are hardcoded default search paths such as "/usr/lib"
and "/Library/Frameworks" in DarwinLdDriver.cpp.
This change is a starting point for development of NetBSD support
in LLD. This is also another approach to achieve the same goal as
mutating the default LLD/ELF target based on Triple, but in a
less invasive way as everything is moved out of LLD to nb.lld now.
You can't use DT_RUNPATH probably because the change Add support for DT_RUNPATH - it is just the same as we always have treated DT_RPATH. Approved by core. (2018-12-30) is still considered new. If you do this in clangDriver, you need a comment with a TODO about the migration process.