Rev 3 | Blame | Last modification | View Log | Download | RSS feed
QNX 8.0 'gcc' linker driver drop-in replacement by Pierre-Marie BatyRATIONALE=========Until a proper QNXToolchain class is implemented in the Clang driver, Clangrelies on GNU GCC to drive the system linker when it hasn't enough knowledgeof the underlying platform. So, if we are to provide a LLVM/Clang-based nativetoolchain for QNX, we *HAVE* to provide a 'gcc' executable for Clang to beable to link QNX files. This is an either/or situation and it was decidedthat reimplementing an external linker driver would be faster than doing itin the LLVM codebase (mostly because of the very long iteration times thatrebuilding LLVM causes, even when using a compiler cache.)Why does Clang chain-call gcc with the intent of linking ? Because GNU GCC isitself a 'driver' which can also invoke either a compiler or a linker ('gcc'invokes 'cc1' or 'cc1plus', the actual compiler, depending on the language,then runs 'collect2' which in turn invokes 'ld', the UNIX linker). This meansour drop-in GCC replacement will need to either chain-call 'clang' when it iscalled with the intent of *compiling* and chain-call 'ld' when it is calledwith 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 ? Becausewhen 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) whichit uses to construct the linker command line. The 'ld' linker specificationsfor QNX 8.0 can be extracted from 'gcc -dumpspecs' from the cross-compilers(Win64->QNX and Linux->QNX) provided by Blackberry and have been reimplementedin this file.The GNU specs language is documented here:https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.htmlThe following environment variables control the behaviour of the driver:DEBUG_LINKER_DRIVER - when defined to any value (including an emptystring), the constructed ld command line is printedto the standard error before calling the linker.Build with:qnxsdp_envntox86_64-gcc linkerdriver.c -o gccor just 'make' on Win32.--Pierre-Marie Baty <pm@pmbaty.com>