Struct llvm_link::Linker [] [src]

pub struct Linker { /* fields omitted */ }

Used to construct the Linker

This builds an instance of, and can execute the LLVM libLTO linker

use llvm_link::{Linker,PIC,ObjFile,Object};

// build the linker(s)
let mut linker_stage1 = match Linker::new(true,true,false,PIC::default(),&["foo", "bar"]) {
    Ok(x) => x,
    Err(e) => panic!("Could not construct linker. Here's why: {}",e)
};
let mut linker_stage2 = match Linker::new(false,false,true,PIC::default(),&[]) {
    Ok(x) => x,
    Err(e) => panic!("Could not construct linker. Here's why: {}",e)
};

//load files
let obj1 = match ObjFile::new("/home/me/my_project/my_file.o") {
    Ok(x) => x,
    Err(e) => panic!("The LLVM can't load my_file.o Here's why: {}",e)
};
let obj2 = match ObjFile::new("/home/me/my_project/my_other_file.o") {
    Ok(x) => x,
    Err(e) => panic!("The LLVM can't load my_other_file.o Here's why: {}",e)
};
let obj3 = match ObjFile::new("/home/me/my_project/my_final_file.o") {
    Ok(x) => x,
    Err(e) => panic!("The LLVM can't load my_file_file.o Here's why: {}",e)
};

// add the files
linker_stage1.add_file(obj1);
linker_stage2.add_file(obj2);

// compile in memory
let stage1_obj: Object = match linker_stage1.link_to_mem() {
    Ok(x) => x,
    Err(e) => panic!("Link error in stage 1: {}",e)
};

// set up stage 2
linker_stage2.add_buffer(stage1_obj);
linker_stage2.add_file(obj3);

// release output
match linker_stage2.link_to_file("/home/me/my_project/my_project.a") {
    Ok(_) => { },
    Err(e) => panic!("Link error in stage 2: {}", e)
};

Methods

impl Linker
[src]

Construct a new Linker

Contains all the options that are useful for this

  • keep_dwarf: DebugModel. If true DWARF symbols are preserved
  • embed_use_list: Should the use list symbols be embedded within the output. This should be true for all but the last binary
  • should_internalize: I have zero clue what this does. It was removed in LLVMv4.0 here is a discussion why linky
  • pic mode: I think this has to with Position Independent Code (not 100% sure)
  • keep_symbols: Force the linker to preserve these symbols

Link an Object File

Link to a Object File (in a memory buffer)

Complete linking, return a memory buffer

Complete linking, write to a file

Trait Implementations

impl Drop for Linker
[src]

A method called when the value goes out of scope. Read more