[PowerPC, Mach-O] PPCMachObjectWriter.cpp, at long last

David Fang fang at csl.cornell.edu
Thu Jul 25 14:20:27 PDT 2013


I tried the following sed-transformation to turn darwin-asm to linux-asm:

"darwin-to-linux-asm.sed":
#!/sw/bin/sed -f
s|\<r\([0-9]\+\)\>|\1|g
s|\<ha16\>\(([^(]*)\)|\1 at ha|g
s|\<lo16\>\(([^(]*)\)|\1 at l|g
s|\<L[A-Za-z0-9.$_]\+\>|.&|g

1) strip 'r' from register names
2,3) transform ha16/lo16 operators
4) prepend . to local symbols

% darwin-to-linux-asm.sed hello-puts.s > hello-puts-linux.s

% llvm-mc -triple=powerpc-apple-darwin8 -mcpu=g4 -relocation-model=pic -filetype=obj hello-puts-linux.s -o hello-puts-linux.o

llvm-mc was able to compile this version of the assembly, but produced an 
object file that differs from the one produced by llc -filetype=obj.

diffs:
http://paste.lisp.org/display/138202#1

I'm not partcularly comfortable going down this path with hacks.
I'd need to be advised on all the syntactic transformations needed.
Can't we just keep the llc -filetype=obj test for now until proper 
darwin-asm syntax is supported?

Fang

> On 25 July 2013 14:27, David Fang <fang at csl.cornell.edu> wrote:
>> Rafael,
>>
>> Testing .s->.o via llvm-mc would be ideal, but the PPCAsmParser doesn't
>> support darwin syntax yet.
>
> Can't you use the existing syntax as a hack?
>
>
>> I've revised the test commands and added a comment:
>>
>> [hello-reloc.ll]
>> ...
>> ; RUN: llc -filetype=asm -relocation-model=pic -mcpu=g4
>> -mtriple=powerpc-apple-darwin8 %s -o - | tee %t1 | FileCheck
>> -check-prefix=DARWIN-G4-ASM %s
>> ; RUN: llc -filetype=obj -relocation-model=pic -mcpu=g4
>> -mtriple=powerpc-apple-darwin8 %s -o - | tee %t2 | macho-dump | tee %t3
>> FileCheck -check-prefix=DARWIN-G4-DUMP %s
>>
>> ; FIXME: validating .s->.o requires darwin asm syntax support in
>> PPCAsmParser
>> ; RUN-XFAIL: llvm-mc -relocation-model=pic -mcpu=g4
>> -triple=powerpc-apple-darwin8 %t1 -o - | tee %t4 | macho-dump | tee %t5 |
>> FileCheck -check-prefix=DARWIN-G4-DUMP %s
>> ; RUN-XFAIL: diff -u %t2 %t4 || diff -u %t3 %t5
>>
>> The RUN-XFAIL doesn't actually run, it's just a comment.
>> The diff first compares object files, and if that fails, the second diff
>> will also fail and show the differences from macho-dump.
>>
>> Would this be acceptable for now?
>>
>> Fang
>>
>>
>>> OK, now that I see that this is adding the entire PPCMachObjectWriter
>>> I think it should be tested with llvm-mc. Even a hack like using a .s
>>> file with "linux" syntax would be better than depending on llc
>>> -filetype=obj.
>>>
>>> In the past uses llc -filetype=obj stayed around longer than intended
>>> and were fairly brittle.
>>>
>>> On 25 July 2013 00:05, David Fang <fang at csl.cornell.edu> wrote:
>>>>
>>>> Hi,
>>>>         Attached is a patch from my powerpc-darwin8 branch
>>>> [https://github.com/fangism/llvm/tree/powerpc-darwin8] that I've been
>>>> maintaining and merging from trunk for months.  This contains the first
>>>> cut
>>>> of the relocation entry implementation for mach-o/PPC, which is missing
>>>> on
>>>> trunk.
>>>>
>>>> The patch addresses the feature requested here:
>>>> http://llvm.org/bugs/show_bug.cgi?id=14636
>>>>
>>>> 1. This patch was extracted piecewise from my powerpc-darwin8 branch.  I
>>>> can
>>>> only compile the branch and not master/trunk because of other
>>>> compiler-workarounds that are needed, but excluded from this patch.
>>>> It's *possible* I may have made a cut/paste/merge error.
>>>> I could use a volunteer or two to actually test-compile and run this on
>>>> svn-trunk.  Running the new test CodeGen/PowerPC/hello-reloc.ll with
>>>> llvm-lit would be great feedback, and shouldn't require a Darwin machine,
>>>> just have Targets=PPC.
>>>>
>>>> 2. I've tested PIC objects on small hello-world sized programs such as
>>>> the
>>>> test that is included.  The executables run correctly.
>>>>
>>>> 3. I have compared the object files and their dumps against
>>>> system-assembled
>>>> (GNU as) object files.  (See bug report above for details.)
>>>>
>>>> 4. Style comments are welcome, though effort to conform on this was
>>>> minimal.
>>>> I plan to follow through on feedback.
>>>>
>>>> I understand this may take many iterations, but the ball has to get
>>>> rolling
>>>> some time.
>>>>
>>>> Let the comments begin.
>>>>
>>>> Fang
>>>>
>>>> --
>>>> David Fang
>>>> http://www.csl.cornell.edu/~fang/
>>>>
>>>> _______________________________________________
>>>> llvm-commits mailing list
>>>> llvm-commits at cs.uiuc.edu
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>>
>>>
>>
>> --
>> David Fang
>> http://www.csl.cornell.edu/~fang/
>>
>

-- 
David Fang
http://www.csl.cornell.edu/~fang/




More information about the llvm-commits mailing list