All Projects → m4b → Faerie

m4b / Faerie

Licence: mit
Magical ELF and Mach-o object file writer backend

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Faerie

Open C Book
开源书籍:《C语言编程透视》,配套视频课程《360° 剖析 Linux ELF》已上线,视频讲解更为系统和深入,欢迎订阅:https://www.cctalk.com/m/group/88089283
Stars: ✭ 715 (+282.35%)
Mutual labels:  compiler, elf
Shecc
A self-hosting and educational C compiler
Stars: ✭ 286 (+52.94%)
Mutual labels:  compiler, elf
Command Block Assembly
Compile high-level code into Minecraft commands
Stars: ✭ 175 (-6.42%)
Mutual labels:  compiler
Appfairy
A CLI tool to Migrate a Webflow project into a React app
Stars: ✭ 183 (-2.14%)
Mutual labels:  compiler
Snapdragon
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Stars: ✭ 180 (-3.74%)
Mutual labels:  compiler
C3c
Compiler for the C3 language
Stars: ✭ 178 (-4.81%)
Mutual labels:  compiler
Whileycompiler
The Whiley Compiler (WyC)
Stars: ✭ 181 (-3.21%)
Mutual labels:  compiler
Inmemoryjavacompiler
Utility class to compile java source code in memory
Stars: ✭ 174 (-6.95%)
Mutual labels:  compiler
Minijit
A basic x86-64 JIT compiler written from scratch in stock Python
Stars: ✭ 185 (-1.07%)
Mutual labels:  compiler
Llvm Guide Zh
User Guides For those new to the LLVM system.(LLVM系统的新用户指南,中文翻译版)
Stars: ✭ 180 (-3.74%)
Mutual labels:  compiler
Veriloggen
Veriloggen: A Mixed-Paradigm Hardware Construction Framework
Stars: ✭ 182 (-2.67%)
Mutual labels:  compiler
Elfkit
rust elf parsing, manipulation and (re)linking toolkit
Stars: ✭ 180 (-3.74%)
Mutual labels:  elf
Go.vm
A simple virtual machine - compiler & interpreter - written in golang
Stars: ✭ 178 (-4.81%)
Mutual labels:  compiler
Philip2
An Elm to OCaml compiler
Stars: ✭ 182 (-2.67%)
Mutual labels:  compiler
Wag
WebAssembly compiler implemented in Go
Stars: ✭ 177 (-5.35%)
Mutual labels:  compiler
Prototype
(deprecated) The journey continues at ASNEXT: https://github.com/AssemblyScript/assemblyscript
Stars: ✭ 2,114 (+1030.48%)
Mutual labels:  compiler
Play with llvm
A book about LLVM & Clang(中文开源书:玩转 LLVM)
Stars: ✭ 175 (-6.42%)
Mutual labels:  compiler
Rubyspeed
Compile ruby functions to C
Stars: ✭ 180 (-3.74%)
Mutual labels:  compiler
Varjo
Lisp to GLSL Language Translator
Stars: ✭ 181 (-3.21%)
Mutual labels:  compiler
Hybridizer Basic Samples
Examples of C# code compiled to GPU by hybridizer
Stars: ✭ 186 (-0.53%)
Mutual labels:  compiler

faerie Build Status Documentatation.

Emit some object files, at your leisure:

let name = "test.o";
let file = File::create(Path::new(name))?;
let mut obj = ArtifactBuilder::new(triple!("x86_64-unknown-unknown-unknown-elf"))
    .name(name.to_owned())
    .finish();

// first we declare our symbolic references;
// it is a runtime error to define a symbol _without_ declaring it first
obj.declarations(
    [
        ("deadbeef", Decl::function().into()),
        ("main",     Decl::function().global().into()),
        ("str.1",    Decl::cstring().into()),
        ("DEADBEEF", Decl::data_import().into()),
        ("printf",   Decl::function_import().into()),
    ].iter().cloned()
)?;

// we now define our local functions and data
// 0000000000000000 <deadbeef>:
//    0:	55                   	push   %rbp
//    1:	48 89 e5             	mov    %rsp,%rbp
//    4:	48 8b 05 00 00 00 00 	mov    0x0(%rip),%rax        # b <deadbeef+0xb>
// 			7: R_X86_64_GOTPCREL	DEADBEEF-0x4
//    b:	8b 08                	mov    (%rax),%ecx
//    d:	83 c1 01             	add    $0x1,%ecx
//   10:	89 c8                	mov    %ecx,%eax
//   12:	5d                   	pop    %rbp
//   13:	c3                   	retq
obj.define("deadbeef",
    vec![0x55,
         0x48, 0x89, 0xe5,
         0x48, 0x8b, 0x05, 0x00, 0x00, 0x00, 0x00,
         0x8b, 0x08,
         0x83, 0xc1, 0x01,
         0x89, 0xc8,
         0x5d,
         0xc3])?;
// main:
// 55	push   %rbp
// 48 89 e5	mov    %rsp,%rbp
// b8 00 00 00 00	mov    $0x0,%eax
// e8 00 00 00 00   callq  0x0 <deadbeef>
// 89 c6	mov    %eax,%esi
// 48 8d 3d 00 00 00 00 lea    0x0(%rip),%rdi # will be: deadbeef: 0x%x\n
// b8 00 00 00 00	mov    $0x0,%eax
// e8 00 00 00 00	callq  0x3f <main+33>  # printf
// b8 00 00 00 00	mov    $0x0,%eax
// 5d	pop    %rbp
// c3	retq
obj.define("main",
    vec![0x55,
         0x48, 0x89, 0xe5,
         0xb8, 0x00, 0x00, 0x00, 0x00,
         0xe8, 0x00, 0x00, 0x00, 0x00,
         0x89, 0xc6,
         0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00, 0x00,
         0xb8, 0x00, 0x00, 0x00, 0x00,
         0xe8, 0x00, 0x00, 0x00, 0x00,
         0xb8, 0x00, 0x00, 0x00, 0x00,
         0x5d,
         0xc3])?;
obj.define("str.1", b"deadbeef: 0x%x\n\0".to_vec())?;

// Next, we declare our relocations,
// which are _always_ relative to the `from` symbol
obj.link(Link { from: "main", to: "str.1", at: 19 })?;
obj.link(Link { from: "main", to: "printf", at: 29 })?;
obj.link(Link { from: "main", to: "deadbeef", at: 10 })?;
obj.link(Link { from: "deadbeef", to: "DEADBEEF", at: 7 })?;

// Finally, we write the object file
obj.write(file)?;

Will emit an object file like this:

ELF REL X86_64-little-endian @ 0x0:

e_phoff: 0x0 e_shoff: 0x2a2 e_flags: 0x0 e_ehsize: 64 e_phentsize: 56 e_phnum: 0 e_shentsize: 64 e_shnum: 9 e_shstrndx: 1

SectionHeaders(9):
  Idx   Name                      Type   Flags                  Offset   Addr   Size    Link         Entsize   Align  
  0                           SHT_NULL                          0x0      0x0    0x0                  0x0       0x0    
  1     .strtab             SHT_STRTAB                          0x8c     0x0    0xc6                 0x0       0x1    
  2     .symtab             SHT_SYMTAB                          0x152    0x0    0xf0    .strtab(1)   0x18      0x8    
  3     .rodata.str.1       SHT_PROGBITS   ALLOC MERGE STRINGS    0x40     0x0    0x10                 0x1       0x1    
  4     .text.deadbeef    SHT_PROGBITS   ALLOC EXECINSTR        0x50     0x0    0x14                 0x0       0x10   
  5     .text.main        SHT_PROGBITS   ALLOC EXECINSTR        0x64     0x0    0x28                 0x0       0x10   
  6     .reloc.main           SHT_RELA                          0x242    0x0    0x48    .symtab(2)   0x18      0x8    
  7     .reloc.deadbeef       SHT_RELA                          0x28a    0x0    0x18    .symtab(2)   0x18      0x8    
  8     .note.GNU-stack   SHT_PROGBITS                          0x0      0x0    0x0                  0x0       0x1    

Syms(10):
               Addr   Bind       Type        Symbol     Size    Section             Other  
                 0    LOCAL      NOTYPE                 0x0                         0x0    
                 0    LOCAL      FILE        test.o     0x0     ABS                 0x0    
                 0    LOCAL      SECTION                0x0     .rodata.str.1(3)      0x0    
                 0    LOCAL      SECTION                0x0     .text.deadbeef(4)   0x0    
                 0    LOCAL      SECTION                0x0     .text.main(5)       0x0    
                 0    LOCAL      OBJECT      str.1      0x10    .rodata.str.1(3)      0x0    
                 0    LOCAL      FUNC        deadbeef   0x14    .text.deadbeef(4)   0x0    
                 0    GLOBAL     FUNC        main       0x28    .text.main(5)       0x0    
                 0    GLOBAL     NOTYPE      DEADBEEF   0x0                         0x0    
                 0    GLOBAL     NOTYPE      printf     0x0                         0x0    

Shdr Relocations(4):
  .text.main(3)
              13 X86_64_PC32 .rodata.str.1
              1d X86_64_PLT32 printf+-4
               a X86_64_PLT32 .text.deadbeef+-4

  .text.deadbeef(1)
               7 X86_64_GOTPCREL DEADBEEF+-4

😎

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].