Using DragonEgg

Dragonegg is a gcc plugin that allows gcc to make use of the LLVM optimizer and code generator instead of gcc's own optimizer and code generator.

Getting ready

You need to have gcc 4.5 or above, with the target machine being x86-32/x86-64 and an ARM processor. Also, you need to download the dragonegg source code and build the dragonegg.so file.

How to do It…

Do the following steps:

  1. Create a simple hello world program:
    $ cat testprog.c
    #include<stdio.h>
    int main() {
    printf("hello world");
    }
    
  2. Compile this program with your gcc; here we use gcc-4.5:
    $ gcc testprog.c -S -O1 -o -
      .file  " testprog.c"
      .section  .rodata.str1.1,"aMS",@progbits,1
    .LC0:
      .string  "Hello world!"
      .text
    .globl main
      .type  main, @function
    main:
      subq  $8, %rsp
     movl ...

Get LLVM Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.