Blame | Last modification | View Log | Download | RSS feed
QNX 8.0 'gcc' linker driver drop-in replacement by Pierre-Marie Baty
RATIONALE
=========
Until a proper QNXToolchain class is implemented in the Clang driver, Clang
relies on GNU GCC to drive the system linker when it hasn't enough knowledge
of the underlying platform. So, if we are to provide a LLVM/Clang-based native
toolchain for QNX, we *HAVE* to provide a 'gcc' executable for Clang to be
able to link QNX files. This is an either/or situation and it was decided
that reimplementing an external linker driver would be faster than doing it
in the LLVM codebase (mostly because of the very long iteration times that
rebuilding LLVM causes, even when using a compiler cache.)
Why does Clang chain-call gcc with the intent of linking ? Because GNU GCC is
itself a 'driver' which can also invoke either a compiler or a linker ('gcc'
invokes 'collect2' which in turn invokes 'ld', the UNIX linker). This means
our drop-in GCC replacement will need to either chain-call 'clang' when it is
called with the intent of *compiling* and chain-call ld' when it is called
with the intent of *linking*. This can be decided by looking at its command-
line arguments.
How will our drop-in gcc replacement know how to call 'ld' correctly ? Because
when proper support is added to it, GNU GCC contains a 'linker specification'
for the system (a string of symbols describing a sort of decision tree) which
it uses to construct the linker command line. The 'ld' linker specifications
for QNX 8.0 can be extracted from 'gcc -dumpspecs' from the cross-compilers
(Win64->QNX and Linux->QNX) provided by Blackberry and have been reimplemented
in this file.
The GNU specs language is documented here:
https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html
The following environment variables control the behaviour of the driver:
DEBUG_LINKER_DRIVER - when defined to any value (including an empty
string), the constructed ld command line is printed
to the standard error before calling the linker.
Build with:
qnxsdp_env
ntox86_64-gcc linkerdriver.c -o gcc
or just 'make' on Win32.
--
Pierre-Marie Baty <pm@pmbaty.com>