Subversion Repositories QNX 8.QNX8 linker driver

Rev

Rev 14 | Last modification | Compare with Previous | View Log | Download | RSS feed

Last modification

Path Last modification Log Download RSS
[FILE] gcc 13  2024-08-01 05:39:53 pmbaty Log Download RSS
[FILE] gcc.exe 13  2024-08-01 05:39:53 pmbaty Log Download RSS
[C-FILE] linkerdriver.c 13  2024-08-01 05:39:53 pmbaty Log Download RSS
[FILE] linkerdriver.vcxproj 2  2024-05-12 19:26:10 pmbaty Log Download RSS
[FILE] linkerdriver.vcxproj.user 1  2024-05-12 04:37:46 pmbaty Log Download RSS
[FILE] make.cmd 3  2024-05-12 19:45:22 pmbaty Log Download RSS
[FILE] README.md 15  2024-11-22 18:36:23 pmbaty Log Download RSS

QNX 8.0 gcc linker driver drop-in replacement

$ uname -a

QNX XPS64-df54 8.0.0 2024/06/13-12:41:48EDT x86pc x86_64

$ gcc hello.c

$ ./a.out

Hello world!

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 would 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 itself invokes cc1 or cc1plus, the actual compiler, depending on the language, then runs collect2 which in turn invokes ld, the UNIX linker).

This makes GCC the unique entrypoint for any platform- and target-specific compilation and linking task, and foreign compilers such as Clang just leverage that feature when support of the target system isn't built-in.

This implies a drop-in GCC replacement needs 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 does this 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 are public (because GCC is) and can be extracted from gcc -dumpspecs from the Win64->QNX and Linux->QNX cross-compilers provided by Blackberry, and have been reimplemented in this file.

The GNU specs language is documented on the GNU website here.

Driver behaviour

The following environment variables control the behaviour of the driver:

How to build

Build with:

qnxsdp_env
ntox86_64-gcc linkerdriver.c -o gcc

or just make on Win32.

--

Pierre-Marie Baty pm@pmbaty.com