Compilers #644
-
I'm in the early stages of developing a compiler (for a new systems programming language), written in C# which generates unmanaged code and will eventually target ELF but initially I want to target Windows. I want to be able to generate windows COFF output OBJ/DLL files programmatically, the compiler generates unmanaged code. I did this many years ago and wrote a COFF generator in C, part of the backend of a compiler that worked and produced linkable outputs. But that code is all C and I'd rather avoid writing a C# version of that code if I can. So can AsmResolver be used for this? FYI this is the compiler I did years ago and this is the source and header for the "cofflib" COFF file generator. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
AsmResolver can create new PE files, which includes DLLs. Creating and writing a PE can be as simple as: using AsmResolver;
using AsmResolver.PE.File;
// Create a new empty PE file (default target arch is i386).
var file = new PEFile();
// Add a section.
var section = new PESection(
name: ".text",
characteristics: SectionFlags.MemoryRead | SectionFlags.MemoryExecute | SectionFlags.ContentCode,
contents: new DataSegment([1, 2, 3, 4, 5])
);
file.Sections.Add(section);
// Save it to the disk.
file.Write(@"C:\output.dll"); You probably want to start here or here for documentation for setting up the headers, creating sections, and interacting with standard data directories found in PE. AsmResolver does not have support for |
Beta Was this translation helpful? Give feedback.
-
Thanks. Sure I don't expect code to be generated, I will do that, but I do have a few questions:
|
Beta Was this translation helpful? Give feedback.
AsmResolver can create new PE files, which includes DLLs. Creating and writing a PE can be as simple as:
You probably want to start here or here for documentation for setting up the headers, creating sections, and interacting with standard data directories found in…