Compiler Drivers = GCC

Similar documents
CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

(Extract from the slides by Terrance E. Boult

CS 550 Operating Systems Spring Process I

Introduction Presentation A

LINKING. Jo, Heeseung

Systems Programming and Computer Architecture ( ) Timothy Roscoe

CS 33. Linkers. CS33 Intro to Computer Systems XXV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Executables and Linking. CS449 Fall 2017

CSE 2421: Systems I Low-Level Programming and Computer Organization. Linking. Presentation N. Introduction to Linkers

CS2141 Software Development using C/C++ Libraries

Linking. Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3. Instructor: Joanna Klukowska

Computer Systems. Linking. Han, Hwansoo

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp)

Link Edits and Relocatable Code

Linking Oct. 26, 2009"

Link 3. Symbols. Young W. Lim Mon. Young W. Lim Link 3. Symbols Mon 1 / 42

Computer Systems Organization

Executables and Linking. CS449 Spring 2016

Exercise Session 7 Computer Architecture and Systems Programming

Link 4. Relocation. Young W. Lim Thr. Young W. Lim Link 4. Relocation Thr 1 / 26

Linking Oct. 15, 2002

Link 4. Relocation. Young W. Lim Wed. Young W. Lim Link 4. Relocation Wed 1 / 22

Example C program. 11: Linking. Why linkers? Modularity! Static linking. Why linkers? Efficiency! What do linkers do? 10/28/2013

CS356: Discussion #8 Buffer-Overflow Attacks. Marco Paolieri

Machine Language, Assemblers and Linkers"

Generating Programs and Linking. Professor Rick Han Department of Computer Science University of Colorado at Boulder

A Simplistic Program Translation Scheme

Compiler Design IIIT Kalyani, West Bengal 1. Introduction. Goutam Biswas. Lect 1

Linking. Explain what ELF format is. Explain what an executable is and how it got that way. With huge thanks to Steve Chong for his notes from CS61.

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova

Assembly Language Programming Linkers

CS356: Discussion #7 Buffer Overflows. Marco Paolieri

Princeton University Computer Science 217: Introduction to Programming Systems. Machine Language

CIT 595 Spring System Software: Programming Tools. Assembly Process Example: First Pass. Assembly Process Example: Second Pass.

Computer Organization: A Programmer's Perspective

238P: Operating Systems. Lecture 7: Basic Architecture of a Program. Anton Burtsev January, 2018

CS 201 Linking Gerson Robboy Portland State University

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

Example C Program The course that gives CMU its Zip! Linking March 2, Static Linking. Why Linkers? Page # Topics

Systems Programming. Fatih Kesgin &Yusuf Yaslan Istanbul Technical University Computer Engineering Department 18/10/2005

Process Environment. Pradipta De

CS-220 Spring 2018 Test 2 Version Practice Apr. 23, Name:

CS377P Programming for Performance Leveraging the Compiler for Performance

Embedded Systems Programming

EL2310 Scientific Programming

Lecture 3: Instruction Set Architecture

Link 2. Object Files

C03c: Linkers and Loaders

Linking February 24, 2005

independent compilation and Make

2 Compiling a C program

COS 318: Operating Systems

Link 2. Object Files

Computer Systems C S Cynthia Lee

Compiler, Assembler, and Linker

get.c get.o extern int a[]; int get_a(int i) { return a[i]; }

3.3 Machine-Independent Loader Features

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Blossom Hands-on exercises for computer forensics and security. Buffer Overflow

Lecture 16: Linking Computer Architecture and Systems Programming ( )

Programming I Laboratory - lesson 01

EL2310 Scientific Programming

Princeton University Computer Science 217: Introduction to Programming Systems. A paradox. Machine Language. Machine language.

Program Translation. text. text. binary. binary. C program (p1.c) Compiler (gcc -S) Asm code (p1.s) Assembler (gcc or as) Object code (p1.

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Your first C and C++ programs

Program Translation. text. text. binary. binary. C program (p1.c) Compiler (gcc -S) Asm code (p1.s) Assembler (gcc or as) Object code (p1.

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

ELF (1A) Young Won Lim 10/22/14

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

ECE 3210 Laboratory 1: Develop an Assembly Program

Systems I. Linking II

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

From Code to Program: CALL Con'nued (Linking, and Loading)

CS 61C: Great Ideas in Computer Architecture CALL continued ( Linking and Loading)

Buffer Overflow Attack (AskCypert CLaaS)

CS240: Programming in C

12: Memory Management

Objectives. Chapter 2: Operating-System Structures. 2.1 Operating System Services

C: Program Structure. Department of Computer Science College of Engineering Boise State University. September 11, /13

Blanket Execution: Dynamic Similarity Testing for Program Binaries and Components

Embedded Systems. 2. Software Development. Lothar Thiele. Computer Engineering and Networks Laboratory

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University

Linker Puzzles The course that gives CMU its Zip! Linking Mar 4, A Simplistic Program Translation Scheme. A Better Scheme Using a Linker

Department of Computer Science and Engineering Yonghong Yan

CS429: Computer Organization and Architecture

CS240: Programming in C. Lecture 2: Overview

Problem 1 (Void * generics) (24 points) (suggested time: 30 minutes)

CS Programming In C

Essentials for Scientific Computing: Source Code, Compilation and Libraries Day 8

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

Course Information and Introduction

Midterm. Median: 56, Mean: "midterm.data" using 1:2 1 / 37

Chapter 2: System Structures

Introduction to Supercomputing

ELF (1A) Young Won Lim 3/24/16

CSE 351. Introduction & Course Tools

ECE 15B COMPUTER ORGANIZATION

gpio timer uart printf malloc keyboard fb gl console shell

COMP1917: Computing 1 1. Introduction

Transcription:

Compiler Drivers = GCC When you invoke GCC, it normally does preprocessing, compilation, assembly and linking, as needed, on behalf of the user accepts options and file names as operands % gcc O1 -g -o p main.c swap.c % man gcc Pre-processor (cpp).c to.i Compiler (cc1).i file to.s Assembler (as).s to relocatable object file.o Linker (ld) creates executable object file called a.out as default Compiler driver Loader the unix shell invokes a function in the OS to call the loader Copies the code and data in the executable file into memory Transfers control to the beginning of the program See slide #13 and #206 (3 times a charm?!) 394

Chp. 7 Linking building a program vs program execution which runs a program i.e. text file EFFICIENCY issue: Small change requires recompilation MODULARITY issue: hard to share common functions (i.e. printf) SOLUTION static LINKER like LAB4 Compile each C program separately to create.o file: % gcc c m.c % gcc c a.c Combined.o files into single executable, then run: % gcc m.o a.o o p % p 395

Types of object files Object files, created by the assembler and link editor, are binary representations of programs intended to be executed directly on a processor A relocatable object file holds code and data suitable for linking with other object files to create an executable or a shared object file. Each.o file is produced from exactly one source (.c) file An executable object file (default is a.out) holds code and data that can be copied directly into memory then executed. A shared object file (.so file) is a special type of relocatable object file that can be loaded into memory and linked dynamically, at either load time or run time. Load time: the link editor processes the shared object file with other relocatable and shared object files to create another object file Run time: the dynamic linker combines it with an executable file and other shared objects to create a process image 396

Hello World revisited #include <stdio.h> int main() { printf("hello World"); return 0; } Object file has not been linked yet 0000000000000000 <main>: 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: bf 00 00 00 00 mov $0x0,%edi 9: b8 00 00 00 00 mov $0x0,%eax e: e8 00 00 00 00 callq 13 <main+0x13> 13: b8 00 00 00 00 mov $0x0,%eax 18: c9 leaveq 19: c3 retq 00000000004004cc <main>: 4004cc: 55 push %rbp 4004cd: 48 89 e5 mov %rsp,%rbp 4004d0: bf dc 05 40 00 mov $0x4005dc,%edi 4004d5: b8 00 00 00 00 mov $0x0,%eax 4004da: e8 e1 fe ff ff callq 4003c0 <printf@plt> 4004df: b8 00 00 00 00 mov $0x0,%eax 4004e4: c9 leaveq 4004e5: c3 retq Relocatable vs Executable object code 397

Static linking What do linkers do? Step 1. Symbol resolution Programs define and reference symbols (variables and functions): void swap() { } swap(); int *xp = &x; // define symbol swap // reference to a symbol swap // define symbol xp, reference x Symbol definitions are stored (by compiler) in a symbol table A symbol table is an array of structs Each entry includes name, size, and location of symbol Linker associates each symbol reference with exactly one symbol definition 398

Static linking What do linkers do? Step 2. Relocation Merges separate code and data sections into single sections Relocates symbols from their relative locations in the.o files to their final absolute memory locations in the executable. Updates all references to these symbols to reflect their new positions. 399

Object File Format/Organization The object file formats provide parallel views of a file's contents, reflecting the differing needs of those activities ELF header (executable and linkable format) resides at the beginning and holds a road map describing the file's organization. Program header table Tells the system how to create a process image Files used to build a process image (execute a program) must have a program header table; relocatable files do not need one. 400

Object File Format/Organization (cont) Section header table Contains information describing the file's sections Every section has an entry in the table each entry gives information such as the section name, the section size, and so on. Sections Hold the bulk of object file information for the linking view: instructions, data, symbol table, relocation information, etc. Files used during linking must have a section header table; other object files may or may not have one. FYI: Although the figure shows the program header table immediately after the ELF header, and the section header table following the sections, actual files may differ. Moreover, sections and segments have no specified order. Only the ELF header has a fixed position in the file. 401

ELF Object File Format (details) 402

ELF Object File Format (cont) 403

Processes (section 8.2) What is a process? Provides each program with the illusion that is has exclusive use of the processor and memory What is a process image? Process address space 404