[powerpc-darwin] cpusubtype mismatches between integrated/no-integrated-as
| Bugzilla Link | 18463 |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @echristo,@iains,@jeremyhu |
Extended Description
Object files written by the integrated-as get a different CPU subtype than using no-integrated-as.
% otool -h gcc40-stage2-build/lib/Support/CMakeFiles/LLVMSupport.dir/IsNAN.cpp.o gcc40-stage2-build/lib/Support/CMakeFiles/LLVMSupport.dir/IsNAN.cpp.o: Mach header magic cputype cpusubtype filetype ncmds sizeofcmds flags 0xfeedface 18 10 1 3 364 0x00002000
% otool -h gcc40-stage2-intas-build/lib/Support/CMakeFiles/LLVMSupport.dir/IsNAN.cpp.o gcc40-stage2-intas-build/lib/Support/CMakeFiles/LLVMSupport.dir/IsNAN.cpp.o: Mach header magic cputype cpusubtype filetype ncmds sizeofcmds flags 0xfeedface 18 0 1 3 364 0x00002000
-----------------------------^ here
Is this perhaps related to the .machine directive in AsmParser?
Once we get this to match, I can do a direct object comparison between stage-2 with/without integrated-as.
While it is true that ppc is EOL, and the behavior certainly doesn't need to match what it used to as long as you maintain binary compatibility, I would strongly suggest that you fix this problem in a way that is consistent across different architectures.
FAOD; my comment is simply that (because the platform is EOL) anything that we might do to extend behaviour to cater for functionality that was not present in the darwin ppc ports (e.g. LTO) need not be concerned that it might conflict.
Specifically, arm and intel are dealing with this problem in a hacky way, and it would be good to solve the it once for mach-o in general and let ppc, arm, and intel all benefit from the same set of changes and a shared common architecture.
Certainly. However this is surely going to be led by the Intel and ARM ports which are current and under development - PPC can (and should) adopt whatever the eventual chosen solution is there.
Eric mentioned the idea of automatically generating slices to cater for multiple incompatible arch labels on functions. That seems like an extension (rather than a hack) - but does require the creation of multiple streamers (on demand) and that the .o file emission understands the concepts of FAT files.
To maintain the abstraction that the .s and .o streamers are equivalent, the splitting of arch-dependent streams would also have to happen at quite a low-level, which might be quite a bit of adjustment.
While it is true that ppc is EOL, and the behavior certainly doesn't need to match what it used to as long as you maintain binary compatibility, I would strongly suggest that you fix this problem in a way that is consistent across different architectures.
Specifically, arm and intel are dealing with this problem in a hacky way, and it would be good to solve the it once for mach-o in general and let ppc, arm, and intel all benefit from the same set of changes and a shared common architecture.
So Eric was asking about this (or rather a related topic) on IRC
I have looked up the behaviour of the Apple compiler.
- There only interface to as is "-arch ppc|ppc64" the cpu type is not passed on the c/l
- The remaining actions are carried out using the ,machine directive
- thus, -mcpu= on the command line is ignored for .S/.s files
- -mcpu= on the command line is processed in a logical manner to produce a .machine directive for .i/.c
- if the -mcpu= disagrees with the -m32/64 (e.g. -m64 -mcpu=7400) then the mcpu is ignored e.g. in that case a .machine of ppc64 used
- if one puts a stupid .machine directive in a .s file as errors (e.g. -m64 with .machine ppc7400)
- in the absence of a .machine directive the cpusubtype = any
- the last .machine directive in the asm file sets the cpusubtype.
- in particular .machine ppc970 .machine ppc7400
sets cpusubtype on the file = ppc7400 NOT 'any" as one might expect.
9 there are a lot of .machine values we don't have (and I don't think we need) - but we might wish to implement ppc970-64 at some point.
because the arch (ppc/ppc64) and cpu subtype are file-global there's no way to communicate things per function. All one could do would be to create slices - or to force the cpusubtype = any (although that would deviate fron the Apple compiler behaviour).
To some extent, we have carte-blanch to change things - since the platform is EOL - so long as we are backward-compatible with the existing installed libs.
Yeah, the current architecture is fighting against this. X86 and ARM work around this in similarly hacky ways by checking the triple. That's an ok proxy but is not technically correct nor fool-proof. Unfortunately, I'll probably just follow a similar path for this in MacPorts since I don't really have the desire nor time to come up with a better way of doing it.
make the default 7400 for darwin >= 9 (OS X 10.5) This is in my (long) Q of patches that allow self-hosting of clang/llvm on earlier darwin platforms (incl. powerpc). It solves part of the problem by making the default correct when using the clang driver.
It's lacking a test-case in order to apply it.
As of now, I haven't got around to making a patch that modifies the binary file CPU type on the basis of the .machine directive in asm.
This is on the TODO, but needs a modification to the core mach-o stuff, which assumes currently that the CPU type is set when the output object is created and doesn't have an interface to modify the value as a result of the .machine directive.
PPCAsmPrinter.cpp seems to have support for picking the right directive, assuming DarwinDirective is set correctly:
unsigned Directive = Subtarget.getDarwinDirective(); if (Subtarget.hasMFOCRF() && Directive < PPC::DIR_970) Directive = PPC::DIR_970; if (Subtarget.hasAltivec() && Directive < PPC::DIR_7400) Directive = PPC::DIR_7400; if (Subtarget.isPPC64() && Directive < PPC::DIR_64) Directive = PPC::DIR_64; assert(Directive <= PPC::DIR_64 && "Directive out of range.");
Unfortunately, simple grepping suggests that there isn't any logic to set it to ppc7400 based on the deployment target being >= 10.5.
Additionally, PPCAsmBackend.cpp is not encoding the cpu subtype. It just always writes out CPU_SUBTYPE_POWERPC_ALL unconditionally:
MCObjectWriter *createObjectWriter(raw_ostream &OS) const override {
bool is64 = getPointerSize() == 8;
return createPPCMachObjectWriter(
OS,
/*Is64Bit=*/is64,
(is64 ? MachO::CPU_TYPE_POWERPC64 : MachO::CPU_TYPE_POWERPC),
MachO::CPU_SUBTYPE_POWERPC_ALL);
}
This is likely because clang doesn't have the same cpu subtype selection that was added to gcc. Specifically, G3 support was dropped from OS X Leopard:
~ $ gcc-4.2 -arch ppc -c test.c -mmacosx-version-min=10.4
~ $ otool -h test.o test.o: Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags 0xfeedface 18 0 0x00 1 3 296 0x00002000
~ $ gcc-4.2 -arch ppc -c test.c -mmacosx-version-min=10.5
~ $ otool -h test.o test.o: Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags 0xfeedface 18 10 0x00 1 3 296 0x00002000
I'm surprised to see that your non-integrated-as building with subtype 10 given that I assume you are setting a deployment target of 10.4. Was your deployment target higher than 10.4? If it was 10.3, how was the no-integrated-assembler IsNAN.cpp.o compiled and assembled?
PowerPC dropped the support for Darwin. Closing this item.