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

Size: px
Start display at page:

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

Transcription

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

2 Outline How to assemble and link nasm ld gcc Debugging Using gdb; breakpoints,registers, memory Objdump, readelf,nm,ldd

3 Definition Compilers and assemblers create object files containing the generated binary code and data for a source file. Linkers combine multiple object files into one, loaders take object files and load them into memory. (In an integrated programming environment, the compilers, assemblers, and linkers are run implicitly when the user tells it to build a program, but they're there under the covers.)

4 Example: Hello world segment.data msg db "Hello, world!",10 len equ $ - msg segment.text global main main: mov eax,4 mov ebx,1 mov ecx,msg mov edx,len int 80h write syscal stdout address of output buffer length of buffer mov eax,1 mov ebx,0 int 80h exit syscal success

5 Assembling Hello.asm nasm - the Netwide Assembler, a portable 80x86 assembler nasm -f elf hello.asm To change the output file name use the -o command nasm -f elf hello.asm merhaba.o The -f elf option tells nasm to output the object code in the Executable and Linking Format (ELF) that Linux uses. The object code is still not executable.

6 Linking Hello.asm To create an executable file, we have to link it using a linker. We can use the GNU linker ld to link our object file: ld hello.o -o hello However, this will result in the following warning: ld: warning: cannot find entry symbol _start; defaulting to ld searches for a _start label to use as the entry point of the linked program. Since our entry point is not _start but main instead

7 Linking Hello.asm we have to tell the ld use the label main as the entry point. ld hello.o -o hello -e main Let s execute the program examine listing file (little endianness) A listing file can be created by nasm for the assembled code by using the -l option: nasm -f elf hello.asm -l hello.lis The original source is displayed on the right hand side and the generated code is shown in hex on the left.

8 Examining the.lis file B mov eax,4 Here we can see that the machine code for the mov eax instruction is B8. The value next to it correspond to the immediate addressed parameter 4, but as we can see It is stored in 32 bits and stored as little endian. This is because our system is a 32 bit little endian system (Intel)

9 Differences between ld and gcc: entry points, size We can also use the GNU C compiler gcc to link the object file: gcc hello.o -o hello Note that gcc is not a linker but a compiler gcc is able to the determine the type of its input files and take appropriate actions to produce the executable gcc will try to invoke the linker ld in the background to generate the executable Compile hello.c and compare the file sizes

10 Differences between ld and gcc: entry points, size gcc links the object files to the standard C runtime library by default. Linking to the standard C runtime library result in an increase in the size of the executable. there is a label _start in one of the standard C runtime library object files ld does not complain about the entry point. (The _start function in the standard C runtime library is responsible for initializing the argc and argv variables for the main function of the C programs.)

11 Russian peasant method of multiplication Write the operands on top of two columns. At each step, divide the number on the first column by two and multiply the number on the second column by two. Ignore the remainders of division operations. Each time you obtain an odd number on the first column, add the number on the second column to the result. Stop when the number on the first column becomes 0.

12 Russian peasant method of multiplication Example: Multiply 92 by = = =3404 0

13 Russian peasant method of multiplication Write a C program. The main function should read the values from the keyboard, multiply them using the assembly function and display the result on the screen solution: rusmain.c Write a function in Intel assembly that multiplies its two operands using the algorithm described above and returns the result solution: russian.asm

14 Russian peasant method of multiplication Replace the call to the assembler function by appropriate inline assembly instructions that implement the described multiplication algorithm solution: rusinl.c Note That AT&T syntax is used in rusinl.c how to assemble/link nasm -f elf -g russian.asm -o russian.o Compiling rusmain.c: gcc -c -g rusmain.c -o rusmain.o Linking the object files russian.o and rusmain.o to produce russian executable: gcc -g russian.o rusmain.o -o russian

15 Debugging In order to debug the executable file; -g is used during compiling and linking gdb russian Add breakpoints to program break main break russian run info register trace the registers and program

16 Object File Formats MS-DOS.COM files A.COM file literally consists of nothing other than binary code Loaded to memory. Segments adjusted and Run If the program doesn t fit into segment fix up needed

17 Object File Formats Unix a.out files Computers with hardware memory relocation usually create a new process with an empty address space for each newly run program, in which case programs can be linked to start at a fixed address and require no relocation at load time. The Unix a.out object format handles this situation a.out header text section data section other section

18 a.out Header int a_magic; // magic number int a_text; // text segment size int a_data; // initialized data size int a_bss; // uninitialized data size int a_syms; // symbol table size int a_entry; // entry point int a_trsize; // text relocation size int a_drsize; // data relocation size

19 Object File Formats COFF (Common Object File Format )something better to support cross-compilation, dynamic linking and other modern system features Time Sharing Problem UNIX ELF (Executable & Linking Format) ELF files come in three slightly different flavors: relocatable, executable, and shared object. Relocatable files are created by compilers and assemblers but need to be processed by the linker before running.

20 Object File Formats Executable: All relocations are done, all symbols are resolved except shared library symbols at runtime Shared object: Symbol info + runnable code ELF Summary Complex but good Flexible Relocatable,Supports C++ Efficient Executable format for V.M. with dynamic linking Cross Compilation, cross linking enabled

21 Inspecting the Object File After Compiling objdump : display information from object files objdump -d rusmain.o Note that the address of the call function is dummy and the address of the main is objdump -d russian.o objdump -d russian The address of the printf call is 80482ec and the new address of the main is e0

22 Inspecting the Object File After Compiling readelf - Displays information about ELF files readelf -a russian.o readelf -a russian nm - list symbols from object files nm russian.o nm russian

23 Static Linking gcc -static rusmain.o russian.o -o rus_static Let s look at the file size of the rus_static: ll -h 477K, Isn t it too big? Why? objdump -d rus_static strace - trace system calls and signals strace./russian ltrace - A library call tracer ltrace./russian

Assembly Language Programming Debugging programs

Assembly Language Programming Debugging programs Assembly Language Programming Debugging programs November 18, 2017 Debugging programs During the development and investigation of behavior of system programs various tools are used. Some utilities are

More information

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

ELF (1A) Young Won Lim 10/22/14 ELF (1A) Copyright (c) 2010-2014 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Executables and Linking. CS449 Fall 2017

Executables and Linking. CS449 Fall 2017 Executables and Linking CS449 Fall 2017 Remember External Linkage Scope? #include int global = 0; void foo(); int main() { } foo(); printf( global=%d\n, global); return 0; extern int

More information

Executables and Linking. CS449 Spring 2016

Executables and Linking. CS449 Spring 2016 Executables and Linking CS449 Spring 2016 Remember External Linkage Scope? #include int global = 0; void foo(); int main() { foo(); printf( global=%d\n, global); return 0; } extern int

More information

A Real Object File Format

A Real Object File Format A Real Object File Format Computer Science and Engineering College of Engineering The Ohio State University Lecture 28 Linking and Loading in Practice Real object files have multiple segments Text: read-only

More information

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

CNIT 127: Exploit Development. Ch 3: Shellcode. Updated CNIT 127: Exploit Development Ch 3: Shellcode Updated 1-30-17 Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object files strace System Call Tracer Removing

More information

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

238P: Operating Systems. Lecture 7: Basic Architecture of a Program. Anton Burtsev January, 2018 238P: Operating Systems Lecture 7: Basic Architecture of a Program Anton Burtsev January, 2018 What is a program? What parts do we need to run code? Parts needed to run a program Code itself By convention

More information

Compilation, Disassembly, and Profiling (in Linux)

Compilation, Disassembly, and Profiling (in Linux) Compilation, Disassembly, and Profiling (in Linux) CS 485: Systems Programming Spring 2016 Instructor: Neil Moore 1 Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc O1 p1.c

More information

Assembly basics CS 2XA3. Term I, 2017/18

Assembly basics CS 2XA3. Term I, 2017/18 Assembly basics CS 2XA3 Term I, 2017/18 Outline What is Assembly Language? Assemblers NASM Program structure I/O First program Compiling Linking What is Assembly Language? In a high level language (HLL),

More information

Lecture 2 Assembly Language

Lecture 2 Assembly Language Lecture 2 Assembly Language Computer and Network Security 9th of October 2017 Computer Science and Engineering Department CSE Dep, ACS, UPB Lecture 2, Assembly Language 1/37 Recap: Explorations Tools assembly

More information

CS527 Software Security

CS527 Software Security Reverse Engineering Purdue University, Spring 2018 Basics: encodings Code is data is code is data Learn to read hex numbers: 0x38 == 0011'1000 Python: hex(int('00111000', 2)) Remember common ASCII characters

More information

Assembly Language Programming Linkers

Assembly Language Programming Linkers Assembly Language Programming Linkers November 14, 2017 Placement problem (relocation) Because there can be more than one program in the memory, during compilation it is impossible to forecast their real

More information

Machine Language, Assemblers and Linkers"

Machine Language, Assemblers and Linkers Machine Language, Assemblers and Linkers 1 Goals for this Lecture Help you to learn about: IA-32 machine language The assembly and linking processes 2 1 Why Learn Machine Language Last stop on the language

More information

C03c: Linkers and Loaders

C03c: Linkers and Loaders CISC 3320 MW3 C03c: Linkers and Loaders Hui Chen Department of Computer & Information Science CUNY Brooklyn College 2/4/2019 CUNY Brooklyn College: CISC 3320 OS 1 Outline Linkers and linking Loaders and

More information

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

CMSC Lecture 03. UMBC, CMSC313, Richard Chang CMSC Lecture 03 Moore s Law Evolution of the Pentium Chip IA-32 Basic Execution Environment IA-32 General Purpose Registers Hello World in Linux Assembly Language Addressing Modes UMBC, CMSC313, Richard

More information

Computer Systems Organization

Computer Systems Organization Computer Systems Organization 1 Outline 2 A software view User Interface 3 How it works 4 The gcc compilation system 5 The gcc compilation system hello.c (source code) Pre-processor (cpp) hello.i (modified

More information

Compila(on, Disassembly, and Profiling

Compila(on, Disassembly, and Profiling Compila(on, Disassembly, and Profiling (in Linux) CS 485: Systems Programming Fall 2015 Instructor: James Griffioen 1 Recall the compila(on process/steps 2 Turning C into Object Code Code in files p1.c

More information

M2 Instruction Set Architecture

M2 Instruction Set Architecture M2 Instruction Set Architecture Module Outline Addressing modes. Instruction classes. MIPS-I ISA. Translating and starting a program. High level languages, Assembly languages and object code. Subroutine

More information

ALT-Assembly Language Tutorial

ALT-Assembly Language Tutorial ALT-Assembly Language Tutorial ASSEMBLY LANGUAGE TUTORIAL Let s Learn in New Look SHAIK BILAL AHMED i A B O U T T H E T U TO R I A L Assembly Programming Tutorial Assembly language is a low-level programming

More information

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

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3 Hello, World! in C Johann Myrkraverk Oskarsson October 23, 2018 Contents 1 The Quintessential Example Program 1 I Printing Text 2 II The Main Function 3 III The Header Files 4 IV Compiling and Running

More information

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems Programs CSCI 4061 Introduction to Operating Systems C Program Structure Libraries and header files Compiling and building programs Executing and debugging Instructor: Abhishek Chandra Assume familiarity

More information

CS 550 Operating Systems Spring Process I

CS 550 Operating Systems Spring Process I 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

More information

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

ELF (1A) Young Won Lim 3/24/16 ELF (1A) Copyright (c) 21-216 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

EE458 - Embedded Systems Lecture 4 Embedded Devel.

EE458 - Embedded Systems Lecture 4 Embedded Devel. EE458 - Embedded Lecture 4 Embedded Devel. Outline C File Streams References RTC: Chapter 2 File Streams man pages 1 Cross-platform Development Environment 2 Software available on the host system typically

More information

Problem Set 1: Unix Commands 1

Problem Set 1: Unix Commands 1 Problem Set 1: Unix Commands 1 WARNING: IF YOU DO NOT FIND THIS PROBLEM SET TRIVIAL, I WOULD NOT RECOMMEND YOU TAKE THIS OFFERING OF 300 AS YOU DO NOT POSSESS THE REQUISITE BACKGROUND TO PASS THE COURSE.

More information

System calls and assembler

System calls and assembler System calls and assembler Michal Sojka sojkam1@fel.cvut.cz ČVUT, FEL License: CC-BY-SA 4.0 System calls (repetition from lectures) A way for normal applications to invoke operating system (OS) kernel's

More information

CS354 gdb Tutorial Written by Chris Feilbach

CS354 gdb Tutorial Written by Chris Feilbach CS354 gdb Tutorial Written by Chris Feilbach Purpose This tutorial aims to show you the basics of using gdb to debug C programs. gdb is the GNU debugger, and is provided on systems that

More information

ASSEMBLY - QUICK GUIDE ASSEMBLY - INTRODUCTION

ASSEMBLY - QUICK GUIDE ASSEMBLY - INTRODUCTION ASSEMBLY - QUICK GUIDE http://www.tutorialspoint.com/assembly_programming/assembly_quick_guide.htm Copyright tutorialspoint.com What is Assembly Language? ASSEMBLY - INTRODUCTION Each personal computer

More information

Practical Malware Analysis

Practical Malware Analysis Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the

More information

ECE 3210 Laboratory 1: Develop an Assembly Program

ECE 3210 Laboratory 1: Develop an Assembly Program ECE 3210 Laboratory 1: Develop an Assembly Program Spring 2018 1 Objective To become familiar with the development system s software: screen editor, assembler, linker, and debugger. After finishing this

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer About the Tutorial Assembly language is a low-level programming language for a computer or other programmable device specific to a particular computer architecture in contrast to most high-level programming

More information

Department of Computer Science and Engineering Yonghong Yan

Department of Computer Science and Engineering Yonghong Yan Appendix A and Chapter 2.12: Compiler, Assembler, Linker and Program Execution CSCE 212 Introduction to Computer Architecture, Spring 2019 https://passlab.github.io/csce212/ Department of Computer Science

More information

Compiler Drivers = GCC

Compiler Drivers = GCC 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

More information

Lecture 4 Processes. Dynamic Analysis. GDB

Lecture 4 Processes. Dynamic Analysis. GDB Lecture 4 Processes. Dynamic Analysis. GDB Computer and Network Security 23th of October 2017 Computer Science and Engineering Department CSE Dep, ACS, UPB Lecture 4, Processes. Dynamic Analysis. GDB 1/45

More information

Embedded Systems Programming

Embedded Systems Programming Embedded Systems Programming ES Development Environment (Module 3) Yann-Hang Lee Arizona State University yhlee@asu.edu (480) 727-7507 Summer 2014 Embedded System Development Need a real-time (embedded)

More information

ECE 471 Embedded Systems Lecture 4

ECE 471 Embedded Systems Lecture 4 ECE 471 Embedded Systems Lecture 4 Vince Weaver http://www.eece.maine.edu/ vweaver vincent.weaver@maine.edu 12 September 2013 Announcements HW#1 will be posted later today For next class, at least skim

More information

Laboratory 1 Semester 1 11/12

Laboratory 1 Semester 1 11/12 CS2106 National University of Singapore School of Computing Laboratory 1 Semester 1 11/12 MATRICULATION NUMBER: In this lab exercise, you will get familiarize with some basic UNIX commands, editing and

More information

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

Cross Compiling. Real Time Operating Systems and Middleware. Luca Abeni Cross Compiling Real Time Operating Systems and Middleware Luca Abeni luca.abeni@unitn.it The Kernel Kernel OS component interacting with hardware Runs in privileged mode (Kernel Space KS) User Level Kernel

More information

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

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 Chapter 1 Program Structure In the beginning there were 0s and 1s. GRR 1.1 Introduction In this chapter we will talk about memory: bits, bytes and how data is represented in the computer. We will also

More information

ECE 498 Linux Assembly Language Lecture 1

ECE 498 Linux Assembly Language Lecture 1 ECE 498 Linux Assembly Language Lecture 1 Vince Weaver http://www.eece.maine.edu/ vweaver vincent.weaver@maine.edu 13 November 2012 Assembly Language: What s it good for? Understanding at a low-level what

More information

CS 107 Lecture 18: GCC and Make

CS 107 Lecture 18: GCC and Make S 107 Lecture 18: G and Make Monday, March 12, 2018 omputer Systems Winter 2018 Stanford University omputer Science Department Lecturers: Gabbi Fisher and hris hute Today's Topics 1. What really happens

More information

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization Spring 2013 CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization Kitty Reeves TWRF 8:00-8:55am 1 Compiler Drivers = GCC When you invoke GCC, it normally does preprocessing,

More information

Reviewing gcc, make, gdb, and Linux Editors 1

Reviewing gcc, make, gdb, and Linux Editors 1 Reviewing gcc, make, gdb, and Linux Editors 1 Colin Gordon csgordon@cs.washington.edu University of Washington CSE333 Section 1, 3/31/11 1 Lots of material borrowed from 351/303 slides Colin Gordon (University

More information

CSC 405 Computer Security Shellcode

CSC 405 Computer Security Shellcode CSC 405 Computer Security Shellcode Alexandros Kapravelos akaprav@ncsu.edu Attack plan Attack code Vulnerable code xor ebx, ebx xor eax, eax mov ebx,edi mov eax,edx sub eax,0x388 Vulnerable code xor ebx,

More information

Università Ca Foscari Venezia

Università Ca Foscari Venezia Stack Overflow Security 1 2018-19 Università Ca Foscari Venezia www.dais.unive.it/~focardi secgroup.dais.unive.it Introduction Buffer overflow is due to careless programming in unsafe languages like C

More information

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION ECOM 2325 Computer Organization and Assembly Language Instructor: Ruba A.Salamah INTRODUCTION Overview Welcome to ECOM 2325 Assembly-, Machine-, and High-Level Languages Assembly Language Programming Tools

More information

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

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova Linking and Loading ICS312 - Spring 2010 Machine-Level and Systems Programming Henri Casanova (henric@hawaii.edu) The Big Picture High-level code char *tmpfilename; int num_schedulers=0; int num_request_submitters=0;

More information

Basic Assembly. Ned Nedialkov. McMaster University Canada. SE 3F03 January 2014

Basic Assembly. Ned Nedialkov. McMaster University Canada. SE 3F03 January 2014 Basic Assembly Ned Nedialkov McMaster University Canada SE 3F03 January 2014 Outline Assemblers Basic instructions Program structure I/O First program Compiling Linking c 2013 14 Ned Nedialkov 2/9 Assemblers

More information

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

Midterm. Median: 56, Mean: midterm.data using 1:2 1 / 37 30 Midterm "midterm.data" using 1:2 25 20 15 10 5 0 0 20 40 60 80 100 Median: 56, Mean: 53.13 1 / 37 Today s Big Adventure f.c gcc f.s as f.o c.c gcc c.s as c.o ld a.out How to name and refer to things

More information

Reversing. Time to get with the program

Reversing. Time to get with the program Reversing Time to get with the program This guide is a brief introduction to C, Assembly Language, and Python that will be helpful for solving Reversing challenges. Writing a C Program C is one of the

More information

CS2141 Software Development using C/C++ Libraries

CS2141 Software Development using C/C++ Libraries CS2141 Software Development using C/C++ Compilation and linking /* p1.c */ int x; int z; main() { x=0; z=0; printf("f(3)=%d x=%d z=%d\n",f(3),x,z); } Code for int f(int) not available yet, nor printf()

More information

Introduction to 8086 Assembly

Introduction to 8086 Assembly Introduction to 8086 Assembly Lecture 13 Inline Assembly Inline Assembly Compiler-dependent GCC -> GAS (the GNU assembler) Intel Syntax => AT&T Syntax Registers: eax => %eax Immediates: 123 => $123 Memory:

More information

Assembly Language. Assembly language for x86 compatible processors using GNU/Linux operating system

Assembly Language. Assembly language for x86 compatible processors using GNU/Linux operating system Assembly Language Assembly language for x86 compatible processors using GNU/Linux operating system x86 refers to the instruction set architecture in most personal computers Derives from model numbers ending

More information

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

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp) A software view User Interface Computer Systems MTSU CSCI 3240 Spring 2016 Dr. Hyrum D. Carroll Materials from CMU and Dr. Butler How it works hello.c #include int main() { printf( hello, world\n

More information

Today s Big Adventure

Today s Big Adventure Today s Big Adventure - How to name and refer to things that don t exist yet - How to merge separate name spaces into a cohesive whole Readings - man a.out & elf on a Solaris machine - run nm or objdump

More information

Today s Big Adventure

Today s Big Adventure 1/34 Today s Big Adventure - How to name and refer to things that don t exist yet - How to merge separate name spaces into a cohesive whole Readings - man a.out & elf on a Solaris machine - run nm or objdump

More information

CNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux

CNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux CNIT 127: Exploit Development Ch 2: Stack Overflows in Linux Stack-based Buffer Overflows Most popular and best understood exploitation method Aleph One's "Smashing the Stack for Fun and Profit" (1996)

More information

W4118: PC Hardware and x86. Junfeng Yang

W4118: PC Hardware and x86. Junfeng Yang W4118: PC Hardware and x86 Junfeng Yang A PC How to make it do something useful? 2 Outline PC organization x86 instruction set gcc calling conventions PC emulation 3 PC board 4 PC organization One or more

More information

Soumava Ghosh The University of Texas at Austin

Soumava Ghosh The University of Texas at Austin Soumava Ghosh The University of Texas at Austin Agenda Overview of programs that perform I/O Linking, loading and the x86 model Modifying programs to perform I/O on the x86 model Interpreting and loading

More information

How Compiling and Compilers Work

How Compiling and Compilers Work How Compiling and Compilers Work Dr. Axel Kohlmeyer Research Professor, Department of Mathematics Associate Director, Institute for Computational Science Assistant Vice President for High-Performance Computing

More information

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

9/19/18. COS 318: Operating Systems. Overview. Important Times. Hardware of A Typical Computer. Today CPU. I/O bus. Network Important Times COS 318: Operating Systems Overview Jaswinder Pal Singh and a Fabulous Course Staff Computer Science Department Princeton University (http://www.cs.princeton.edu/courses/cos318/) u Precepts:

More information

Operating Systems. Objective

Operating Systems. Objective Operating Systems Project #1: Introduction & Booting Project #1: Introduction & Booting Objective Background Tools Getting Started Booting bochs The Bootloader Assembling the Bootloader Disk Images A Hello

More information

Teensy Tiny ELF Programs

Teensy Tiny ELF Programs Teensy Tiny ELF Programs inspired by Brian Raiter Roland Hieber Stratum 0 e. V. March 15, 2013 1 / 14 Hello World # include int main ( int argc, char ** argv ) { printf (" Hello World!\n"); return

More information

COS 318: Operating Systems

COS 318: Operating Systems COS 318: Operating Systems Overview Kai Li Computer Science Department Princeton University (http://www.cs.princeton.edu/courses/cos318/) Important Times Lectures 9/20 Lecture is here Other lectures in

More information

Compiler construction. x86 architecture. This lecture. Lecture 6: Code generation for x86. x86: assembly for a real machine.

Compiler construction. x86 architecture. This lecture. Lecture 6: Code generation for x86. x86: assembly for a real machine. This lecture Compiler construction Lecture 6: Code generation for x86 Magnus Myreen Spring 2018 Chalmers University of Technology Gothenburg University x86 architecture s Some x86 instructions From LLVM

More information

This is an example C code used to try out our codes, there several ways to write this but they works out all the same.

This is an example C code used to try out our codes, there several ways to write this but they works out all the same. ...._ _... _.;_/ [_) (_]\_ [ )(_](_. \.net._ "LINUX SHELLCODING REFERENCE" Author: Nexus Email: nexus.hack@gmail.com Website: http://www.playhack.net Introduction ------------- One of the most important

More information

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

2012 LLVM Euro - Michael Spencer. lld. Friday, April 13, The LLVM Linker lld Friday, April 13, 2012 The LLVM Linker What is lld? A system linker Produce final libraries and executables, no other tools or runtime required Understands platform ABI What is lld? A system linker

More information

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

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University COS 318: Operating Systems Overview Andy Bavier Computer Science Department Princeton University http://www.cs.princeton.edu/courses/archive/fall10/cos318/ Logistics Precepts: Tue: 7:30pm-8:30pm, 105 CS

More information

Mitchell Adair January, 2014

Mitchell Adair January, 2014 Mitchell Adair January, 2014 Know Owen from our time at Sandia National Labs Currently work for Raytheon Founded UTDallas s Computer Security Group (CSG) in Spring 2010 Reversing, binary auditing, fuzzing,

More information

ECE 471 Embedded Systems Lecture 8

ECE 471 Embedded Systems Lecture 8 ECE 471 Embedded Systems Lecture 8 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 21 September 2018 Announcements HW#2 was due HW#3 will be posted today. Work in groups? Note

More information

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c How to learn C? CSCI [4 6]730: A C Refresher or Introduction Hello Word! ~/ctutorial/ In addition to syntax you need to learn: the Tools. the Libraries. And the Documentation (how to access) Practice on

More information

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated CNIT 127: Exploit Development Ch 1: Before you begin Updated 1-14-16 Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend, such as Denial

More information

Sistemi Operativi. Lez. 16 Elementi del linguaggio Assembler AT&T

Sistemi Operativi. Lez. 16 Elementi del linguaggio Assembler AT&T Sistemi Operativi Lez. 16 Elementi del linguaggio Assembler AT&T Data Sizes Three main data sizes Byte (b): 1 byte Word (w): 2 bytes Long (l): 4 bytes Separate assembly-language instructions E.g., addb,

More information

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015 CS165 Computer Security Understanding low-level program execution Oct 1 st, 2015 A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns

More information

CSE 351. GDB Introduction

CSE 351. GDB Introduction CSE 351 GDB Introduction Lab 2 Out either tonight or tomorrow Due April 27 th (you have ~12 days) Reading and understanding x86_64 assembly Debugging and disassembling programs Today: General debugging

More information

CS/COE 0449 term 2174 Lab 5: gdb

CS/COE 0449 term 2174 Lab 5: gdb CS/COE 0449 term 2174 Lab 5: gdb What is a debugger? A debugger is a program that helps you find logical mistakes in your programs by running them in a controlled way. Undoubtedly by this point in your

More information

Object Files. An Overview of. And Linking. Harry H. Porter III. Goals of this Paper. Portland State University cs.pdx.edu/~harry.

Object Files. An Overview of. And Linking. Harry H. Porter III. Goals of this Paper. Portland State University cs.pdx.edu/~harry. An Overview of Object Files And Linking Goals of this Paper Audience: CS-201 students Coverage: Compiling Linking Object files External Symbols Relocatable Code Segments (.text,.data.,.bss) Harry H. Porter

More information

Making things work as expected

Making things work as expected Making things work as expected System Programming Lab Maksym Planeta Björn Döbel 20.09.2018 Table of Contents Introduction Hands-on Tracing made easy Dynamic intervention Compiler-based helpers The GNU

More information

Compiler, Assembler, and Linker

Compiler, Assembler, and Linker Compiler, Assembler, and Linker Minsoo Ryu Department of Computer Science and Engineering Hanyang University msryu@hanyang.ac.kr What is a Compilation? Preprocessor Compiler Assembler Linker Loader Contents

More information

Unix and C Program Development SEEM

Unix and C Program Development SEEM Unix and C Program Development SEEM 3460 1 Operating Systems A computer system cannot function without an operating system (OS). There are many different operating systems available for PCs, minicomputers,

More information

Outline. Unresolved references

Outline. Unresolved references Outline CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 36: Linking and Loading 21 Nov 11 Static linking Object files Libraries Shared libraries Relocatable Dynamic linking explicit

More information

HOW TO USE CODE::BLOCKS IDE FOR COMPUTER PROGRAMMING LABORATORY SESSIONS

HOW TO USE CODE::BLOCKS IDE FOR COMPUTER PROGRAMMING LABORATORY SESSIONS HOW TO USE CODE::BLOCKS IDE FOR COMPUTER PROGRAMMING LABORATORY SESSIONS INTRODUCTION A program written in a computer language, such as C/C++, is turned into executable using special translator software.

More information

why we shouldn t use assembly compilers generate pre8y fast, efficient code tedious, easy to screw up not portable

why we shouldn t use assembly compilers generate pre8y fast, efficient code tedious, easy to screw up not portable chapter 3 part 1 1 why we shouldn t use assembly compilers generate pre8y fast, efficient code tedious, easy to screw up not portable 2 why you shouldn t use assembly and for that ma8er, why for a lot

More information

A tale of ELFs and DWARFs

A tale of ELFs and DWARFs A tale of ELFs and DWARFs A glimpse into the world of linkers, loaders and binary formats Volker Krause vkrause@kde.org @VolkerKrause Our Workflow Write code Run compiler... Run application Profit! Why

More information

x86 assembly CS449 Spring 2016

x86 assembly CS449 Spring 2016 x86 assembly CS449 Spring 2016 CISC vs. RISC CISC [Complex instruction set Computing] - larger, more feature-rich instruction set (more operations, addressing modes, etc.). slower clock speeds. fewer general

More information

Binary Analysis and Reverse Engineering

Binary Analysis and Reverse Engineering Pattern Recognition and Applications Lab Binary Analysis and Reverse Engineering Ing. Davide Maiorca, Ph.D. davide.maiorca@diee.unica.it Computer Security A.Y. 2017/2018 Department of Electrical and Electronic

More information

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c! Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Hello Word! ~/ctest/ In addition to syntax you need to learn: the Tools the Libraries. And the Documentation. Maria Hybinette,

More information

Lecture 3: Instruction Set Architecture

Lecture 3: Instruction Set Architecture Lecture 3: Instruction Set Architecture CSE 30: Computer Organization and Systems Programming Summer 2014 Diba Mirza Dept. of Computer Science and Engineering University of California, San Diego 1. Steps

More information

Ethical Hacking. Assembly Language Tutorial

Ethical Hacking. Assembly Language Tutorial Ethical Hacking Assembly Language Tutorial Number Systems Memory in a computer consists of numbers Computer memory does not store these numbers in decimal (base 10) Because it greatly simplifies the hardware,

More information

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

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006 C Compilation Model Comp-206 : Introduction to Software Systems Lecture 9 Alexandre Denault Computer Science McGill University Fall 2006 Midterm Date: Thursday, October 19th, 2006 Time: from 16h00 to 17h30

More information

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

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program. Language Translation Compilation vs. interpretation Compilation diagram Step 1: compile program compiler Compiled program Step 2: run input Compiled program output Language Translation compilation is translation

More information

Intro x86 Part 3: Linux Tools & Analysis

Intro x86 Part 3: Linux Tools & Analysis Intro x86 Part 3: Linux Tools & Analysis Xeno Kovah 2009/2010 xkovah at gmail Approved for Public Release: 10-3348. Distribution Unlimited All materials is licensed under a Creative Commons Share Alike

More information

Sandwiches for everyone

Sandwiches for everyone Inf2C :: Computer Systems Today s menu ( And finally, monsieur, a wafer-thin mint ) Notes on security Or, why safety is an illusion, why ignorance is bliss, and why knowledge is power Stack overflows Or,

More information

Computer Architecture and Assembly Language. Practical Session 3

Computer Architecture and Assembly Language. Practical Session 3 Computer Architecture and Assembly Language Practical Session 3 Advanced Instructions division DIV r/m - unsigned integer division IDIV r/m - signed integer division Dividend Divisor Quotient Remainder

More information

Welcome to CS 106L! Ali Malik

Welcome to CS 106L! Ali Malik Welcome to CS 106L! Ali Malik malikali@stanford.edu Game Plan Welcome Why CS106L? Logistics History and Philosophy of C++ C++ Basics Welcome! Instructor Ali Malik malikali@stanford.edu Instructor Ali Malik

More information

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

Generating Programs and Linking. Professor Rick Han Department of Computer Science University of Colorado at Boulder Generating Programs and Linking Professor Rick Han Department of Computer Science University of Colorado at Boulder CSCI 3753 Announcements Moodle - posted last Thursday s lecture Programming shell assignment

More information

Outline. Compiling process Linking libraries Common compiling op2ons Automa2ng the process

Outline. Compiling process Linking libraries Common compiling op2ons Automa2ng the process Compiling Programs Outline Compiling process Linking libraries Common compiling op2ons Automa2ng the process Program compilation Programmers usually writes code in high- level programming languages (e.g.

More information

Assembly Language Fundamentals. Chapter 3

Assembly Language Fundamentals. Chapter 3 Assembly Language Fundamentals Chapter 3 1 Numeric Constants 2 Numeric constants are made of numerical digits with, possibly, a sign and a suffix. Ex: -23 (a negative integer, base 10 is default) 1011b

More information

Simple C Program. Assembly Ouput. Using GCC to produce Assembly. Assembly produced by GCC is easy to recognize:

Simple C Program. Assembly Ouput. Using GCC to produce Assembly. Assembly produced by GCC is easy to recognize: Simple C Program Helloworld.c Programming and Debugging Assembly under Linux slides by Alexandre Denault int main(int argc, char *argv[]) { } printf("hello World"); Programming and Debugging Assembly under

More information

CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary

CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary Due: Thursday 14 Sept. Electronic copy due at 9:00 A.M., optional paper copy may be delivered to

More information