Linkers and Loaders. CS 167 VI 1 Copyright 2008 Thomas W. Doeppner. All rights reserved.

Size: px
Start display at page:

Download "Linkers and Loaders. CS 167 VI 1 Copyright 2008 Thomas W. Doeppner. All rights reserved."

Transcription

1 Linkers and Loaders CS 167 VI 1 Copyright 2008 Thomas W. Doeppner. All rights reserved.

2 Does Location Matter? int main(int argc, char *[ ]) { return(argc); } main: pushl %ebp ; push frame pointer movl %esp, %ebp ; set frame pointer to point to new frame movl 8(%ebp), %eax ; put argc into return register (eax) movl %ebp, %esp ; restore stack pointer popl %ebp ; pop stack into frame pointer ret ; return: pops end of stack into eip CS 167 VI 2 Copyright 2008 Thomas W. Doeppner. All rights reserved. The material in this slide through slide 14 is taken directly from the textbook.

3 Location Matters int X=6; int *ax = &X; int main( ) { void subr(int); int y=x; subr(y); return(0); } void subr(int i) { printf("i = %d\n", i); } CS 167 VI 3 Copyright 2008 Thomas W. Doeppner. All rights reserved. We don t need to look at the assembler code to see what s different about this program: the machine code produced for it can t simply be copied to an arbitrary location in our computer s memory and executed. The location identified by the name ax should contain the address of the location containing X. But since the address of X will not be known until the program is copied into memory, neither the compiler nor the assembler can initialize ax correctly. Similarly, the addresses of subr and printf are not known until the program is copied into memory again, neither the compiler nor the assembler would know what addresses to use.

4 A Slight Revision extern int X; int *ax = &X; #include <stdio.h> int X; int main( ) { void subr(int); int y = *ax; subr(y); return(0); } main.c void subr(int i) { printf("i = %d\n", i); } subr.c gcc o prog main.c subr.c CS 167 VI 4 Copyright 2008 Thomas W. Doeppner. All rights reserved.

5 main.s 0:.data ; what follows is initialized data 0:.globl ax ; ax is global: it may be used by others 0: ax: 0:.long X 4: 0:.text ; offset restarts; what follows is text (read-only code) 0:.globl main 0: main: 0: pushl %ebp ; save the frame pointer 1: movl %esp,%ebp ; point to current frame 3: subl $4,%esp ; make space for y on stack 6: movl ax,%eax ; put contents of X into eax 11: movl (%eax),%eax ; put *X into %eax 13: movl %eax,-4(%ebp) ; store *ax into y 16: pushl -4(%ebp) ; push y onto stack 19: call subr 24: addl $4,%esp ; remove y from stack 27: movl $0,%eax ; set return value to 0 31: movl %ebp, %esp ; restore stack pointer 33: popl %ebp ; pop frame pointer 35: ret CS 167 VI 5 Copyright 2008 Thomas W. Doeppner. All rights reserved.

6 subr.s 0:.data ; what follows is initialized data 0: printfarg: 0:.string "i = %d\n" 8: 0:.comm X,4 ; 4 bytes in BSS is required for global X 4: 0:.text ; offset restarts; what follows is text (read-only code) 0:.globl subr 0: subr: 0: pushl %ebp ; save the frame pointer 1: movl %esp, %ebp ; point to current frame 3: pushl 8(%ebp) ; push i onto stack 6: pushl $printfarg ; push address of string onto stack 11: call printf 16: addl $8, %esp ; pop arguments from stack 19: movl %ebp, %esp ; restore stack pointer 21: popl %ebp ; pop frame pointer 23: ret CS 167 VI 6 Copyright 2008 Thomas W. Doeppner. All rights reserved.

7 main.o Data: Size: 4 Global: ax, offset 0 Undefined: X Relocation: offset 0, size 4, value: address of X Contents: 0x bss: Size: 0 Text: Size: 36 Global: main, offset 0 Undefined: subr Relocation: offset 7, size 4, value: address of ax offset 20, size 4, value: PC-relative address of subr Contents: [machine instructions] CS 167 VI 7 Copyright 2008 Thomas W. Doeppner. All rights reserved.

8 subr.o Data: Size: 8 Contents: "i = %d\n" bss: Size: 4 Global: X, offset 0 Text: Size: 44 Global: subr, offset 0 Undefined: printf Relocation: offset 7, size 4, value: address of printfarg offset 12, size 4, value: PC-relative address of printf Contents: [machine instructions] CS 167 VI 8 Copyright 2008 Thomas W. Doeppner. All rights reserved.

9 printf.o Data: Size: 1024 Global: StandardFiles Contents: bss: Size: 256 Text: Size: Global: printf, offset 100 Undefined: write Relocation: offset 211, value: address of StandardFiles offset 723, value: PC-relative address of printf Contents: [machine instructions] CS 167 VI 9 Copyright 2008 Thomas W. Doeppner. All rights reserved.

10 write.o Data: Size: 0 bss: Size: 4 Global: errno, offset 0 Text: Size: 16 Contents: [machine instructions] CS 167 VI 10 Copyright 2008 Thomas W. Doeppner. All rights reserved.

11 prog Text Data bss main 4096 subr 4132 printf 4156 write startup ax printfargs StandardFiles X errno CS 167 VI 11 Copyright 2008 Thomas W. Doeppner. All rights reserved.

12 Shared Libraries Process A Process B printf( ) stdio printf( ) printf( ) CS 167 VI 12 Copyright 2008 Thomas W. Doeppner. All rights reserved. Consider the situation shown in the slide: we have two processes, each containing a program that calls printf. Up to this point in our discussion, the two processes have no means for sharing a single copy of printf each must have its own. If you consider that pretty much every C program calls printf, a huge amount of disk space in the world could be wasted because of all the copies of printf. Furthermore, when each program is loaded into primary memory, large amount of such memory is wasted because of multiple copies of printf. What is needed is a means for programs to share a single copy of printf (as well as other routines). However, sharing of code is not trivial to implement. A big problem is relocation. The code for printf might well contain relocatable addreses, such as references to global data and other procedures. What makes things difficult is that the code for printf might be mapped into the two processes at different virtual locations.

13 Relocation and Shared Libraries 1) Prerelocation: relocate libraries ahead of time 2) Limited sharing: relocate separately for each process 3) Position-Independent Code: no need for relocation CS 167 VI 13 Copyright 2008 Thomas W. Doeppner. All rights reserved. If all users of printf agree to load it and everything it references into the same locations in their address spaces, we would have no relocation problem. But such agreement is, in general, hard to achieve. It is, however, the approach used in Windows. A possibility might be for the users of printf to share a single on-disk copy, but for this copy to be relocated separately in each process when loaded. This would allow sharing of disk space, but not of primary storage. Another possibility is for printf to be written in such a way that relocation is not necessary. Code written in this fashion is known as position-independent code (PIC).

14 Position-Independent Code ld r2, r1[printf] call r2 0 printf( ) { ld r2, r1[doprint] call r2... } ld r2, r1[printf] call r2 r1 printf doprint doprint( ) {... } r1 printf doprint CS 167 VI 14 Copyright 2008 Thomas W. Doeppner. All rights reserved. Here is an example of the use of position-independent code (PIC). Processes A and B are sharing the library containing printf (note that printf contains a call to another shared routine, doprint), though each has it mapped into a different location. Each process maintains a private table, pointed to by register r1. In the table are the addresses of shared routines, as mapped into the process. Thus, rather than call a routine directly (via an address embedded in the code), a position-independent call is made: the address of the desired routine is stored at some fixed offset within the table. The contents of the table at this offset are loaded into register r2, and then the call is made via r2.

15 Linking and Loading on Linux with ELF Substitution Shared libraries Versioning Dynamic linking Interpositioning CS 167 VI 15 Copyright 2008 Thomas W. Doeppner. All rights reserved. ELF stands for executable and linking format and is used on most Unix systems, including Linux, Solaris, FreeBSD, NetBSD, and OpenBSD, but not MacOS X.

16 Creating a Library % gcc -c sub1.c sub2.c sub3.c % ls sub1.c sub2.c sub3.c sub1.o sub2.o sub3.o % ar cr libpriv1.a sub1.o sub2.o sub3.o % ar t libpriv1.a sub1.o sub2.o sub3.o % CS 167 VI 16 Copyright 2008 Thomas W. Doeppner. All rights reserved.

17 Using a Library % cat prog.c int main() { sub1(); sub2(); sub3(); } % cat sub1.c void sub1() { puts("sub1"); } % gcc -o prog prog.c -L. -lpriv1 Where does puts come from? %gcc o prog prog.c L. \ -lpriv1 L/lib -lc CS 167 VI 17 Copyright 2008 Thomas W. Doeppner. All rights reserved.

18 Substitution % cat myputs.c int puts(char *s) { write(1, "My puts: ", 9); write(1, s, strlen(s)); write(1, "\n", 1); return 1; } % gcc c myputs.c % ar cr libmyputs.a myputs.o % gcc -o prog prog.c -L. -lpriv1 -lmyputs % CS 167 VI 18 Copyright 2008 Thomas W. Doeppner. All rights reserved.

19 Shared Libraries 1 Compile program 2 Track down linkages with ld archives (containing relocatable objects) in.a files are statically linked shared objects in.so files are dynamically linked 3 Run program ld.so is invoked to complete the linking and relocation steps, if necessary CS 167 VI 19 Copyright 2008 Thomas W. Doeppner. All rights reserved. Linux supports two kinds of libraries static libraries, contained in archives, whose names end with.a (e.g. libc.a) and shared objects, whose names end with.so (e.g. libc.so). When ld is invoked to handle the linking of object code, it is normally given a list of libraries in which to find unresolved references. If it resolves a reference within a.a file, it copies the code from the file and statically links it into the object code. However, if it resolves the reference within a.so file, it records the name of the shared object (not the complete path, just the final component) and postpones actual linking until the program is executed. If the program is fully bound and relocated, then it is ready for direct execution. However, if it is not fully bound and relocated, then ld arranges things so that when the program is executed, rather than starting with the program s main routine, a runtime version of ld, called ld.so, is called first. ld.so maps all the required libraries into the address space, completes the linkages, and then calls the main routine.

20 Creating a Shared Library (1) % gcc -fpic -c myputs.c % ld -shared -o libmyputs.so myputs.o % gcc -o prog prog.c -L. -lpriv1 lmyputs %./prog./prog: error while loading shared libraries: libmyputs.so: cannot open shared object file: No such file or directory % ldd prog libmyputs.so => not found libc.so.6 => /lib/tls/i686/cmoc/libc.so.6 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 CS 167 VI 20 Copyright 2008 Thomas W. Doeppner. All rights reserved.

21 Creating a Shared Library (2) % gcc -o prog prog.c -L. -lpriv1 lmyputs \ Wl,-rpath. % ldd prog libmyputs.so =>./libmyputs.so libc.so.6 => /lib/tls/i686/cmoc/libc.so.6 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 %./prog My puts: sub1 My puts: sub2 My puts: sub3 CS 167 VI 21 Copyright 2008 Thomas W. Doeppner. All rights reserved.

22 Versioning % gcc -fpic -c myputs.c % ld -shared soname libmyputs.so.1 \ -o libmyputs.so.1 myputs.o % ln s libmyputs.so.1 libmyputs.so % gcc -o prog1 prog1.c -L. -lpriv1 lmyputs \ Wl,-rpath. % vi myputs.c % ld -shared soname libmyputs.so.2 \ -o libmyputs.so.2 myputs.o % rm f libmyputs.so % ln s libmyputs.so.2 libmyputs.so % gcc -o prog2 prog2.c -L. -lpriv1 lmyputs \ Wl,-rpath. CS 167 VI 22 Copyright 2008 Thomas W. Doeppner. All rights reserved.

23 Interpositioning prog wrapper puts CS 167 VI 23 Copyright 2008 Thomas W. Doeppner. All rights reserved.

24 How To? #include <dlfcn.h> int puts(const char *s) { int (*pptr)(const char *); pptr = (int(*)())dlsym(rtld_next, "puts"); } write(2, "calling myputs: ", 16); return (*pptr)(s); CS 167 VI 24 Copyright 2008 Thomas W. Doeppner. All rights reserved.

25 Compiling/Linking It % gcc -fpic -c myputs.c -D_GNU_SOURCE % ld -shared -soname libmyputs.so.1 \ -o libmyputs.so.1 myputs.o -ldl % gcc -o tputs tputs.c./libmyputs.so.1 \ -Wl,-rpath. CS 167 VI 25 Copyright 2008 Thomas W. Doeppner. All rights reserved.

26 What s Going On gcc/ld compiles code does static linking - searches list of libraries - adds references to shared objects runtime program invokes ld.so to finish linking - maps in shared objects - does relocation and procedure linking as required dlsym invokes ld.so to do more linking CS 167 VI 26 Copyright 2008 Thomas W. Doeppner. All rights reserved.

27 Delayed Wrapping LD_PRELOAD environment variable checked by ld.so specifies additional shared objects to search (first) when program is started CS 167 VI 27 Copyright 2008 Thomas W. Doeppner. All rights reserved.

28 Example % gcc o tputs tputs.c %./tputs This is a boring message. % setenv LD_PRELOAD./libmyputs.so.1 %./tputs calling myputs: This is a boring message. % CS 167 VI 28 Copyright 2008 Thomas W. Doeppner. All rights reserved.

29 Position-Independent Code Processor-dependent; x86 32-bit version: each dynamic executable and share object has: - procedure-linkage table shared, read-only executable code essentially stubs for calling subroutines - global-offset table private, read-write data relocated dynamically for each process - dynamic structure shared, read-only data contains relocation info and symbol table CS 167 VI 29 Copyright 2008 Thomas W. Doeppner. All rights reserved. To provide position-independent code on a 32-bit x86, ELF requires three data structures for each dynamic executable (i.e., the program binary loaded by exec) and shared object: the procedure-linkage table, the global-offset table, and the dynamic structure. To simplify discussion, we refer to dynamic executables and shared objects as modules. The procedure linkage table contains the code that s actually called when control is to be transferred to an externally defined routine. It is shared by all processes using the associated executable or object, and makes use of data in the global-object table to link the caller to the called program. Each process has its own private copy of each global-object table. It contains the relocated addresses of all externally defined symbols. Finally, the dynamic structure contains much information about each module. What is used for linking is relocation information and the symbol table, as we explain in the next few slides. How things work is similar for other architectures, but definitely not the same. Detailed (but confusing) information can be found at

30 Global-Offset Table: Data References Global Offset Table errno errno address myglob myglob address CS 167 VI 30 Copyright 2008 Thomas W. Doeppner. All rights reserved. To establish position-independent references to global variables, the compiler produces, for each module, a global-offset table. Modules refer to global variables indirectly by looking up their addresses in the table. The way this works is that when code in the module refers to something in the table, a register is set to point to it. The item needed is at some fixed offset from the beginning of the table. When the module is loaded into memory, ld.so is responsible for putting into it the actual addresses of all the needed global variables.

31 Procedure References Lots of them Many are never used Fix them up on demand CS 167 VI 31 Copyright 2008 Thomas W. Doeppner. All rights reserved.

32 Before Calling Name1.PLT0: pushl 4(%ebx) jmp 8(%ebx) nop; nop nop; nop.plt1: jmp name1(%ebx).plt1next: pushl $name1reloffset jmp.plt0.plt2: jmp name2(%ebx).plt2next pushl $name2reloffset jmp.plt0 Procedure-Linkage Table ebx Relocation info: _GLOBAL_OFFSET_TABLE:.long _DYNAMIC.long identification.long ld.so name1:.long.plt1next name2:.long.plt2next GOT_offset(name1), symx(name1) GOT_offset(name2), symx(name2) _DYNAMIC CS 167 VI 32 Copyright 2008 Thomas W. Doeppner. All rights reserved. Dealing with references to external procedures is considerably more complicated than dealing with references to external data. This slide shows the procedure linkage table, global offset table, and relocation information for a module that contains references to external procedures name1 and name2. Let s follow a call to procedure name1. The general idea is before the first call to name1, the actual address of the name1 procedure is not recorded in the global-offset table, Instead, the first call to name1 actually invokes ld.so, which is passed parameters indicating what is really wanted. It then finds name1 and updates the globaloffset table so that things are more direct on subsequent calls. To make this happen, references from the module to name1 are statically linked to entry.plt1 in the procedurelinkage table. This entry contains an unconditional jump to the address contained in the name1 offset of the global-offset table (pointed to by register ebx). Initially this address is of the instruction following the jump instruction, which contains code that pushes onto the stack the offset of the name1 entry in the relocation table. The next instruction is an unconditional jump to the beginning of the procedure-linkage table, entry.plt0. Here there s code that pushes onto the stack the second 32-bit word of the global-offset table, which contains a value identifying this module. The following instruction is an unconditional jump to the address in the third word of the global-offset table, which is conveniently the address of ld.so. Thus control finally passes to ld.so, which looks back on the stack and determines which module has called it and what that module really wants to call. It figures this out based on the module-identification word and the relocation table entry, which contains the offset of the name1 entry in the global-offset table (which is what must be updated) and the index of name1 in the symbol table (so it knows the name of what it must locate).

33 After Calling Name1.PLT0: pushl 4(%ebx) jmp 8(%ebx) nop; nop nop; nop.plt1: jmp name1(%ebx).plt1next: pushl $name1reloffset jmp.plt0.plt2: jmp name2(%ebx).plt2next pushl $name2reloffset jmp.plt0 Procedure-Linkage Table ebx Relocation info: _GLOBAL_OFFSET_TABLE:.long _DYNAMIC.long identification.long ld.so name1:.long name1 name2:.long.plt2next GOT_offset(name1), symx(name1) GOT_offset(name2), symx(name2) _DYNAMIC CS 167 VI 33 Copyright 2008 Thomas W. Doeppner. All rights reserved. Finally, ld.so writes the actual address of the name1 procedure into the name1 entry of the global-offset table, and, after unwinding the stack a bit, passes control to name1. On subsequent calls by the module to name1, since the global-offset table now contains name1 s address, control goes to it more directly, without an invocation of ld.so.

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

CS 33. Libraries. CS33 Intro to Computer Systems XXIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Libraries CS33 Intro to Computer Systems XXIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Libraries Collections of useful stuff Allow you to: incorporate items into your program substitute

More information

CS 33. Libraries. CS33 Intro to Computer Systems XXVIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 33. Libraries. CS33 Intro to Computer Systems XXVIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. CS 33 Libraries CS33 Intro to Computer Systems XXVIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. Libraries Collections of useful stuff Allow you to: incorporate items into your program substitute

More information

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

CS 33. Linkers. CS33 Intro to Computer Systems XXV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Linkers CS33 Intro to Computer Systems XXV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. gcc Steps 1) Compile to start here, supply.c file to stop here: gcc -S (produces.s file) if not

More information

CS5460/6460: Operating Systems. Lecture 21: Shared libraries. Anton Burtsev March, 2014

CS5460/6460: Operating Systems. Lecture 21: Shared libraries. Anton Burtsev March, 2014 CS5460/6460: Operating Systems Lecture 21: Shared libraries Anton Burtsev March, 2014 Recap from last time We know what linkers and loaders do Types of object files Relocatable object files (.o) Static

More information

CPEG421/621 Tutorial

CPEG421/621 Tutorial CPEG421/621 Tutorial Compiler data representation system call interface calling convention Assembler object file format object code model Linker program initialization exception handling relocation model

More information

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site) Function Calls COS 217 Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site) 1 Goals of Today s Lecture Finishing introduction to assembly language o EFLAGS register

More information

Assembly Language: Function Calls

Assembly Language: Function Calls Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and returning Passing parameters Storing local variables Handling registers without interference

More information

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang Project 3 Questions CMSC 313 Lecture 12 How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP

More information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls Goals of this Lecture Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and returning" Passing parameters" Storing local variables" Handling registers without interference"

More information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls Goals of this Lecture Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and urning" Passing parameters" Storing local variables" Handling registers without interference"

More information

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

CSC 2400: Computing Systems. X86 Assembly: Function Calls CSC 24: Computing Systems X86 Assembly: Function Calls" 1 Lecture Goals! Challenges of supporting functions" Providing information for the called function" Function arguments and local variables" Allowing

More information

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110 Questions 1 Question 4.1 1: (Solution, p 5) Define the fetch-execute cycle as it relates to a computer processing a program. Your definition should describe the primary purpose of each phase. Question

More information

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions CS220 Logic Design Outline Calling Conventions Multi-module Programs 1 Calling and Returning We have already seen how the call instruction is used to execute a subprogram. call pushes the address of the

More information

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and urning Passing parameters Storing local variables Handling registers without interference Returning

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

CSC 2400: Computing Systems. X86 Assembly: Function Calls

CSC 2400: Computing Systems. X86 Assembly: Function Calls CSC 24: Computing Systems X86 Assembly: Function Calls 1 Lecture Goals Challenges of supporting functions Providing information for the called function Function arguments and local variables Allowing the

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

CMSC 313 Lecture 12 [draft] How C functions pass parameters

CMSC 313 Lecture 12 [draft] How C functions pass parameters CMSC 313 Lecture 12 [draft] How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP removes an

More information

Exercise Session 7 Computer Architecture and Systems Programming

Exercise Session 7 Computer Architecture and Systems Programming Systems Group Department of Computer Science ETH Zürich Exercise Session 7 Computer Architecture and Systems Programming Herbstsemester 2014 Review of last week s excersice structs / arrays in Assembler

More information

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control. C Flow Control David Chisnall February 1, 2011 Outline What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope Disclaimer! These slides contain a lot of

More information

Implementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Implementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. Implementing Threads Operating Systems In Depth II 1 Copyright 2018 Thomas W Doeppner All rights reserved The Unix Address Space stack dynamic bss data text Operating Systems In Depth II 2 Copyright 2018

More information

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016 CS 31: Intro to Systems Functions and the Stack Martin Gagne Swarthmore College February 23, 2016 Reminders Late policy: you do not have to send me an email to inform me of a late submission before the

More information

CPS104 Recitation: Assembly Programming

CPS104 Recitation: Assembly Programming CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in

More information

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1 Homework In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, 361-367 Practice Exam 1 1 In-line Assembly Code The gcc compiler allows you to put assembly instructions in-line

More information

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

COMPILING OBJECTS AND OTHER LANGUAGE IMPLEMENTATION ISSUES. Credit: Mostly Bryant & O Hallaron COMPILING OBJECTS AND OTHER LANGUAGE IMPLEMENTATION ISSUES Credit: Mostly Bryant & O Hallaron Word-Oriented Memory Organization Addresses Specify Byte Locations Address of first byte in word Addresses

More information

Assembly Language Programming - III

Assembly Language Programming - III Assembly Language Programming - III GDB Debugger Please refer to the handout New GDB commands (power.s) info registers (prints all register values) print/d $eax (prints individual register value. Note

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

Relocating Symbols and Resolving External References. CS429: Computer Organization and Architecture. m.o Relocation Info

Relocating Symbols and Resolving External References. CS429: Computer Organization and Architecture. m.o Relocation Info Relocating Symbols and Resolving External References CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: January 13,

More information

CS 537 Lecture 2 - Processes

CS 537 Lecture 2 - Processes CS 537 Lecture 2 - Processes Michael Swift 1 Basic Structure Kernel is a big program that starts when you boot your program Has full access to physical hardware. User programs, utilities, services see

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: January 13, 2017 at 08:55 CS429 Slideset 25: 1 Relocating Symbols

More information

X86 Review Process Layout, ISA, etc. CS642: Computer Security. Drew Davidson

X86 Review Process Layout, ISA, etc. CS642: Computer Security. Drew Davidson X86 Review Process Layout, ISA, etc. CS642: Computer Security Drew Davidson davidson@cs.wisc.edu From Last Time ACL-based permissions (UNIX style) Read, Write, execute can be restricted on users and groups

More information

Introduction Selected details Live demos. HrwCC. A self-compiling C-compiler. Stefan Huber Christian Rathgeb Stefan Walkner

Introduction Selected details Live demos. HrwCC. A self-compiling C-compiler. Stefan Huber Christian Rathgeb Stefan Walkner HrwCC A self-compiling C-compiler. Stefan Huber Christian Rathgeb Stefan Walkner Universität Salzburg VP Compiler Construction June 26, 2007 Overview 1 Introduction Basic properties Features 2 Selected

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

(Extract from the slides by Terrance E. Boult

(Extract from the slides by Terrance E. Boult What software engineers need to know about linking and a few things about execution (Extract from the slides by Terrance E. Boult http://vast.uccs.edu/~tboult/) A Simplistic Program Translation Scheme

More information

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

CIT 595 Spring System Software: Programming Tools. Assembly Process Example: First Pass. Assembly Process Example: Second Pass. System Software: Programming Tools Programming tools carry out the mechanics of software creation within the confines of the operating system and hardware environment Linkers & Loaders CIT 595 Spring 2010

More information

Lab 10: Introduction to x86 Assembly

Lab 10: Introduction to x86 Assembly CS342 Computer Security Handout # 8 Prof. Lyn Turbak Wednesday, Nov. 07, 2012 Wellesley College Revised Nov. 09, 2012 Lab 10: Introduction to x86 Assembly Revisions: Nov. 9 The sos O3.s file on p. 10 was

More information

X86 Stack Calling Function POV

X86 Stack Calling Function POV X86 Stack Calling Function POV Computer Systems Section 3.7 Stack Frame Reg Value ebp xffff FFF0 esp xffff FFE0 eax x0000 000E Memory Address Value xffff FFF8 xffff FFF4 x0000 0004 xffff FFF4 x0000 0003

More information

CMSC 430 Introduction to Compilers. Spring Code Generation

CMSC 430 Introduction to Compilers. Spring Code Generation CMSC 430 Introduction to Compilers Spring 2015 Code Generation Introduction Code generation is the process of moving from highest level IR down to machine code Usually takes place after data flow analysis

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013 CONST POINTERS CONST POINTERS 4 ways to declare pointers in combination with const:!! int *ptr! const int *ptr!

More information

Link 8.A Dynamic Linking

Link 8.A Dynamic Linking Link 8.A Dynamic Linking Young W. Lim 2019-01-04 Fri Young W. Lim Link 8.A Dynamic Linking 2019-01-04 Fri 1 / 42 Outline 1 Linking - 8.A Dynamic Linking Based on Dynamic linking with a shared library example

More information

CS642: Computer Security

CS642: Computer Security X86 Review Process Layout, ISA, etc. CS642: Computer Security Drew Davidson davidson@cs.wisc.edu From Last Week ACL- based permissions (UNIX style) Read, Write, execute can be restricted on users and groups

More information

x86 assembly CS449 Fall 2017

x86 assembly CS449 Fall 2017 x86 assembly CS449 Fall 2017 x86 is a CISC CISC (Complex Instruction Set Computer) e.g. x86 Hundreds of (complex) instructions Only a handful of registers RISC (Reduced Instruction Set Computer) e.g. MIPS

More information

Intel assembly language using gcc

Intel assembly language using gcc QOTD Intel assembly language using gcc Assembly language programming is difficult. Make no mistake about that. It is not for wimps and weaklings. - Tanenbaum s 6th, page 519 These notes are a supplement

More information

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017 CS 31: Intro to Systems ISAs and Assembly Martin Gagné Swarthmore College February 7, 2017 ANNOUNCEMENT All labs will meet in SCI 252 (the robot lab) tomorrow. Overview How to directly interact with hardware

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

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29 Procedure Calls Young W. Lim 2017-08-21 Mon Young W. Lim Procedure Calls 2017-08-21 Mon 1 / 29 Outline 1 Introduction Based on Stack Background Transferring Control Register Usage Conventions Procedure

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

Obtained the source code to gcc, one can just follow the instructions given in the INSTALL file for GCC.

Obtained the source code to gcc, one can just follow the instructions given in the INSTALL file for GCC. Building cross compilers Linux as the target platform Obtained the source code to gcc, one can just follow the instructions given in the INSTALL file for GCC. configure --target=i486-linux --host=xxx on

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

Link 8. Dynamic Linking

Link 8. Dynamic Linking Link 8. Dynamic Linking Young W. Lim 2018-12-27 Thr Young W. Lim Link 8. Dynamic Linking 2018-12-27 Thr 1 / 66 Outline 1 Linking - 8. Dynamic Linking Based on Dynamic linking with a shared library example

More information

LINKING. Jo, Heeseung

LINKING. Jo, Heeseung LINKING Jo, Heeseung PROGRAM TRANSLATION (1) A simplistic program translation scheme m.c ASCII source file Translator p Binary executable object file (memory image on disk) Problems: - Efficiency: small

More information

Low-Level Essentials for Understanding Security Problems Aurélien Francillon

Low-Level Essentials for Understanding Security Problems Aurélien Francillon Low-Level Essentials for Understanding Security Problems Aurélien Francillon francill@eurecom.fr Computer Architecture The modern computer architecture is based on Von Neumann Two main parts: CPU (Central

More information

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27 Procedure Calls Young W. Lim 2016-11-05 Sat Young W. Lim Procedure Calls 2016-11-05 Sat 1 / 27 Outline 1 Introduction References Stack Background Transferring Control Register Usage Conventions Procedure

More information

Link 7. Static Linking

Link 7. Static Linking Link 7. Static Linking Young W. Lim 2018-12-21 Fri Young W. Lim Link 7. Static Linking 2018-12-21 Fri 1 / 41 Outline 1 Linking - 7. Static Linking Based on Static Library Examples Linking with Static Libraries

More information

x86 architecture et similia

x86 architecture et similia x86 architecture et similia 1 FREELY INSPIRED FROM CLASS 6.828, MIT A full PC has: PC architecture 2 an x86 CPU with registers, execution unit, and memory management CPU chip pins include address and data

More information

CPSC W Term 2 Problem Set #3 - Solution

CPSC W Term 2 Problem Set #3 - Solution 1. (a) int gcd(int a, int b) { if (a == b) urn a; else if (a > b) urn gcd(a - b, b); else urn gcd(a, b - a); CPSC 313 06W Term 2 Problem Set #3 - Solution.file "gcdrec.c".globl gcd.type gcd, @function

More information

Systems I. Linking II

Systems I. Linking II Systems I Linking II Topics Relocation Static libraries Loading Dynamic linking of shared libraries Relocating Symbols and Resolving External References Symbols are lexical entities that name functions

More information

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction E I P CPU isters Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Topics Assembly Programmer

More information

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? exam on Wednesday today s material not on the exam 1 Assembly Assembly is programming

More information

238P: Operating Systems. Lecture 4: Linking and Loading (Basic architecture of a program) Anton Burtsev October, 2018

238P: Operating Systems. Lecture 4: Linking and Loading (Basic architecture of a program) Anton Burtsev October, 2018 238P: Operating Systems Lecture 4: Linking and Loading (Basic architecture of a program) Anton Burtsev October, 2018 What is a program? What parts do we need to run code? Parts needed to run a program

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

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

Compiler Construction D7011E

Compiler Construction D7011E Compiler Construction D7011E Lecture 8: Introduction to code generation Viktor Leijon Slides largely by Johan Nordlander with material generously provided by Mark P. Jones. 1 What is a Compiler? Compilers

More information

Stack Debugging. Young W. Lim Sat. Young W. Lim Stack Debugging Sat 1 / 40

Stack Debugging. Young W. Lim Sat. Young W. Lim Stack Debugging Sat 1 / 40 Stack Debugging Young W. Lim 2017-07-22 Sat Young W. Lim Stack Debugging 2017-07-22 Sat 1 / 40 Outline 1 Introduction References Compiling to IA32 Assembly Checking /proc//maps file Checking Stack

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

CIT Week13 Lecture

CIT Week13 Lecture CIT 3136 - Week13 Lecture Runtime Environments During execution, allocation must be maintained by the generated code that is compatible with the scope and lifetime rules of the language. Typically there

More information

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016 CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College February 9, 2016 Reading Quiz Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between

More information

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

CSE 2421: Systems I Low-Level Programming and Computer Organization. Linking. Presentation N. Introduction to Linkers CSE 2421: Systems I Low-Level Programming and Computer Organization Linking Read/Study: Bryant 7.1 7.10 Gojko Babić 11-15-2017 Introduction to Linkers Linking is the process of collecting and combining

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

CMSC 216 Introduction to Computer Systems Lecture 23 Libraries

CMSC 216 Introduction to Computer Systems Lecture 23 Libraries CMSC 216 Introduction to Computer Systems Lecture 23 Libraries Administrivia Read Sections 2.2-2.4 of Bryant and O Hallaron on data representation Make sure you copy your projects (for future reference)

More information

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018 CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College September 25, 2018 Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between programmer

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

143A: Principles of Operating Systems. Lecture 4: Linking and Loading (Basic architecture of a program) Anton Burtsev October, 2018

143A: Principles of Operating Systems. Lecture 4: Linking and Loading (Basic architecture of a program) Anton Burtsev October, 2018 143A: Principles of Operating Systems Lecture 4: Linking and Loading (Basic architecture of a program) Anton Burtsev October, 2018 What is a program? What parts do we need to run code? Parts needed to

More information

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Architecture and the OS CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. The Operating System My Program Mary s Program Bob s Program OS CS33 Intro to

More information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures ISAs Brief history of processors and architectures C, assembly, machine code Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface contain?

More information

Buffer Overflow Attack

Buffer Overflow Attack Buffer Overflow Attack What every applicant for the hacker should know about the foundation of buffer overflow attacks By (Dalgona@wowhacker.org) Email: zinwon@gmail.com 2005 9 5 Abstract Buffer overflow.

More information

CMSC 430 Introduction to Compilers. Fall Code Generation

CMSC 430 Introduction to Compilers. Fall Code Generation CMSC 430 Introduction to Compilers Fall 2018 Code Generation Code Representations Front end Source code Lexer Parser Types AST/IR IR 2 IR n IR n.s Middle end Back end Front end syntax recognition, semantic

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

ANITA S SUPER AWESOME RECITATION SLIDES

ANITA S SUPER AWESOME RECITATION SLIDES ANITA S SUPER AWESOME RECITATION SLIDES 15/18-213: Introduction to Computer Systems Stacks and Buflab, 11 Jun 2013 Anita Zhang, Section M WHAT S NEW (OR NOT) Bomblab is due tonight, 11:59 PM EDT Your late

More information

An Experience Like No Other. Stack Discipline Aug. 30, 2006

An Experience Like No Other. Stack Discipline Aug. 30, 2006 15-410 An Experience Like No Other Discipline Aug. 30, 2006 Bruce Maggs Dave Eckhardt Slides originally stolen from 15-213 15-410, F 06 Synchronization Registration If you're here but not registered, please

More information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures! ISAs! Brief history of processors and architectures! C, assembly, machine code! Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface

More information

Computer Systems Lecture 9

Computer Systems Lecture 9 Computer Systems Lecture 9 CPU Registers in x86 CPU status flags EFLAG: The Flag register holds the CPU status flags The status flags are separate bits in EFLAG where information on important conditions

More information

CMPSC 497 Buffer Overflow Vulnerabilities

CMPSC 497 Buffer Overflow Vulnerabilities Systems and Internet Infrastructure Security Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA CMPSC 497 Buffer Overflow

More information

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation Compiler Construction SMD163 Lecture 8: Introduction to code generation Viktor Leijon & Peter Jonsson with slides by Johan Nordlander Contains material generously provided by Mark P. Jones What is a Compiler?

More information

CS631 - Advanced Programming in the UNIX Environment

CS631 - Advanced Programming in the UNIX Environment CS631 - Advanced Programming in the UNIX Environment Slide 1 CS631 - Advanced Programming in the UNIX Environment Shared Libraries Department of Computer Science Stevens Institute of Technology Jan Schaumann

More information

Process Layout and Function Calls

Process Layout and Function Calls Process Layout and Function Calls CS 6 Spring 07 / 8 Process Layout in Memory Stack grows towards decreasing addresses. is initialized at run-time. Heap grow towards increasing addresses. is initialized

More information

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. CS 33 Architecture and the OS CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. The Operating System My Program Mary s Program Bob s Program OS CS33 Intro to

More information

CSE 351: Week 4. Tom Bergan, TA

CSE 351: Week 4. Tom Bergan, TA CSE 35 Week 4 Tom Bergan, TA Does this code look okay? int binarysearch(int a[], int length, int key) { int low = 0; int high = length - ; while (low

More information

143A: Principles of Operating Systems. Lecture 5: Calling conventions. Anton Burtsev January, 2017

143A: Principles of Operating Systems. Lecture 5: Calling conventions. Anton Burtsev January, 2017 143A: Principles of Operating Systems Lecture 5: Calling conventions Anton Burtsev January, 2017 Stack and procedure calls Stack Main purpose: Store the return address for the current procedure Caller

More information

Outline. Outline. Common Linux tools to explore object/executable files. Revealing Internals of Loader. Zhiqiang Lin

Outline. Outline. Common Linux tools to explore object/executable files. Revealing Internals of Loader. Zhiqiang Lin CS 6V81-05: System Security and Malicious Code Analysis Revealing Internals of Loader Zhiqiang Lin Department of Computer Science University of Texas at Dallas March 28 th, 2012 Common Linux tools to explore

More information

CS 201 Linking Gerson Robboy Portland State University

CS 201 Linking Gerson Robboy Portland State University CS 201 Linking Gerson Robboy Portland State University 1 15-213, F 02 A Simplistic Program Translation Scheme m.c ASCII source file Translator p Binary executable object file (memory image on disk) Problems:

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

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1 Lecture #16: Introduction to Runtime Organization Last modified: Fri Mar 19 00:17:19 2010 CS164: Lecture #16 1 Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces

More information

Object-oriented features

Object-oriented features Chapter 1 Object-oriented features The compiler s job for a procedural language like C is relatively straightforward, because C and most other compiled procedural languages have been designed to approximate

More information

Introduction Presentation A

Introduction Presentation A CSE 2421/5042: Systems I Low-Level Programming and Computer Organization Introduction Presentation A Read carefully: Bryant Chapter 1 Study: Reek Chapter 2 Skim: Reek Chapter 1 08/22/2018 Gojko Babić Some

More information

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Machine-level Representation of Programs Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Program? 짬뽕라면 준비시간 :10 분, 조리시간 :10 분 재료라면 1개, 스프 1봉지, 오징어

More information

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha CS 111 Scribe Notes for 4/11/05 by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha Processes What is a process? A process is a running instance of a program. The Web browser you're using to

More information

Processes (Intro) Yannis Smaragdakis, U. Athens

Processes (Intro) Yannis Smaragdakis, U. Athens Processes (Intro) Yannis Smaragdakis, U. Athens Process: CPU Virtualization Process = Program, instantiated has memory, code, current state What kind of memory do we have? registers + address space Let's

More information

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

Example C program. 11: Linking. Why linkers? Modularity! Static linking. Why linkers? Efficiency! What do linkers do? 10/28/2013 Example C program 11: Linking Computer Architecture and Systems Programming 252 61, Herbstsemester 213 Timothy Roscoe main.c int buf[2] = 1, 2; swap(); return ; swap.c static int *bufp = &buf[]; void swap()

More information

Stack Discipline Jan. 19, 2018

Stack Discipline Jan. 19, 2018 15-410 An Experience Like No Other Discipline Jan. 19, 2018 Dave Eckhardt Brian Railing Slides originally stolen from 15-213 1 15-410, S 18 Synchronization Registration The wait list will probably be done

More information