Creating a Shared Library How you can create and use your own object-code libraries within the Linux environment.

Slides:



Advertisements
Similar presentations
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Advertisements

Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
UEE072HM Linking HLL and ALP An example on ARM. Embedded and Real-Time Systems We will mainly look at embedded systems –Systems which have the computer.
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
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.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Chapter 3 Loaders and Linkers
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
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++
Beginning Assembly, Part 2 The Assembling! Poorly Presented by Gleep.
Linking and Loading Fred Prussack CS 518. L&L: Overview Wake-up Questions Terms and Definitions / General Information LoadingLinking –Static vs. Dynamic.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3.
1 Assemblers and Linkers Professor Jennifer Rexford COS 217.
What is Assembly Language? Introduction to the GNU/Linux assembler and linker for Intel Pentium processors.
1 Assemblers and Linkers CS Goals of This Lecture Compilation process  Compile, assemble, archive, link, execute Assembling  Representing instructions.
Run-Time Storage Organization
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
What is Assembly Language? Introduction to the GNU/Linux assembler and linker for Intel Pentium processors.
Practical Session 8 Computer Architecture and Assembly Language.
Software Development and Software Loading in Embedded Systems.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
6.828: PC hardware and x86 Frans Kaashoek
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
MIPS coding. SPIM Some links can be found such as:
 200 Total Points ◦ 74 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 36 Points Short Answer ◦ 30 Points Multiple Choice.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Lecture 7. Instructions and High-Level to Machine Code Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Lecture-1 Compilation process
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
RNJ 05/05/091 6 Further System Fundamentals (HL) ‏ 6.3 Operating Systems and Utility Software Linkers, Loaders and Library Managers.
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
The Development Process Compilation. Compilation - Dr. Craig A. Struble 2 Programming Process Problem Solving Phase We will spend significant time on.
C Programming Chapters 11, . . .
CSc 453 Linking and Loading
Practical Session 8. Position Independent Code- self sufficiency of combining program Position Independent Code (PIC) program has everything it needs.
Linking I Topics Assembly and symbol resolution Static linking Systems I.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language.
Operating Systems A Biswas, Dept. of Information Technology.
Object Files & Linking. Object Sections Compiled code store as object files – Linux : ELF : Extensible Linking Format – Windows : PE : Portable Execution.
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Lecture 3 Translation.
Instruction Set Architecture
Computer Science 210 Computer Organization
A bit of C programming Lecture 3 Uli Raich.
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
Homework In-line Assembly Code Machine Language
Program Execution in Linux
Assembly Language Programming V: In-line Assembly Code
Computer Science 210 Computer Organization
Computer Architecture and Assembly Language
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Assembly Language Programming II: C Compiler Calling Sequences
Memory Management Overview
The Assembly Language Level
CSE 303 Concepts and Tools for Software Development
Program Execution in Linux
Computer Architecture and System Programming Laboratory
Computer Architecture and Assembly Language
Run-time environments
Presentation transcript:

Creating a Shared Library How you can create and use your own object-code libraries within the Linux environment

Building an executable file source text compiler object code linker executable file Translates programming language statements into cpu’s machine-language instructions Adjusts any memory references to fit the Operating Sytem’s memory model

Example: source text in assembly.data msg:string“ Hello \n”.text main:movl$4, %eax movl$1, %ebx movl$msg, %ecx movl$8, %edx int$0x80 ret.globlmain

Compiling the source text $gcc –c hello.s; compile $ ld hello.o –o hello; link

Normally need a runtime library source text object file object code library executable file compiler linker A previously compiled collection of standard program functions

How to build/use an archive file $ gcc –c func1.c $ gcc –c func2.c $ ar cr myarchive.a func1.o func.o $ g++ myapp.cpp myarchive.a –o myapp

Static versus Dynamic Linking $ gcc –c hello.s $ ld –static hello.o –o hello or $ ld –shared hello.o –o hello

Smaller is more efficient objject file function library object file pointer static linking object file function library dynamic linking object file pointer shared function library executable files

Building a ‘Shared Library’ Functions must be ‘reentrant’ –This implies: No global variables Code must be ‘position-independent’ –Can’t jump or call to fixed addresses –Can’t access data at fixed locations

Command-formats For building the shared library: $ gcc –c –fPIC func.c $ gcc –shared –fPIC func.o –o libfunc.so For linking application with shared library: $ g++ app.cpp -oapp –L. –lfunc –Wl,-rpath,.

Command-line options You need the -L. option to tell the linker where to search the for your libxxx.so files You need the -l option to tell the linker which shared object files to link with first You need the -Wl option to tell gcc/g++ compilers to pass options on to the linker See the man pages for additional details

Class Exercise Compile the files ‘comb.c’ and ‘other.c’ Build a shared library containing both Compile the ‘uselib.cpp’ demo-program so it will be linked with your shared library Run the ‘uselib’ demo-program and turn in a printout that shows its output