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
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
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.
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.
Could you please add the comments describing the entities involved?
typedef std::map <std::string, size_t> map;
Please read LLVM Programmer’s Manual — LLVM 16.0.0git documentation and use the
data structures already provided by LLVM. E.g.
definitely be used here.
#define report_fatal_error_dbg(x) __debugbreak ()
Generally it's prohibited to use target/compiler-specific defines
outside of libSystem.
struct MCWin32CoffObjectWriter :
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
Was "| false" intentional? Why?
report_fatal_error_dbg ("unsupported section alignment");
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.