[cfe-dev] Defining a custom "mixed" TargetInfo

Luboš Doležel via cfe-dev cfe-dev at lists.llvm.org
Sun Dec 13 05:36:53 PST 2015


On 12/13/2015 01:12 AM, Luboš Doležel via cfe-dev wrote:
> Hello,
> 
> I'm looking for a way of altering the default i386 ABI on Linux, namely
> for the Darling project (running OS X apps on Linux).
> 
> There are at least two deal-breaking incompatibilities between the i386
> Darwin and Linux ABIs:
> 
> - size_t on Linux is unsigned int, but unsigned long on Darwin.
> - long double on Linux is 96 bits long, Darwin's is 128 bits long.
> 
> Trying the hack around the first one by defining size_t differently
> doesn't end up very well:
> 
> /home/lubos/Projects/darling/src/external/libcxx/include/new:131:30:
> error: 'operator new' takes type size_t ('unsigned int') as first parameter
> 
> I have tried to force the Darwin ABI (which forces Mach-O), but keep the
> ELF output format, but that was very naive of me, apparently.
> 
> An easy way would be to extend clang with a new special descendant of
> X86TargetInfo, but Darling surely doesn't meet the first Clang
> contribution criterion ("Evidence of a significant user community"). (Or
> would this extension be sufficiently small to be accepted?)
> 
> Please, do you have any advice how to go on?
> 
> Thanks!

It appears that this could actually work:

$ clang++ -c test.cpp -target i386-unknown-darwin-elf

error: backend data layout
'e-m:e-p:32:32-f64:32:64-f80:128-n8:16:32-S128' does not match expected
target description 'e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128'

...provided that I add a single "if" into DarwinI386TargetInfo, which
would use m:o or m:e depending on the output format from the triple.

It seems that something very similar is already done in
WindowsX86_32TargetInfo below (choosing between ELF and COFF).

-- 
Luboš Doležel



More information about the cfe-dev mailing list