[LLVMdev] Win32 COFF Support

Anton Korobeynikov anton at korobeynikov.info
Sun May 2 02:53:05 PDT 2010


Hello, Nathan

First of all, I would like to mention that COFF MC backend will be a
really good contribution to LLVM!

> I have created a minimally functional Win32 COFF Exporter using the new MC
> framework. I made some minor changes to other libraries to allow me to plug
> it in without building it as part of the LLVM project. I wanted to share it
> but wasn't sure how to go about doing so, so I have attached the code to
> this message.
> Any feedback on would beĀ appreciated.
As it was already mentioned before you should definitely read & follow
LLVM coding standards.

I'll let others comment on MC hooks, I just made a very brief look
over the contents of the archive. You can find the comments below.

First of all, please include all the files as attachments. If you
decide to put stuff into archive use something standard, e.g. .zip or
.tar.gz.

coff.h:
Please document the source of the information for this file - some
documents, links will be really good. If you copied stuff out of
somewhere - there should be some license disclaimer, etc.

> #pragma once
Use standard include guards

>        typedef unsigned char   uint8;
>        typedef unsigned short  uint16;
>        typedef unsigned long   uint32;
Do not reinvent the wheel - use standard portable types e.g. uint8_t
and friends. "unsigned long" is not 32 bit everywhere.

> #pragma pack (push, 1)
Do not use these pragma's. Not all compilers support them.

>        struct symbol
Could you please add the comments describing the entities involved?

>               typedef std::map <std::string, size_t> map;
Please read http://llvm.org/docs/ProgrammersManual.html and use the
data structures already provided by LLVM. E.g.
http://llvm.org/docs/ProgrammersManual.html#dss_stringmap should
definitely be used here.

> #ifdef _MSC_VER
> #include "stdafx.h"
> #endif
> #define report_fatal_error_dbg(x) __debugbreak ()
Generally it's prohibited to use target/compiler-specific defines
outside of libSystem.

>        struct MCWin32CoffObjectWriter :
>                MCObjectWriter,
>                coff::file
Any reason for such inheritance?

>  MCSectionCOFF const & Section = dynamic_cast <MCSectionCOFF const &> (SectionData.getSection ());
LLVM normally compiles w/o RTTI, so this won't work

>                                CoffSection->Header.Characteristics |=
>                                        coff::IMAGE_SCN_CNT_CODE                |
>                                        coff::IMAGE_SCN_MEM_READ                |
>                                        coff::IMAGE_SCN_MEM_EXECUTE             |
>                                        false;
Was "| false" intentional? Why?

>                        default:
>                                report_fatal_error_dbg ("unsupported section alignment");
Use llvm_unreachable()

>                        for (SmallVector<char, Len>::const_iterator i = Data.begin (); i != Data.end (); i++)
>                        {
>                                if (i != Data.begin ())
>                                        dbgout (' ');
See llvm/Support/Debug.h for standard way of doing debug output in
LLVM code. There are bunch of examples in many places.

-- 
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University




More information about the llvm-dev mailing list