Program Execution and ELF Files Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014 Abed Asi.

Slides:



Advertisements
Similar presentations
Hand-Held Devices and Embedded Systems Course Student: Tomás Sánchez López Student ID:
Advertisements

Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
Hello World!. PC / MS-DOS code segment para assume cs:code,ds:code org 0100h start: mov dx,offset message ;point to message mov ah,09h ;func# to printstring.
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
Linking & Loading CS-502 Operating Systems
Lecture 10: Linking and loading. Lecture 10 / Page 2AE4B33OSS 2011 Contents Linker vs. loader Linking the executable Libraries Loading executable ELF.
Linkers and Loaders 1 Linkers & Loaders – A Programmers Perspective.
Binary Loader What is done by binary loader? ● Read executable from the filesystem ● Parse the binary header ● Copy all segments into addresses specified.
Chapter 3 Memory Management. 3.1 From Programs To Address Space 3 steps to run the programs of an application – A Compiler translates the source code.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
Linking and Loading Fred Prussack CS 518. L&L: Overview Wake-up Questions Terms and Definitions / General Information LoadingLinking –Static vs. Dynamic.
Generating Programs and Linking Professor Rick Han Department of Computer Science University of Colorado at Boulder.
Practical Session 8 Computer Architecture and Assembly Language.
Protected Mode. Protected Mode (1 of 2) 4 GB addressable RAM –( to FFFFFFFFh) Each program assigned a memory partition which is protected from.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
Languages and tools. BY SA machine code.
Command line tools Manfred G. Grabherr. Overview -How do web-based tools work? -What is source code? -How to run things locally? -What is UNIX/Linux?
UNIX ELF File Format. Elf File Format The a.out format served the Unix community well for over 10 years. However, to better support cross-compilation,
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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
CS 3204 Operating Systems Godmar Back Lecture 11.
Introduction to Assembly Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
MIPS coding. SPIM Some links can be found such as:
Introduction to Assembly Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
CSU System Programming, NTNU CSIE1 / 99 Linkers and Libraries Advisor: Dr. Gwan-Hwan Hwang Lecturer: Che-Sheng Lin.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
Topic 2d High-Level languages and Systems Software
CSE451 Linking and Loading Autumn 2002 Gary Kimura Lecture #21 December 9, 2002.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Linking Ⅱ.
ELF binary # readelf -a foo.out ELF Header:
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Chapter 13 : Symbol Management in Linking
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
Different Types of Libraries
Assembly 08. Outline Local Labels Jump Lengths External Libraries Macros 1.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
The Assembly Process Computer Organization and Assembly Language: Module 10.
1 Linking. 2 Outline What is linking and why linking Complier driver Static linking Symbols & Symbol Table Suggested reading: 7.1~7.5.
CSc 453 Linking and Loading
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
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.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
Object Files & Linking. Object Sections Compiled code store as object files – Linux : ELF : Extensible Linking Format – Windows : PE : Portable Execution.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Lecture 3 Translation.
Slides adapted from Bryant and O’Hallaron
Computer Architecture and Assembly Language
Linking & Loading.
Program Execution in Linux
CS 5204 Operating Systems Linking and Loading Godmar Back.
CS-3013 Operating Systems C-term 2008
Topic 2e High-Level languages and Systems Software
Computer Architecture and Assembly Language
Linking & Loading CS-502 Operating Systems
Program Execution in Linux
Loaders and Linkers.
Linking & Loading CS-502 Operating Systems
Program Assembly.
Computer Architecture and System Programming Laboratory
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Computer Architecture and System Programming Laboratory
Presentation transcript:

Program Execution and ELF Files Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014 Abed Asi

 Runs programs – command line  Not the only program that runs other programs  make  gcc  and more …  How this happens ? Who is responsible for that?  Operating System  System call  exec family - execvp, execl, execv, … 2

 These functions  receive the path of the program executable file  receive a list of the program arguments  loads the program into memory, and run it …  Last lecture, fork( ) and exec( )  why these function are used together ? 3

 Unix has several different types of executable files  You are already familiar with some of them:  Binary files  Bash script  more ?  Are these files executed similarly by the OS ? 4

 Binary file  Compiled – intermediate binary  Loading data and code to memory  Moving control to the entry point  Running the machine-code  Scripts  No compilation  We don’t have the binary code nor the memory content  A specified program parses and runs the commands  Commands are interpreted line-by-line  How do we specify which interpreter runs the script ? 5

 The first line - #!/bin/sh  exec( ) uses this to determine the type of the executable  shebang is encountered  it is a script file  The first line contains the path of the relevant program too  What can we do with it ? 6

 No sanity checks for the shebang line  Every program/utility could appear there 7 #!/bin/cat Hello world #!/bin/rm ls -l

8

 ELF defines a format of executable binary files  There are three main types  Relocatable ▪ Created by compilers or assemblers. Need to be processed by the linker before running  Executable ▪ Have all relocation done and all symbol resolved except perhaps shared library symbols that must be resolved at run time  Shared Object ▪ Shared library containing both symbol information for the linker and directly runnable code for run time 9

 Compilers, assemblers, and linkers treat the file as a set of logical sections  The system loader treats the file as a set of segments 10  Sections are intended for further processing by a linker  Segments are intended to be mapped into memory

Program and section header table offsets

12 section.text global _start ; _start: ;tell linker entry point mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel section.data msg db 'Hello world!',0xa ;our dear string len equ $ - msg ;length of our dear string

13 Magic: 7f 45 4c Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Intel Version:0x1 Entry point address:0x Start of program headers: 52 (bytes into file) Start of section headers: 256 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 2 Size of section headers: 40 (bytes) Number of section headers: 7 Section header string table index: 4

 A relocatable or shared object file is a collection of sections  Each section contains a single type of information, such as program code, read-only data, read/write data, symbols  Every symbol’s address is defined relative to a section  For example, the entry point is relative to the code section 14

15 [Nr] Name Type Addr Off Size [ 0] NULL [ 1].text PROGBITS d [ 2].data PROGBITS a0 0000a e [ 3].comment PROGBITS ae 00001f [ 4].shstrtab STRTAB cd [ 5].symtab SYMTAB b0 [ 6].strtab STRTAB c

 An object file symbol table holds information needed to locate and relocate a program’s symbolic definition and references 16 Num: Value Size Type Bind Vis Ndx Name 0: NOTYPE LOCAL DEFAULT UND 1: FILE LOCAL DEFAULT ABS hello.asm 2: SECTION LOCAL DEFAULT 1 3: SECTION LOCAL DEFAULT 2 4: NOTYPE LOCAL DEFAULT 2 msg 5: e 0 NOTYPE LOCAL DEFAULT ABS len 6: e 0 NOTYPE LOCAL DEFAULT ABS len 7: NOTYPE GLOBAL DEFAULT 1 _start 8: ae 0 NOTYPE GLOBAL DEFAULT ABS __bss_start 9: ae 0 NOTYPE GLOBAL DEFAULT ABS _edata 10: b0 0 NOTYPE GLOBAL DEFAULT ABS _end

17

18