[RFC] Add x86-16 target to llvm, 'clang -m16' support.

David Woodhouse dwmw2 at infradead.org
Mon Jan 6 07:41:22 PST 2014


With this, I can use 'clang -m16' and get 16-bit code output. This is
needed for building the early boot code for the Linux kernel, amongst
other things.

With GCC, we do this using a fragile hack using asm(".code16gcc") and
playing dirty tricks to ensure that it really does come at the *start*
of the resulting assembler output. See GCC PR59672 for a request to add
a simple '-m16' option there too: http://gcc.gnu.org/PR59672

Note that I don't bother to define a gratuitous new subclass of
X86TargetMachine for the 16-bit target. Since X86_32TargetMachine is
actually perfectly usable for 16-bit, 32-bit *and* 64-bit targets, in
fact I *only* use that:

--- a/lib/Target/X86/X86TargetMachine.cpp
+++ b/lib/Target/X86/X86TargetMachine.cpp
@@ -24,8 +24,9 @@ using namespace llvm;
 
 extern "C" void LLVMInitializeX86Target() {
   // Register the target.
+  RegisterTargetMachine<X86_32TargetMachine> W(TheX86_16Target);
   RegisterTargetMachine<X86_32TargetMachine> X(TheX86_32Target);
-  RegisterTargetMachine<X86_64TargetMachine> Y(TheX86_64Target);
+  RegisterTargetMachine<X86_32TargetMachine> Y(TheX86_64Target);
 }


Perhaps we should ditch those subclasses altogether and just use
X86TargetMachine? See my mail a few minutes ago to llvmdev@ about that:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-January/069153.html

-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse at intel.com                              Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm-x86_16.patch
Type: text/x-patch
Size: 15401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140106/834f7ce2/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-x86_16.patch
Type: text/x-patch
Size: 3947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140106/834f7ce2/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140106/834f7ce2/attachment-0002.bin>


More information about the llvm-commits mailing list