Subversion Repositories QNX 8.QNX8 linker driver

Rev

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'
17
invokes 'collect2' which in turn invokes 'ld', the UNIX linker). This means
18
our drop-in GCC replacement will need to either chain-call 'clang' when it is
19
called with the intent of *compiling* and chain-call ld' when it is called
20
with the intent of *linking*. This can be decided by looking at its command-
21
line arguments.
22
 
23
How will our drop-in gcc replacement know how to call 'ld' correctly ? Because
24
when proper support is added to it, GNU GCC contains a 'linker specification'
25
for the system (a string of symbols describing a sort of decision tree) which
26
it uses to construct the linker command line. The 'ld' linker specifications
27
for QNX 8.0 can be extracted from 'gcc -dumpspecs' from the cross-compilers
28
(Win64->QNX and Linux->QNX) provided by Blackberry and have been reimplemented
29
in this file.
30
 
31
The GNU specs language is documented here:
32
https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html
33
 
34
The following environment variables control the behaviour of the driver:
35
   DEBUG_LINKER_DRIVER - when defined to any value (including an empty
36
                         string), the constructed ld command line is printed
37
                         to the standard error before calling the linker.
38
 
39
Build with:
40
	qnxsdp_env
41
	ntox86_64-gcc linkerdriver.c -o gcc
42
 
43
or just 'make' on Win32.
44
 
45
-- 
46
Pierre-Marie Baty <pm@pmbaty.com>