CS 550 Operating Systems Spring Process I

Similar documents
Exercise Session 7 Computer Architecture and Systems Programming

Systems Programming and Computer Architecture ( ) Timothy Roscoe

C03c: Linkers and Loaders

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.

Lecture 16: Linking Computer Architecture and Systems Programming ( )

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

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

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

LINKING. Jo, Heeseung

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

Compiler Drivers = GCC

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

A Simplistic Program Translation Scheme

Computer Systems. Linking. Han, Hwansoo

Linking February 24, 2005

Lecture 12-13: Linking

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

Computer Systems Organization

COMPILING OBJECTS AND OTHER LANGUAGE IMPLEMENTATION ISSUES. Credit: Mostly Bryant & O Hallaron

Linking and Loading. CS61, Lecture 16. Prof. Stephen Chong October 25, 2011

Revealing Internals of Linkers. Zhiqiang Lin

Sungkyunkwan University

Link 2. Object Files

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

Linking Oct. 15, 2002

Link 2. Object Files

Example C Program. Linking CS Instructor: Sanjeev Se(a. int buf[2] = {1, 2}; extern int buf[]; int main() { swap(); return 0; }

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

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

Executables and Linking. CS449 Spring 2016

Assembly Language Programming Linkers

(Extract from the slides by Terrance E. Boult

Computer Organization: A Programmer's Perspective

E = 2 e lines per set. S = 2 s sets tag. valid bit B = 2 b bytes per cache block (the data) CSE351 Inaugural EdiNon Spring

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

ECE 471 Embedded Systems Lecture 4

ECE 598 Advanced Operating Systems Lecture 10

CS631 - Advanced Programming in the UNIX Environment

COS 318: Operating Systems

CS2141 Software Development using C/C++ Libraries

Linking. Today. Next time. Static linking Object files Static & dynamically linked libraries. Exceptional control flows

ECE 498 Linux Assembly Language Lecture 1

Executables and Linking. CS449 Fall 2017

CS240: Programming in C

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

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

Process Environment. Pradipta De

Virtual Memory Paging

Operating Systems CMPSC 473. Process Management January 29, Lecture 4 Instructor: Trent Jaeger

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

CS 201 Linking Gerson Robboy Portland State University

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory

CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri

Compiler, Assembler, and Linker

Cross Compiling. Real Time Operating Systems and Middleware. Luca Abeni

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

CS240: Programming in C. Lecture 2: Overview

u Linking u Case study: Library interpositioning

9/19/18. COS 318: Operating Systems. Overview. Important Times. Hardware of A Typical Computer. Today CPU. I/O bus. Network

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

Process Address Spaces and Binary Formats

ECE 598 Advanced Operating Systems Lecture 11

Department of Computer Science and Engineering Yonghong Yan

ECE 471 Embedded Systems Lecture 5

Operating Systems CS3502 Spring 2018

CNIT 127: Exploit Development. Ch 3: Shellcode. Updated

Soumava Ghosh The University of Texas at Austin

Intermediate Programming, Spring 2017*

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Outline. 1 Background. 2 ELF Linking. 3 Static Linking. 4 Dynamic Linking. 5 Summary. Linker. Various Stages. 1 Linking can be done at compile.

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

CS 550 Operating Systems Spring Process II

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

Embedded Systems Programming

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

Lecture 8: linking CS 140. Dawson Engler Stanford CS department

Reminder: compiling & linking

CSCI341. Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory

Week 5 Lecture 3. Compiler Errors

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

2012 LLVM Euro - Michael Spencer. lld. Friday, April 13, The LLVM Linker

Linking Oct. 26, 2009"

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

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

Today s Big Adventure

Main Memory. CISC3595, Spring 2015 X. Zhang Fordham University

EE458 - Embedded Systems Lecture 4 Embedded Devel.

Today s Big Adventure

Tools > Compiling & Debugging

CSE506: Operating Systems CSE 506: Operating Systems

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University

o Code, executable, and process o Main memory vs. virtual memory

CS 550 Operating Systems Spring Process III

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

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

CSE506: Operating Systems CSE 506: Operating Systems

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

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Transcription:

CS 550 Operating Systems Spring 2018 Process I 1

Process Informal definition: A process is a program in execution. Process is not the same as a program. Program is a passive entity stored in the disk Process is an actively executing entity Program is just one component of a process. 2

Programs and Processes Process The running instantiation of a program, stored in RAM Program An executable file in long-term storage One-to-many relationship between program and processes 3

Programs How is a program (i.e., an executable binary file) formatted? main.c int buf[2] = {1, 2}; int main() { swap(); return 0; } swap.c extern int buf[]; int *bufp0 = &buf[0]; static int *bufp1; void swap() { int temp; bufp1 = &buf[1]; temp = *bufp0; *bufp0 = *bufp1; *bufp1 = temp; } 4

Programs How is a program (i.e., an executable binary file) formatted? The compiler compiles source code into relocatable object files. The linker links all necessary relocatable object files into an executable object file (i.e., the program). 5

Static Linking Programs are translated and linked using a compiler driver: unix> gcc -O2 -g -o p main.c swap.c unix>./p main.c swap.c Source files Translators (cpp, cc1, as) main.o Linker (ld) Translators (cpp, cc1, as) swap.o Separately compiled (relocatable) object files p Fully linked program (executable object file) (contains code and data for all functions defined in main.c and swap.c) 6

Executable Object files Object file formats vary from system to system DOS: MZ executables (*.exe) Named after Mark Zbikowski, a DOS developer Windows Portable Executable (PE, PE32+) (*.exe) Modified version of Unix COFF executable format Mac OSX: Mach object file format (Mach-O) Unix/Linux: Executable and Linkable Format (ELF) 7

Executable and Linkable Format (ELF) Standard binary format for object files for Unix and Unix-like systems on x86. Originally proposed by AT&T System V Unix Later adopted by BSD Unix variants and Linux One unified format for Relocatable object files (.o), Executable object files (a.out) Shared object files (.so) Generic name: ELF binaries 8

ELF Object File Format Elf header Word size, byte ordering, file type (.o, exec,.so), machine type, etc. Segment header table Page size, virtual addresses memory segments (sections), segment sizes..text section Code.rodata section Read only data.data section Initialized global variables.bss section Uninitialized global variables Block Started by Symbol Better Save Space Has section header but occupies no space ELF header Segment header table (required for executables).text section.rodata section.data section.bss section.symtab section.rel.txt section.rel.data section.debug section Section header table 9 0

ELF Header oot@huicomputer1:/home/huilu/case1# readelf -h p ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x400430 Start of program headers: 64 (bytes into file) Start of section headers: 6784 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 9 Size of section headers: 64 (bytes) Number of section headers: 31 Section header string table index: 28 10

More Sources (ELF) ELF Wiki https://en.wikipedia.org/wiki/executable_and_link able_format ELF 101: https://linux-audit.com/elf-binaries-onlinux-understanding-and-analysis/ 11

Programs When you double-click on a program (or use command line), how does the OS turn the file on disk into a process? Load time The loader creates a process for the program, loads the program to RAM, or more precisely, to the address space of the process, and starts executing the first instruction of the program. 12

Loading executable object files p is not a built-in shell command shell assumes p is an executable object file shell invokes the loader (some memory-resident OS code) to run the program p. Unix/Linux programs can invoke loader by calling the execve function (introduced later). The loader copies the code and data in the executable object file from disk into memory, and then runs the program by jumping to its first instruction, or the entry point. This process of copying the program into memory and then running it is known as loading. 13

So what else constitutes a process? Memory space (static, dynamic) Procedure call stack Registers and counters : Program counter, Stack pointer, General purpose registers Open files, connections 14

References Chapter 4 of OSTEP book Chapter 2 of the Tanenbaum s book Man pages for different system calls Try man 2 <syscall_name> E.g. man 2 exec Syscalls are normally listed in section 2 of the man page Google for Linux source code 15

Backups 16