Together, We make the difference. Create a Working Linker with the MCLinker framework Luba Tang 2013/02/24.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
lld The LLVM Linker Friday, April 13, 2012
Chapter 10 Linking and Loading. Separate assembly creates “.mob” files.
Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
BASIS Quick Start Guide by Andreas Schuh.  Introduction  Installing BASIS  Creating a New Project  Installing Your Project  Adding Executables 
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Systems Software.
Together, We make the difference. MCLinker Intermediate Representation Luba Tang 2013/2/24.
Generating Programs and Linking Professor Rick Han Department of Computer Science University of Colorado at Boulder.
Characteristics of Realtime and Embedded Systems Chapter 1 6/10/20151.
Exploring the UNIX File System and File Security
Embedded Systems Programming Introduction to cross development techniques.
Software Language Levels Machine Language (Binary) Assembly Language –Assembler converts Assembly into machine High Level Languages (C, Perl, Shell)
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Embedded Control Systems Introduction to cross development techniques.
G++ and make Dan Wilson CS193 02/01/06. The g++ Compiler What happens when you call g++ to build your program? Phase 1, Compilation:.cpp files are compiled.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
Introduction to The Linaro Toolchain Embedded Processors Training Multicore Software Applications Literature Number: SPRPXXX 1.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
OBJECT MODULE FORMATS. The object module format we have employed as an educational device is called OMF (relocatable object format). It’s one of the earliest.
LATTICE TECHNOLOGY, INC. For Version 10.0 and later XVL Web Master Advanced Tutorial For Version 10.0 and later.
1 INF160 IS Development Environments AUBG, COS dept Lecture 06 Title: Dev Env: Code::Blocks (Extract from Syllabus) Reference:
Together, We make the difference. Introduction to LLVM and MCLinker Luba Tang.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
MIPS coding. SPIM Some links can be found such as:
chap13 Chapter 13 Programming in the Large.
Form printing with SAP Smart Forms Instructor: Dylan Liu
Lab 11 Department of Computer Science and Information Engineering National Taiwan University Lab11 - Porting 2014/12/9/ 26 1.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
File Systems (1). Readings r Reading: Disks, disk scheduling (3.7 of textbook; “How Stuff Works”) r Reading: File System Implementation ( of textbook)
Progress with migration to SVN Part3: How to work with g4svn and geant4tags tools. Geant4.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Topic 2d High-Level languages and Systems Software
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Chapter Two Exploring the UNIX File System and File Security.
Bit-DSP-MicrocontrollerTMS320F2812 Texas Instruments Incorporated European Customer Training Center University of Applied Sciences Zwickau (FH)
Dissecting the Windows CE Build Process James Y. Wilson Principal Engineer, Windows Embedded MVP CalAmp, Inc. James Y. Wilson Principal Engineer, Windows.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
1 © 2004, Cisco Systems, Inc. All rights reserved. CCNA 3 v3.1 Module 6 Switch Configuration.
Paradyn Project Paradyn / Dyninst Week Madison, Wisconsin April 12-14, 2010 Binary Rewriting with Dyninst Madhavi Krishnan and Dan McNulty.
1 © 2004, Cisco Systems, Inc. All rights reserved. CCNA 2 v3.1 Module 5 Managing Cisco IOS Software.
Chapter Linux Basics. Acknowledgements This presentation was prepared by – Banyat Settapanich – Bahran Madaen This presentation will be updated later.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
Sung-Dong Kim Dept. of Computer Engineering, Hansung University Chapter 3 Programming Tools.
김민수 Cortex-M4 Processor - Getting Started with the GNU Compiler Collection(gcc)
Program Execution and ELF Files Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014 Abed Asi.
The World Leader in High Performance Signal Processing Solutions Toolchain Basics.
LLVM IR, File - Praakrit Pradhan. Overview The LLVM bitcode has essentially two things A bitstream container format Encoding of LLVM IR.
Together, We make the difference. Tutorial on MCLinker and LLVM Luba Tang, MCLinker architect, MediaTek Wei-Ren Chen, Research Assistant, Sinica.
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Version Control Systems
BASIS Quick Start Guide
Computer Architecture and Assembly Language
CCNA 3 v3.1 Module 6 Switch Configuration
Program Execution in Linux
Version Control Systems
Contiki and Code Composer Studio
Software Installation
Introduction Paul Flynn
Program Execution in Linux
Appendix F C Programming Environment on UNIX Systems
The Role of Command Line Compiler (csc.exe)
Program Assembly.
Computer Architecture and System Programming Laboratory
SPL – PS1 Introduction to C++.
Presentation transcript:

Together, We make the difference. Create a Working Linker with the MCLinker framework Luba Tang 2013/02/24

Agenda ▪ Getting Started –Build MCLinker –Run and cross linking ▪ A simplest linker ▪ Understanding the MCLinker IR framework –Module –LinkerConfig –Linker ▪ Use IRBuilder to build up the input tree ▪ Use IRBuilder to build up the fragment-reference graph Luba Tang, software architect of MCLinker MediaTek, inc.

Together, We make the difference. Download and Install LLVM ▪ MCLinker requires LLVM libraries. Before building MCLinker, you must have LLVM 1.Download LLVM 1.Install LLVM svn co -r llvm cd llvm cd../.. #go back to where you started mkdir llvm-build cd llvm-build../llvm/configure --prefix=${LLVM_INSTALL} make all install

Together, We make the difference. Download and Install MCLinker ▪ MCLinker building system is the GNU auto tool system 1.Download Developing MCLinker 1.Configure MCLinker with llvm-config tool 1.Install MCLinker git clone mcld cd mcld./autogen.sh./configure –with-llvm-config=${LLVM_INSTALL}/bin/llvm-config – prefix=${MCLD_INSTALL} make && make install

Together, We make the difference. Run! ▪ GNU ld is the de facto standard. MCLinker option must compatible to the GNU ld ▪ Synopsis –ld.mcld [options] objfile … ▪ Cross linking options -mtriple=target-triple -march=cpu-arch ▪ Cross Linker –Rename the `ld.mcld` with the prefix of triple ld.mcld -shared -march=arm a.o –o out.so ld.mcld -shared –mtriple=arm-none-linux-gnueabi a.o –o out.so arm-none-linux-ld –shared a.o –o out.so

Together, We make the difference. The MCLinker Library ▪ Executable Programs –bin/ld.mcld –bin/ld.bcc ▪ Archive Library –lib/libmcld.a ▪ Headers –include/mcld/* include/mcld/*.hThe major interfaces include/mcld/ADT/Abstract data type. Fast hash table for huge amount of elements Binary tree Traits Misc. include/mcld/Support/Support libraries. Memory management layer. File system libraries

Together, We make the difference. Using MCLinker as a library ▪ Everything in MCLinker is in the mcld namespace ▪ Major interfaces are under the `mcld` directory #include #include #include #include #include using namespace mcld; int main(int argc, char* argv[]) { Initialize(); /** Add Linker, Module, IRBuilder, and LinkerConfig **/ Finalize(); }

Together, We make the difference. Link with MCLinker ▪ Use –lmcld linker flags LDFLAGS = ${LLVM_LDFLAGS} -lmcld

Together, We make the difference. Major Components in MCLinker ▪ Module consists of –the input tree, and –the fragment-reference graph ▪ LinkerConfig has –script options, and –general options ▪ IRBuilder builds up –The input tree, and –The fragment-reference graph ▪ Linker lowers IRs –Normalization –Resolve –Layout –Emission IRs Options Control of IR Control of Linking

Together, We make the difference. A Simplest Linker ▪ A Linker without any command line language ld –mtriple=arm-none-linux –o out.exe Error: no inputs mcld::Initialize() mcld::Module module("test"); mcld::LinkerConfig config("arm-none-linux”); // -mtriple=arm-none-linux mcld::Linker linker; linker.config(config); mcld::IRBuilder builder(module, config); if (linker.link(module, builder)) linker.emit("./out.exe"); // -o./out.exe mcld::Finalize();

Together, We make the difference. Setting Up General Options (1/2) ▪ To emit a shared library or an executable program mcld::LinkerConfig config("arm-none-linux”); ///< -mtriple=arm-none-linux config.setCodeGenType(LinkerConfig::DynObj); ///< --shared config.options().setSOName("libplasma.so"); ///< --soname=libplasma.so config.options().setBsymbolic(); ///< -Bsymbolic config.options().directories().insert(“/opt/lib”); /// -L/opt/lib

Together, We make the difference. Setting Up General Options (2/2) ▪ Most frequently used options are in class GeneralOptions MethodLinker OptionMeaning SearchDirs& directories()-LThe search pathes void setEntry(const std::string& pEntry) -entry [symbol]Set up the default entrance for an executable void addZOption(const mcld::ZOption& pOption); -z [description]The –z option void setStripDebug()-SStrip debug void setTrace()-tTrace normalization void setHashStyle(HashStyle pStyle) --hash-styleSet hash table to SysV or GNU

Together, We make the difference. mcld::Input ▪ A mcld::Input consists of –Type object file archive, shared object linker script group –Path/Name –A reference to an attribute set –MemoryArea high performance memory handler for file image –LDContext sections and symbols

Together, We make the difference. Read an Input File by IRBuilder ▪ mcld::IRBuilder provides a convenient way for creating the Input Tree or the Fragment-Reference graph ▪ mcld::IRBuilder::ReadInput() reads a file and append it into the input tree of a mcld::Module mcld::Module module("libplasma.so"); mcld::IRBuilder builder(module, config); // /opt/gcc/lib/crtbegin.so builder.ReadInput(”prolog", “/opt/gcc/lib/crtbegin.so”); // -lm –llog builder.ReadInput("m"); builder.ReadInput("log"); cerr << module.getInputTree().size() << end; ///< should be 3

Together, We make the difference. Change the Attribute Set ▪ Example – $ld./ a. o -- whole - archive -- start - group./ b. a./ c. a -- end - group -- no - whole - archive./ d. o./ e. o builder.ReadInput(”obj a", “./a.o”); builder.WholeAchieve(); builder.StartGroup(); builder.ReadInput(“archive b”, “./b.a”); builder.ReadInput(“archive c”, “./c.a”); builder.EndGroup(); builder.NoWholeArchive(); builder.ReadInput(“obj d”, “./d.o”); builder.ReadInput(“obj e”, “./e.o”);

Together, We make the difference. Traverse the input tree BinaryTree::dfs_iterator file = module.getInputTree().bfs_begin(); BinaryTree::dfs_iterator End = module.getInputTree().bfs_end(); while (file != End) { cerr name() << “; ”; } // print out: // archive a; archive b; obj e; obj d; obj a;

Together, We make the difference. Create A Customized mcld::Input ▪ IRBuilder::CreateInput() help developers to create a customized mcld::Input mcld::Module module("libplasma.so"); mcld::IRBuilder builder(module, config); //./plasma.o builder.CreateInput(“plasma object”, “./plasma.o”, mcld::Input::Object);

Together, We make the difference. Section Header and Data ▪ mcld::LDContext contains input symbols and sections ▪ mcld::LDSection is the section header ▪ mcld::SectionData is a container of input mcld::Fragment LDContext LDSection SectionData Fragment

Together, We make the difference. Create A Customized Section ▪ IRBuilder::CreateELFHeader() help developers to create a customized ELF header ▪ IRBuilder::CreateSectionData prepares a mcld::SectionData for the header ▪ IRBuilder::AppendFragment defines a isolated vertex which belongs to the mcld::SectionData /// [ 1].text PROGBITS AX LDSection* text = builder.CreateELFHeader(*input, ".text”, llvm::ELF::SHT_PROGBITS, llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR, 4); SectionData* text_data = builder.CreateSectionData(*text); static uint8_t text_content[] = { 0x00, 0x48, 0x2d, 0xe9, 0xfe, 0xff, 0xff, 0xeb}; Fragment* text_frag = builder.CreateRegion(text_content, 0x10); builder.AppendFragment(*text_frag, *text_data);

Together, We make the difference. Create A Symbol ▪ IRBuilder::AddSymbol() defines a new symbol to a fragment /// 6: FUNC GLOBAL DEFAULT 1 _Z1fv builder.AddSymbol(*input, ///< input file (optional) "_Z1fv", ResolveInfo::Function, ResolveInfo::Define, ResolveInfo::Global, 16, ///< size 0x0, ///< value text ); ///< fragment

Together, We make the difference. Create A Reference ▪ MCLinker will provide a reference rewriter to re-write the topology of the reference graph. –Already in the `diana` branch (under code reviewing) –That branch illustrates how to eliminate dead fragment by reachability ▪ Basic Interfaces –Define FRGraph::reference, plug and slot –Provide FRGraph::connect(plug, slot) to create a reference –Provide FRGraph::break(reference) to remove a reference

Together, We make the difference. Modify Module at different linking stages ▪ Modify mcld::Module between among stages –IRBuilder builder(module, config); –Linker::resolve() –Linker::layout() –Linker::emit(“out.so”)

Together, We make the difference. Connect with LLVM ▪ MCLinker provides mcld::raw_mem_ostream ▪ LLVM can use mcld::raw_mem_ostream as an output ▪ MCLinker can read mcld::raw_mem_ostream as an input mcld::raw_mem_ostream os; Target->createAsmStreamer(…, os, …); ///< LLVM Target builder.ReadInput(os);

Together, We make the difference. Conclusion ▪ We introduce MCLinker major components –Module –LinkerConfig –IRBuilder –Linker ▪ We illustrate how to –Append a input file in the input tree –Create sections in a customized input –Create symbols and relocations –Connect MCLinker and LLVM