[LLVMdev] Win32 COFF Support

Nathan Jeffords blunted2night at gmail.com
Sun May 2 15:40:58 PDT 2010


On Sun, May 2, 2010 at 1:47 PM, Aaron Gray
<aaronngray.lists at googlemail.com>wrote:

> On 2 May 2010 19:32, Nathan Jeffords <blunted2night at gmail.com> wrote:
>
>> Thanks for both of your feedback, I will attempt to make it fit LLVM
>> coding standards better before I resubmit my work.
>
>
> You can send me early drafts to run past GCC, send me something that works.
>

I will test against GCC on my ubuntu virtual machine.


>

> As far as the hooks I put in, they are really only there so I could build
>> the object exporter outside of LLVM, I think having it built directly in
>> like others is preferable in the end. I do think it would be useful if
>> projects had the option of extending supported formats without having to
>> modify LLVM itself, but my changes main goal was minimal impact on LLVM
>> sources.
>>
>
> AFAICT The hooks you sent did not call your code at all.
>
>
The hooks I put in place allow my compiler to specify its own MCStreamer
factory function that TargetMachine::addPassesToEmitFile calls when its time
to create the streamer object. I also made MCAssembler use a virtual
function to construct the MCObjectWriter which I then override in my
streamer to make it construct my object writer. To me, this was important to
allow the streamer & object writer to be built as part of my compiler and
not require me to run a build of LLVM every time I changed something. This
aproach also allows me to keep this code in source control as I bounce
between development machines multiple times a day.


> Have a look at the MachOWriter, this is designed to be extendable to other
> writers. The MCStreamer stuff just needs the same doing probably in
> TargetAsmBackend. It would be good to have this as a separate patch. This
> will allow both COFFWriter and ELFWriter as well as the MachOWriter to
> coexist and be selected by TargetTriple. BTW could you have your Writer and
> Streamer in different source code files, and follow the MachO code format as
> far as is possible/reasonable.
>

I have already re-factored the code a bit to better fit LLVM coding
standard. The writer & streamer are now two different source files, and code
for the coff::file class has been moved directly into the writer instead of
multiply inheriting from it.


>
> JTFYI The COFF code I have written consists of Reader and Writer of COFF
> internal object modules to/from COFF format. I am looking at producing a
> linker with the addition of a PE Writer class, and Library Reader class.
> This should then make LLVM and CLANG more independant on the Windows
> Platform. I have a COFF Dumper class too which works with the reader and the
> internal Object Module format.
>
>
Some time ago, I wrote a simple COFF based linker that would link into
series of object files into a memory buffer then write out the linked and
loaded image to a bin file for use with a OS project I was playing around
with. I revived it to help me test some problems I was having with
relocations. Perhaps some of that code could be useful.

hopefully, I can have a version that will compile as part of LLVM later
today

Thanks,
  Nathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100502/0ed77a77/attachment.html>


More information about the llvm-dev mailing list