Using the Clang Integrated Assembler to Compile the
Using the Clang Integrated Assembler to Compile the Linux Kernel Bryce Adelstein-Lelbach, Louisiana State University
What is the Integrated Assembler? • The Integrated Assembler (IA) is an assembler built in to the Clang compiler driver – Not a separate binary like the GNU Assembler (GAS) • Supports all platforms that Clang supports • Largely compatible with GAS • Benefits – Clang-style diagnostics for assembly – Faster compile times – No temporary assembly files stellar. cct. lsu. edu
IA Issues • IA rejects ambiguous inline x 86 assembly that GAS accepts • IA has no support for 16 -bit mode on x 86 • IA has no support for switching assembly modes on x 86 (e. g. . code 16, . code 32, . code 64) • IA does not support GCC-style explicit register variables (ERVs) • IA uses ARM Unified Assembly Language (UAL), and does not support GAS's ARM assembly extensions stellar. cct. lsu. edu
Ambiguous x 86 Inline Assembly • GAS is more lenient about accepting inline x 86 assembly that is ambiguous. For example: __asm__("add %al, (%rax)"); __asm__("addw $4, (%rax)"); __asm__("add $4, (%rax)"); • Discussion: how should we fix this? – Can someone give me an example of when the more explicit form would be bad? stellar. cct. lsu. edu
16 -bit Mode/Mode Switching • LLVM has no x 86 -16 backend – Essential for compiling kernel boot code, bootloaders, etc • GAS. code 16, . code 32, . code 64 directives – These directives tell GAS what type of assembly to output • Longer term project – Discussion: Could this be accomplished in a GSo. C? stellar. cct. lsu. edu
Explicit Register Variables • Places a variable into a specific hardware register. Example: register uint 64_t sp __asm__("%rsp"); • Compiler must exclude these registers from register allocation while the variable is in scope • Used to access the stack pointer in the kernel – A possible solution for this use case would be to add __builtin_stack_pointer() to Clang and GCC. • Also used in Xen, glibc and most dynamic linkers stellar. cct. lsu. edu
- Slides: 6