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]
fn new(keep_dwarf: bool,
embed_use_list: bool,
should_internalize: bool,
pic_mode: PIC,
keep_symbols: &[&str])
-> Result<Linker, String>
embed_use_list: bool,
should_internalize: bool,
pic_mode: PIC,
keep_symbols: &[&str])
-> Result<Linker, String>
Construct a new Linker
Contains all the options that are useful for this
keep_dwarf
: DebugModel. Iftrue
DWARF symbols are preservedembed_use_list
: Should the use list symbols be embedded within the output. This should be true for all but the last binaryshould_internalize
: I have zero clue what this does. It was removed in LLVMv4.0 here is a discussion why linkypic mode
: I think this has to with Position Independent Code (not 100% sure)keep_symbols
: Force the linker to preserve these symbols
fn add_file(&mut self, object_file: ObjFile)
Link an Object File
fn add_buffer(&mut self, object_buffer: Object)
Link to a Object File (in a memory buffer)
fn link_to_mem(self) -> Result<Object, String>
Complete linking, return a memory buffer
fn link_to_file<P: AsRef<Path>>(self, path: P) -> Result<(), String>
Complete linking, write to a file