Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 3 | pmbaty | 1 | QNX 8.0 'gcc' linker driver drop-in replacement by Pierre-Marie Baty |
| 2 | |||
| 3 | RATIONALE |
||
| 4 | ========= |
||
| 5 | |||
| 6 | Until a proper QNXToolchain class is implemented in the Clang driver, Clang |
||
| 7 | relies on GNU GCC to drive the system linker when it hasn't enough knowledge |
||
| 8 | of the underlying platform. So, if we are to provide a LLVM/Clang-based native |
||
| 9 | toolchain for QNX, we *HAVE* to provide a 'gcc' executable for Clang to be |
||
| 10 | able to link QNX files. This is an either/or situation and it was decided |
||
| 11 | that reimplementing an external linker driver would be faster than doing it |
||
| 12 | in the LLVM codebase (mostly because of the very long iteration times that |
||
| 13 | rebuilding LLVM causes, even when using a compiler cache.) |
||
| 14 | |||
| 15 | Why does Clang chain-call gcc with the intent of linking ? Because GNU GCC is |
||
| 16 | itself a 'driver' which can also invoke either a compiler or a linker ('gcc' |
||
| 9 | pmbaty | 17 | invokes 'cc1' or 'cc1plus', the actual compiler, depending on the language, |
| 18 | then runs 'collect2' which in turn invokes 'ld', the UNIX linker). This means |
||
| 3 | pmbaty | 19 | our drop-in GCC replacement will need to either chain-call 'clang' when it is |
| 9 | pmbaty | 20 | called with the intent of *compiling* and chain-call 'ld' when it is called |
| 3 | pmbaty | 21 | with the intent of *linking*. This can be decided by looking at its command- |
| 22 | line arguments. |
||
| 23 | |||
| 24 | How will our drop-in gcc replacement know how to call 'ld' correctly ? Because |
||
| 25 | when proper support is added to it, GNU GCC contains a 'linker specification' |
||
| 26 | for the system (a string of symbols describing a sort of decision tree) which |
||
| 27 | it uses to construct the linker command line. The 'ld' linker specifications |
||
| 28 | for QNX 8.0 can be extracted from 'gcc -dumpspecs' from the cross-compilers |
||
| 29 | (Win64->QNX and Linux->QNX) provided by Blackberry and have been reimplemented |
||
| 30 | in this file. |
||
| 31 | |||
| 32 | The GNU specs language is documented here: |
||
| 33 | https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html |
||
| 34 | |||
| 35 | The following environment variables control the behaviour of the driver: |
||
| 36 | DEBUG_LINKER_DRIVER - when defined to any value (including an empty |
||
| 37 | string), the constructed ld command line is printed |
||
| 38 | to the standard error before calling the linker. |
||
| 39 | |||
| 40 | Build with: |
||
| 41 | qnxsdp_env |
||
| 42 | ntox86_64-gcc linkerdriver.c -o gcc |
||
| 43 | |||
| 44 | or just 'make' on Win32. |
||
| 45 | |||
| 46 | -- |
||
| 47 | Pierre-Marie Baty <pm@pmbaty.com> |