Link 7. Static Linking
|
|
- Charla Houston
- 5 years ago
- Views:
Transcription
1 Link 7. Static Linking Young W. Lim Fri Young W. Lim Link 7. Static Linking Fri 1 / 41
2 Outline 1 Linking - 7. Static Linking Based on Static Library Examples Linking with Static Libraries Resolving refereces with Static Libraries Static Linking and Symbol Relocation Example Young W. Lim Link 7. Static Linking Fri 2 / 41
3 Based on "Self-service Linux: Mastering the Art of Problem Determination", Mark Wilding "Computer Architecture: A Programmer s Perspective", Bryant & O Hallaron I, the copyright holder of this work, hereby publish it under the following licenses: GNU head 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 published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License. CC BY SA This file is licensed under the Creative Commons Attribution ShareAlike 3.0 Unported License. In short: you are free to share and make derivative works of the file under the conditions that you appropriately attribute it, and that you distribute it only under a license compatible with this one. Young W. Lim Link 7. Static Linking Fri 3 / 41
4 Static Library Examples 1 addvec.c and mutvec.c 2 libvector.a 3 main.c 4 p Young W. Lim Link 7. Static Linking Fri 4 / 41
5 addvec.c and multvec.c! /*::::: addvec.c :::::::::::::::::::::::::*/ void addvec(int *x, int *y, int *z, int n) { int i; } for (i=0; i<n; i++) z[i] = x[i] + y[i]; /*::::: multvec.c :::::::::::::::::::::::::*/ void multvec(int *x, int *y, int *z, int n) { int i; } for (i=0; i<n; i++) z[i] = x[i] * y[i]; Young W. Lim Link 7. Static Linking Fri 5 / 41
6 libvector.a gcc -c addvec.c addvec.o gcc -c multvec.c multvec.o ar rcs libvector.a addvec.o multvec.o libvector.a Young W. Lim Link 7. Static Linking Fri 6 / 41
7 main.c /*::::: vector.h ::::::::::::::::::::::::::*/ void addvec(int *x, int *y, int *z, int n); void multvec(int *x, int *y, int *z, int n); /*::::: main.c ::::::::::::::::::::::::::::*/ #include <stdio.h> #include "vector.h" int x[2] = { 1, 2}; int y[2] = { 3, 4}; int z[2]; int main() { } addvec(x, y, z, 2); printf("z= [%d %d]\n", z[0], z[1]); Young W. Lim Link 7. Static Linking Fri 7 / 41
8 p gcc -O2 -c main.c main.o gcc -static -o p main.o./libvector.a p./p z= [4 6] Young W. Lim Link 7. Static Linking Fri 8 / 41
9 Linking with Static Libraries 1 Static Libraries 2 ANSI C libc.a 3 advantages of static libraries 4 Unix archive 5 Linking with static library examples Young W. Lim Link 7. Static Linking Fri 9 / 41
10 Static Libraries assumption the linker reads a colleciton of relocatable object files and links them together into an output file in practice a static library is a mechanism for packaging those related object modules into a single file this file is supplied as input to the linker the linker copies only those object modules in the library that are referenced by the application program Young W. Lim Link 7. Static Linking Fri 10 / 41
11 ANSI C libc.a libc.a library an extensive collection of standard I/O atoi, pritnf, scanf string manipulation strcpy integer math functions random libm.a library an extensive collection of floating-point math functions sin, cos, sqrt Young W. Lim Link 7. Static Linking Fri 11 / 41
12 advantages of static libraries (1) related functions can be compiled into separate object modules then packaged in a single static library file application program can then use any of the functions defined in the library by specifying the file name on the command line gcc main.c /usr/lib/libc.a /usr/lib/libm.a Young W. Lim Link 7. Static Linking Fri 12 / 41
13 advantages of static libraries (2) at link time, the linker will only copy the object modules that are referenced by the program which reduces the size of the executable on disk and in memory the application programmers only need to include the names of a few library files C compiler drivers always pass libc.a to the linker so the reference to libc.a is unnecessary Young W. Lim Link 7. Static Linking Fri 13 / 41
14 Unix archive an archive on Unix systems static libraries are stored on disk in a particular file format : archive a collection of concatenated relocatable object files a header describes the size and locaton of each member object file archive filenames are denoted with the.a suffix Young W. Lim Link 7. Static Linking Fri 14 / 41
15 Linking with static library examples (1) main2.c main2.o translators (cpp, ccl, as) libvector.a addvec.o libc.a printf.o any other modules called by printf.o also main2.o, addvec.o, printf.o, other object files p2 linker (ld) void addvec(int *x, int *y) Young W. Lim Link 7. Static Linking Fri 15 / 41
16 Linking with static library examples (2) source files : main2.c, vector.h static libraries : libvector.a, libc.a relocatable object files : main2.o, addvec.o, printf.o, any other modules called by printf.o fully linked executable object file : p2 Young W. Lim Link 7. Static Linking Fri 16 / 41
17 Resolving refereces with Static Libraries 1 Symbol resoltuion phase 2 for each input file f 3 for each member in the archive f 4 for undefined symbol set U is not empty 5 Link time error 6 Link time error example 7 Ordering libraries on the command line 8 Ordering libraries on the command line examples Young W. Lim Link 7. Static Linking Fri 17 / 41
18 Symbol resolution phase during the symbol resolution phase, the linker scans the relocatable object files and archives left to right ( ) in the same order that they appear on the command line the linker maintains a set E of relocatable object files that will be merged to form the executable a set U of unresolved symbols symbols referred to but not yet defined a set D of symbols that have been defined in the previous input files initially, all the set E, U, D are empty Young W. Lim Link 7. Static Linking Fri 18 / 41
19 for each input file f for each input file f on the command line, the linker determines if f is an object file or an archive for input file f, the linker adds f to E updates U and D to reflect the symbol definitions and references in f and proceeds to the next input file Young W. Lim Link 7. Static Linking Fri 19 / 41
20 for each input archive f the linker attempts to match the unresolved symbols in U against the symbols defined by the members of the archive any member object files which are not contained in E are discarded and the linker proceeds to the next input file Young W. Lim Link 7. Static Linking Fri 20 / 41
21 for each member in the archive f if some archive member m defines a symbol that resolves a reference in U then m is added to E then the linker updates U and D to reflect the symbol definitions and references in m this process iterates over the member of object files in f until a fixed point is reached where U and D no longer change Young W. Lim Link 7. Static Linking Fri 21 / 41
22 for undefined symbol set U is not empty if U is nonempty when the linker finishes scanning the input files on the command line, it prints an error and terminates otherwise, it merges and relocates the object files in E to build the output executable file Young W. Lim Link 7. Static Linking Fri 22 / 41
23 Link time error the ordering of libraries and object files on the command line is significant if the library that defines a symbol appear on the command line before the object file that references the symbol then the reference will not be resolved and the linking will fail void addvec(int *x, int *y) Young W. Lim Link 7. Static Linking Fri 23 / 41
24 Linke time error example when libvector.a is processed, U is empty therefore, no member object files from libvector.a is added to E the reference to addvec is never resolved error message gcc -static./libvector.a main2.c in function main : undefined reference to addvec gcc -static main2.c./libvector.a Young W. Lim Link 7. Static Linking Fri 24 / 41
25 Ordering libraries on the command line if the members of different libraries are independent (no member references a symbol defined by other member) then the libraries can be placed at the end of the command line in arbitrary order if they not independent, they must be ordered so that for each symbol s that is referenced externally by a member of an archive, at least one definition of s follows a reference to s Young W. Lim Link 7. Static Linking Fri 25 / 41
26 Ordering libraries on the command line example (1) foo.c calls functions in libx.a and libz.a which call functions in liby.a libx.a and libz.a must precedes liby.a on the command line gcc foo.c libx.a libz.a liby.a Young W. Lim Link 7. Static Linking Fri 26 / 41
27 Ordering libraries on the command line example (2) libraries can be repeated on the command line if necessary to satisfy the dependence requirements foo.c calls a function in libx.a which calls a function in liby.a which again calls a function in libx.a then libx.a must be repeated on the command line gcc foo.c libx.a liby.a libx.a alternatively, libx.a and liby.a can be combined into a single archive Young W. Lim Link 7. Static Linking Fri 27 / 41
28 n m ain.c // nothing.h static void donothingstatic(); void donothing(); void doalmostnothing(); // n_main.c #include "nothing.h" int main(int argc, const char *argv[]) { doalmostnothing(); return 0; } Young W. Lim Link 7. Static Linking Fri 28 / 41
29 donothingstatic, donothing, doalmostnothing // nothing.h static void donothingstatic(); void donothing(); void doalmostnothing(); // nothing.c #include "nothing.h" static void donothingstatic() { } void donothing() { } void doalmostnothing() { donothingstatic(); donothing(); } Young W. Lim Link 7. Static Linking Fri 29 / 41
30 disassemble (1) gcc -nostdlib -c -m32 nothing.c objdump -d nothing.o nothing.o: file format elf32-i386 Disassembly of section.text: <donothingstatic>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: e8 fc ff ff ff call 4 <donothingstatic+0x4> 8: add $0x1,%eax d: 90 nop e: 5d pop %ebp f: c3 ret Young W. Lim Link 7. Static Linking Fri 30 / 41
31 disassemble (2) <donothing>: 10: 55 push %ebp 11: 89 e5 mov %esp,%ebp 13: e8 fc ff ff ff call 14 <donothing+0x4> 18: add $0x1,%eax 1d: 90 nop 1e: 5d pop %ebp 1f: c3 ret <doalmostnothing>: 20: 55 push %ebp 21: 89 e5 mov %esp,%ebp 23: e8 fc ff ff ff call 24 <doalmostnothing+0x4> 28: add $0x1,%eax 2d: e8 ce ff ff ff call 0 <donothingstatic> 32: e8 fc ff ff ff call 33 <doalmostnothing+0x13> 37: 90 nop 38: 5d pop %ebp 39: c3 ret Young W. Lim Link 7. Static Linking Fri 31 / 41
32 disassemble (3) Disassembly of section.text. x86.get_pc_thunk.ax: < x86.get_pc_thunk.ax>: 0: 8b mov (%esp),%eax 3: c3 ret Young W. Lim Link 7. Static Linking Fri 32 / 41
33 relocation seciton readelf -r nothing.o Relocation section.rel.text at offset 0x288 contains 7 entries: Offset Info Type Sym.Value Sym. Name b02 R_386_PC x86.get_pc_thunk.ax c0a R_386_GOTPC _GLOBAL_OFFSET_TABLE_ b02 R_386_PC x86.get_pc_thunk.ax c0a R_386_GOTPC _GLOBAL_OFFSET_TABLE_ b02 R_386_PC x86.get_pc_thunk.ax c0a R_386_GOTPC _GLOBAL_OFFSET_TABLE_ d02 R_386_PC donothing Relocation section.rel.eh_frame at offset 0x2c0 contains 4 entries: Offset Info Type Sym.Value Sym. Name R_386_PC text R_386_PC text R_386_PC text R_386_PC text. x86.get_pc_thu Young W. Lim Link 7. Static Linking Fri 33 / 41
34 the final binary listing (1) objdump -D nothing.o nothing.o: file format elf32-i386 Disassembly of section.group: <.group>: 0: add %eax,(%eax) 2: add %al,(%eax) 4: 06 push %es 5: add %al,(%eax)... Disassembly of section.text: <donothingstatic>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: e8 fc ff ff ff call 4 <donothingstatic+0x4> 8: add $0x1,%eax d: 90 nop e: 5d pop %ebp f: c3 ret Young W. Lim Link 7. Static Linking Fri 34 / 41
35 the final binary listing (2) <donothing>: 10: 55 push %ebp 11: 89 e5 mov %esp,%ebp 13: e8 fc ff ff ff call 14 <donothing+0x4> 18: add $0x1,%eax 1d: 90 nop 1e: 5d pop %ebp 1f: c3 ret <doalmostnothing>: 20: 55 push %ebp 21: 89 e5 mov %esp,%ebp 23: e8 fc ff ff ff call 24 <doalmostnothing+0x4> 28: add $0x1,%eax 2d: e8 ce ff ff ff call 0 <donothingstatic> 32: e8 fc ff ff ff call 33 <doalmostnothing+0x13> 37: 90 nop 38: 5d pop %ebp 39: c3 ret Disassembly of section.text. x86.get_pc_thunk.ax: < x86.get_pc_thunk.ax>: 0: 8b mov (%esp),%eax 3: Young c3 W. Lim ret Link 7. Static Linking Fri 35 / 41
36 the final binary listing (3) Disassembly of section.comment: <.comment>: 0: add %al,0x43(%edi) 3: 43 inc %ebx 4: 3a 20 cmp (%eax),%ah 6: sub %dl,0x62(%ebp) 9: 75 6e jne 79 <doalmostnothing+0x59> b: je 82 <doalmostnothing+0x62> d: and %dh,(%edi) f: 2e 33 2e xor %cs:(%esi),%ebp 12: 30 2d xor %ch,0x : 75 6e jne 88 <doalmostnothing+0x68> 1a: je 91 <doalmostnothing+0x71> 1c: 31 7e 31 xor %edi,0x31(%esi) 1f: 38 2e cmp %ch,(%esi) 21: xor %dh,(%ecx,%ebp,1) 24: and %dh,(%edi) 26: 2e 33 2e xor %cs:(%esi),%ebp 29: xor %al,(%eax) Young W. Lim Link 7. Static Linking Fri 36 / 41
37 the final binary listing (4) Disassembly of section.eh_frame: <.eh_frame>: 0: adc $0x0,%al 2: add %al,(%eax) 4: add %al,(%eax) 6: add %al,(%eax) 8: 01 7a 52 add %edi,0x52(%edx) b: add %al,(%ecx) d: 7c 08 jl 17 <.eh_frame+0x17> f: 01 1b add %ebx,(%ebx) 11: 0c 04 or $0x4,%al 13: add $0x88,%al 15: add %eax,(%eax) 17: 00 1c 00 add %bl,(%eax,%eax,1) 1a: add %al,(%eax) 1c: 1c 00 sbb $0x0,%al 1e: add %al,(%eax) 20: add %al,(%eax) 22: add %al,(%eax) 24: adc %al,(%eax) 26: add %al,(%eax) 28: e add %al,0xe(%ecx) 2b: d 05 or %al,0x50d4202(%ebp) Young W. Lim Link 7. Static Linking Fri 37 / 41
38 the final binary listing (5) 31: 4c dec %esp 32: c5 0c 04 lds (%esp,%eax,1),%ecx 35: add $0x0,%al 37: 00 1c 00 add %bl,(%eax,%eax,1) 3a: add %al,(%eax) 3c: 3c 00 cmp $0x0,%al 3e: add %al,(%eax) 40: adc %al,(%eax) 42: add %al,(%eax) 44: adc %al,(%eax) 46: add %al,(%eax) 48: e add %al,0xe(%ecx) 4b: d 05 or %al,0x50d4202(%ebp) 51: 4c dec %esp 52: c5 0c 04 lds (%esp,%eax,1),%ecx 55: add $0x0,%al 57: 00 1c 00 add %bl,(%eax,%eax,1) 5a: add %al,(%eax) 5c: 5c pop %esp 5d: add %al,(%eax) 5f: add %ah,(%eax) Young W. Lim Link 7. Static Linking Fri 38 / 41
39 the final binary listing (6) 61: add %al,(%eax) 63: 00 1a add %bl,(%edx) 65: add %al,(%eax) 67: add %al,(%eax) 69: 41 inc %ecx 6a: 0e push %cs 6b: d 05 or %al,0x50d4202(%ebp) 71: 56 push %esi 72: c5 0c 04 lds (%esp,%eax,1),%ecx 75: add $0x0,%al 77: add %dl,(%eax) 79: add %al,(%eax) 7b: 00 7c add %bh,0x0(%eax,%eax,1) 7f: add %al,(%eax) 81: add %al,(%eax) 83: add %al,(%eax,%eax,1) 86: add %al,(%eax) 88: add %al,(%eax) Young W. Lim Link 7. Static Linking Fri 39 / 41
40 relocation information in nmain.o gcc -nostdlib -c -m32 nmain.c readelf -s --wide nmain.o grep doalmostnothing 13: NOTYPE GLOBAL DEFAULT UND doalmostnothing young@usys1:~$ readelf -r nmain.o Relocation section.rel.text at offset 0x224 contains 3 entries: Offset Info Type Sym.Value Sym. Name b02 R_386_PC x86.get_pc_thunk.ax c0a R_386_GOTPC _GLOBAL_OFFSET_TABLE_ c 00000d04 R_386_PLT doalmostnothing Relocation section.rel.eh_frame at offset 0x23c contains 2 entries: Offset Info Type Sym.Value Sym. Name R_386_PC text R_386_PC text. x86.get_pc_thu Young W. Lim Link 7. Static Linking Fri 40 / 41
41 relocation information in nmain.out gcc -m32 -o nmain.out nmain.o nothing.o readelf -r nmain.out Relocation section.rel.dyn at offset 0x310 contains 8 entries: Offset Info Type Sym.Value Sym. Name 00001edc R_386_RELATIVE 00001ee R_386_RELATIVE 00001ff R_386_RELATIVE R_386_RELATIVE 00001fec R_386_GLOB_DAT _ITM_deregisterTMClone 00001ff R_386_GLOB_DAT cxa_finalize@glibc_ ff R_386_GLOB_DAT gmon_start 00001ffc R_386_GLOB_DAT _ITM_registerTMCloneTa Relocation section.rel.plt at offset 0x350 contains 1 entry: Offset Info Type Sym.Value Sym. Name 00001fe R_386_JUMP_SLOT libc_start_main@glibc_2.0 Young W. Lim Link 7. Static Linking Fri 41 / 41
Link 7.A Static Linking
Link 7.A Static Linking Young W. Lim 2019-01-04 Fri Young W. Lim Link 7.A Static Linking 2019-01-04 Fri 1 / 27 Outline 1 Linking - 7.A Static Linking Based on Static Library Examples Linking with Static
More informationLink 7. Dynamic Linking
Link 7. Dynamic Linking Young W. Lim 2018-10-05 Fri Young W. Lim Link 7. Dynamic Linking 2018-10-05 Fri 1 / 26 Outline 1 Linking - 7. Dynamic Linking Based on Dynamic Shared Library Examples Young W. Lim
More informationLink 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 informationLink 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 informationCSE 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 informationLink 4. Relocation. Young W. Lim Wed. Young W. Lim Link 4. Relocation Wed 1 / 22
Link 4. Relocation Young W. Lim 2017-09-13 Wed Young W. Lim Link 4. Relocation 2017-09-13 Wed 1 / 22 Outline 1 Linking - 4. Relocation Based on Relocation Relocation Entries Relocating Symbol Reference
More informationExample 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 informationExample C Program The course that gives CMU its Zip! Linking March 2, Static Linking. Why Linkers? Page # Topics
15-213 The course that gives CMU its Zip! Topics Linking March 2, 24 Static linking Dynamic linking Case study: Library interpositioning Example C Program main.c int buf[2] = 1, 2; int main() swap(); return
More informationLink 4. Relocation. Young W. Lim Thr. Young W. Lim Link 4. Relocation Thr 1 / 26
Link 4. Relocation Young W. Lim 2017-09-14 Thr Young W. Lim Link 4. Relocation 2017-09-14 Thr 1 / 26 Outline 1 Linking - 4. Relocation Based on Relocation Relocation Entries Relocating Symbol Reference
More informationLink 2. Object Files
Link 2. Object Files Young W. Lim 2017-09-20 Wed Young W. Lim Link 2. Object Files 2017-09-20 Wed 1 / 33 Outline 1 Linking - 2. Object Files Based on Oject Files ELF Sections Example Program Source Codes
More informationLink 2. Object Files
Link 2. Object Files Young W. Lim 2017-09-23 Sat Young W. Lim Link 2. Object Files 2017-09-23 Sat 1 / 40 Outline 1 Linking - 2. Object Files Based on Oject Files ELF Sections Example Program Source Codes
More informationLinking February 24, 2005
15-213 The course that gives CMU its Zip! Linking February 24, 2005 Topics Static linking Dynamic linking Case study: Library interpositioning 13-linking.ppt Example C Program main.c int buf[2] = {1, 2};
More informationLink 3. Symbols. Young W. Lim Mon. Young W. Lim Link 3. Symbols Mon 1 / 42
Link 3. Symbols Young W. Lim 2017-09-11 Mon Young W. Lim Link 3. Symbols 2017-09-11 Mon 1 / 42 Outline 1 Linking - 3. Symbols Based on Symbols Symbol Tables Symbol Table Examples main.o s symbol table
More informationLecture 16: Linking Computer Architecture and Systems Programming ( )
Systems Group Department of Computer Science ETH Zürich Lecture 16: Linking Computer Architecture and Systems Programming (252-0061-00) Timothy Roscoe Herbstsemester 2012 Last time: memory hierarchy L1/L2
More informationExample C Program. Linking CS Instructor: Sanjeev Se(a. int buf[2] = {1, 2}; extern int buf[]; int main() { swap(); return 0; }
Linking Instructor: Sanjeev Se(a 1 Example C Program main.c int buf[2] = {1, 2; int main() { swap(); return 0; swap.c extern int buf[]; static int *bufp0 = &buf[0]; static int *bufp1; void swap() { int
More informationComputer Systems. Linking. Han, Hwansoo
Computer Systems Linking Han, Hwansoo Example C Program int sum(int *a, int n); int array[2] = {1, 2}; int sum(int *a, int n) { int i, s = 0; int main() { int val = sum(array, 2); return val; } main.c
More informationLinking. Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3. Instructor: Joanna Klukowska
Linking Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed Zahran (NYU) Example C
More informationSystems Programming and Computer Architecture ( ) Timothy Roscoe
Systems Group Department of Computer Science ETH Zürich Systems Programming and Computer Architecture (252-0061-00) Timothy Roscoe Herbstsemester 2016 AS 2016 Linking 1 12: Linking Computer Architecture
More informationProcedure 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 informationStack Tutorial. Young W. Lim Sat. Young W. Lim Stack Tutorial Sat 1 / 15
Stack Tutorial Young W. Lim 2016-10-15 Sat Young W. Lim Stack Tutorial 2016-10-15 Sat 1 / 15 Outline 1 Introduction References Stack Background Transferring Control Young W. Lim Stack Tutorial 2016-10-15
More informationSystems 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 informationProcedure 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 informationLINKING. 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 informationLinking. Today. Next time. Static linking Object files Static & dynamically linked libraries. Exceptional control flows
Linking Today Static linking Object files Static & dynamically linked libraries Next time Exceptional control flows Fabián E. Bustamante, 2007 Example C program main.c void swap(); int buf[2] = {1, 2;
More informationExercise 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 informationOutline. 1 Background. 2 ELF Linking. 3 Static Linking. 4 Dynamic Linking. 5 Summary. Linker. Various Stages. 1 Linking can be done at compile.
Outline CS 6V81-05: System Security and Malicious Code Analysis Revealing Internals of Linkers Zhiqiang Lin Department of Computer Science University of Texas at Dallas March 26 th, 2012 1 Background 2
More informationAccess. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18
Access Young W. Lim 2017-01-27 Fri Young W. Lim Access 2017-01-27 Fri 1 / 18 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Young W. Lim Access 2017-01-27 Fri 2 / 18 Based
More informationELF (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 informationCS429: 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 informationAccess. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19
Access Young W. Lim 2017-06-10 Sat Young W. Lim Access 2017-06-10 Sat 1 / 19 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Data Movement Examples Young W. Lim Access 2017-06-10
More informationRevealing Internals of Linkers. Zhiqiang Lin
CS 6V81-05: System Security and Malicious Code Analysis Revealing Internals of Linkers Zhiqiang Lin Department of Computer Science University of Texas at Dallas March 26 th, 2012 Outline 1 Background 2
More informationRelocating 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 informationLink 4. Relocation. Young W. Lim Sat. Young W. Lim Link 4. Relocation Sat 1 / 33
Link 4. Relocation Young W. Lim 2017-09-16 Sat Young W. Lim Link 4. Relocation 2017-09-16 Sat 1 / 33 Outline 1 Linking - 4. Relocation Based on Relocation Relocation Entries Relocating Symbol Reference
More informationComputer Organization: A Programmer's Perspective
A Programmer's Perspective Linking Gal A. Kaminka galk@cs.biu.ac.il A Simplistic Program Translation Scheme m.c ASCII source file Translator p Binary executable object file (memory image on disk) Problems:
More informationLinking Oct. 15, 2002
15-213 The course that gives CMU its Zip! Topics Linking Oct. 15, 2002 Static linking Object files Static libraries Loading Dynamic linking of shared libraries class15.ppt Linker Puzzles int x; p1() {}
More informationCSE2421 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 informationLink Edits and Relocatable Code
Link Edits and Relocatable Code Computer Systems Chapter 7.4-7.7 gcc g o ttt ttt.c ttt.c gcc ttt Pre-Processor Linker Compiler Assembler ttt.s ttt.o gcc g o ttt ttt.c main.c gcc cmd util.c Pre-Processor
More informationE = 2 e lines per set. S = 2 s sets tag. valid bit B = 2 b bytes per cache block (the data) CSE351 Inaugural EdiNon Spring
Last Time Caches E = 2 e lines per set Address of word: t bits s bits b bits S = 2 s sets tag set index block offset data begins at this offset v tag 0 1 2 B 1 valid bit B = 2 b bytes per cache block (the
More informationLinking Oct. 26, 2009"
Linking Oct. 26, 2009" Linker Puzzles" int x; p1() {} p1() {} int x; p1() {} int x; p2() {} int x; int y; p1() {} int x=7; int y=5; p1() {} double x; p2() {} double x; p2() {} int x=7; p1() {} int x; p2()
More informationLinking and Loading. CS61, Lecture 16. Prof. Stephen Chong October 25, 2011
Linking and Loading CS61, Lecture 16 Prof. Stephen Chong October 25, 2011 Announcements Midterm exam in class on Thursday 80 minute exam Open book, closed note. No electronic devices allowed Please be
More informationCS 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 informationStack Debugging. Young W. Lim Thr. Young W. Lim Stack Debugging Thr 1 / 12
Stack Debugging Young W. Lim 2017-07-13 Thr Young W. Lim Stack Debugging 2017-07-13 Thr 1 / 12 Outline 1 Introduction References Compiling to IA32 Assembly Checking /proc//maps file Young W. Lim Stack
More informationStack 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 informationArrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17
Arrays Young W. Lim 2017-02-06 Mon Young W. Lim Arrays 2017-02-06 Mon 1 / 17 Outline 1 Introduction References Array Background Young W. Lim Arrays 2017-02-06 Mon 2 / 17 Based on "Self-service Linux: Mastering
More informationLinkers and Loaders. CS 167 VI 1 Copyright 2008 Thomas W. Doeppner. All rights reserved.
Linkers and Loaders CS 167 VI 1 Copyright 2008 Thomas W. Doeppner. All rights reserved. Does Location Matter? int main(int argc, char *[ ]) { return(argc); } main: pushl %ebp ; push frame pointer movl
More informationLink 4. Relocation. Young W. Lim Tue. Young W. Lim Link 4. Relocation Tue 1 / 38
Link 4. Relocation Young W. Lim 2017-09-26 Tue Young W. Lim Link 4. Relocation 2017-09-26 Tue 1 / 38 Outline 1 Linking - 4. Relocation Based on Relocation Relocation Entries Relocation Algorithm Reloation
More informationMachine 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 informationLink 8.B Dynamic Linking
Link 8.B Dynamic Linking Young W. Lim 2019-01-11 Fri Young W. Lim Link 8.B Dynamic Linking 2019-01-11 Fri 1 / 80 Outline 1 Based on 2 background readelf background PIC background 3 example codes 4 examining
More informationLink 4. Relocation. Young W. Lim Mon. Young W. Lim Link 4. Relocation Mon 1 / 35
Link 4. Relocation Young W. Lim 2017-09-25 Mon Young W. Lim Link 4. Relocation 2017-09-25 Mon 1 / 35 Outline 1 Linking - 4. Relocation Based on Relocation Relocation Entries Relocating Symbol Reference
More information238P: 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 informationArrays. Young W. Lim Wed. Young W. Lim Arrays Wed 1 / 19
Arrays Young W. Lim 2017-02-08 Wed Young W. Lim Arrays 2017-02-08 Wed 1 / 19 Outline 1 Introduction References Array Background Young W. Lim Arrays 2017-02-08 Wed 2 / 19 Based on "Self-service Linux: Mastering
More informationCPS104 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 informationSystem 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 informationELF (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 informationUniversità 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 informationCS241 Computer Organization Spring Buffer Overflow
CS241 Computer Organization Spring 2015 Buffer Overflow 4-02 2015 Outline! Linking & Loading, continued! Buffer Overflow Read: CSAPP2: section 3.12: out-of-bounds memory references & buffer overflow K&R:
More informationDay05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14
Day05 A Young W. Lim 2017-10-07 Sat Young W. Lim Day05 A 2017-10-07 Sat 1 / 14 Outline 1 Based on 2 Structured Programming (2) Conditions and Loops Conditional Statements Loop Statements Type Cast Young
More informationLink 4. Relocation. Young W. Lim Thr. Young W. Lim Link 4. Relocation Thr 1 / 48
Link 4. Relocation Young W. Lim 2017-09-28 Thr Young W. Lim Link 4. Relocation 2017-09-28 Thr 1 / 48 Outline 1 Linking - 4. Relocation Based on Relocation Relocation Entries Relocation Algorithm Reloation
More informationSungkyunkwan University
Linking Case study: Library interpositioning main.c int buf[2] = {1, 2}; int main() { swap(); return 0; } swap.c extern int buf[]; int *bufp0 = &buf[0]; static int *bufp1; void swap() { int temp; } bufp1
More informationGenerating 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 informationGDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32
GDB Tutorial Young W. Lim 2017-02-14 Tue Young W. Lim GDB Tutorial 2017-02-14 Tue 1 / 32 Outline 1 Introduction Young W. Lim GDB Tutorial 2017-02-14 Tue 2 / 32 Based on "Self-service Linux: Mastering the
More informationBinghamton University. CS-220 Spring Loading Code. Computer Systems Chapter 7.5, 7.8, 7.9
Loading Code Computer Systems Chapter 7.5, 7.8, 7.9 gcc g o ttt ttt.c ttt.c ttt gcc gcc g o ttt ttt.c ttt.c gcc ttt Pre-Processor Linker Compiler Assembler ttt.s ttt.o What is in a binary executable file?
More informationDay02 A. Young W. Lim Sat. Young W. Lim Day02 A Sat 1 / 12
Day02 A Young W. Lim 2017-10-07 Sat Young W. Lim Day02 A 2017-10-07 Sat 1 / 12 Outline 1 Based on 2 Introduction (2) - Basic Elements Basic Elements in C Programming Young W. Lim Day02 A 2017-10-07 Sat
More informationA SimplisHc Program TranslaHon Scheme. TranslaHng the Example Program. Example C Program. Why Linkers? - Modularity. Linking
A SimplisHc Program TranslaHon Scheme Linking ASCII (Text) source file The American Standard Code for InformaHon Interchange (ASCII) CSCI 221: Machine Architecture and OrganizaHon Pen- Chung Yew Department
More informationLecture 12-13: Linking
CSCI-UA.0201-003 Computer Systems Organization Lecture 12-13: Linking Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Source Code to Execution C source Assembly Assembly Compiler Assembly
More informationCIT 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 informationExecutables 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 informationCS , Spring 2002 Exam 2
Full Name: CS 15-213, Spring 2002 Exam 2 March 28, 2002 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write your answers
More informationCS165 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 informationCS 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 informationIntroduction 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 informationAssembly 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 informationExecutables 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 informationA Simplistic Program Translation Scheme
A Simplistic Program Translation Scheme m.c ASCII source file Translator p Binary executable object file (memory image on disk) Problems: Efficiency: small change requires complete recompilation Modularity:
More informationDay06 A. Young W. Lim Mon. Young W. Lim Day06 A Mon 1 / 16
Day06 A Young W. Lim 2017-09-18 Mon Young W. Lim Day06 A 2017-09-18 Mon 1 / 16 Outline 1 Based on 2 Introduction C Program Control Young W. Lim Day06 A 2017-09-18 Mon 2 / 16 Based on "C How to Program",
More information(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 informationGDB Tutorial. Young W. Lim Fri. Young W. Lim GDB Tutorial Fri 1 / 24
GDB Tutorial Young W. Lim 2016-02-19 Fri Young W. Lim GDB Tutorial 2016-02-19 Fri 1 / 24 Outline 1 Introduction Young W. Lim GDB Tutorial 2016-02-19 Fri 2 / 24 Based on Self-service Linux: Mastering the
More informationToday s Big Adventure
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 that don t exist yet How to merge separate name spaces into a cohesive whole More information: - How
More informationTowards the Hardware"
CSC 2400: Computer Systems Towards the Hardware Chapter 2 Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 High-Level Language Make programming
More informationFrom Website:
From Website: http://resources.infosecinstitute.com/hello-world-c-assembly-object-file-and-executable/ Hello World: C, Assembly, Object File and Executable By Dejan Lukan January 7th, 2013 Introduction
More informationLinker Puzzles The course that gives CMU its Zip! Linking Mar 4, A Simplistic Program Translation Scheme. A Better Scheme Using a Linker
15-213 The course that gives CMU its Zi! Toics Static linking Object files Linking Mar 4, 2003 Static libraries Loading Dynamic linking of shared libraries Linker Puzzles 1() { 1() { 1() { 1() { int x=7;
More informationMidterm results Mean: 43, median: 40
Midterm results 30 25 20 15 10 5 0 0 9 10 19 20 29 30 39 40 49 50 59 60 69 70 79 80 89 90 99 100 Mean: 43, median: 40 1 / 45 Midterm results 100% 80% 60% 40% 20% 0% 0 20 40 60 80 100 Systems students should
More informationDay08 A. Young W. Lim Mon. Young W. Lim Day08 A Mon 1 / 27
Day08 A Young W. Lim 2017-10-16 Mon Young W. Lim Day08 A 2017-10-16 Mon 1 / 27 Outline 1 Based on 2 C Functions (2) Storage Class and Scope Storage Class Specifiers A. Storage Duration B. Scope C. Linkage
More informationGAS Tutorial - 4. Sections & Relocation
GAS Tutorial - 4. Sections & Relocation Young W. Lim 2016-03-01 Tue Young W. Lim GAS Tutorial - 4. Sections & Relocation 2016-03-01 Tue 1 / 22 Outline 1 Sections and Relocation Young W. Lim GAS Tutorial
More informationDay06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26
Day06 A Young W. Lim 2017-09-20 Wed Young W. Lim Day06 A 2017-09-20 Wed 1 / 26 Outline 1 Based on 2 C Program Control Overview for, while, do... while break and continue Relational and Logical Operators
More informationOverview REWARDS TIE HOWARD Summary CS 6V Data Structure Reverse Engineering. Zhiqiang Lin
CS 6V81-05 Data Structure Reverse Engineering Zhiqiang Lin Department of Computer Science The University of Texas at Dallas September 2 nd, 2011 Outline 1 Overview 2 REWARDS 3 TIE 4 HOWARD 5 Summary Outline
More informationCompiler 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 informationBuffer 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 informationTurning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p
Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm
More informationOverview of Compiler. A. Introduction
CMPSC 470 Lecture 01 Topics: Overview of compiler Compiling process Structure of compiler Programming language basics Overview of Compiler A. Introduction What is compiler? What is interpreter? A very
More informationOutline. 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 informationCSC 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 informationThis 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 informationGDB Tutorial. Young W. Lim Thr. Young W. Lim GDB Tutorial Thr 1 / 24
GDB Tutorial Young W. Lim 2016-09-29 Thr Young W. Lim GDB Tutorial 2016-09-29 Thr 1 / 24 Outline 1 Introduction Young W. Lim GDB Tutorial 2016-09-29 Thr 2 / 24 Based on "Self-service Linux: Mastering the
More informationLecture 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 informationCS2141 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 informationCSC 591 Systems Attacks and Defenses Return-into-libc & ROP
CSC 591 Systems Attacks and Defenses Return-into-libc & ROP Alexandros Kapravelos akaprav@ncsu.edu NOEXEC (W^X) 0xFFFFFF Stack Heap BSS Data 0x000000 Code RW RX Deployment Linux (via PaX patches) OpenBSD
More informationu Linking u Case study: Library interpositioning
u Linking u Case study: Library interpositioning int sum(int *a, int n); int array[2] = {1, 2}; int sum(int *a, int n) { int i, s = 0; int main() { int val = sum(array, 2); return val; } main.c } for (i
More informationHomework. 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 informationOutline. x86 Architecture
Data Representation Code Representation Summary Data Representation Code Representation Summary Code Representation Summary Outline CS 6V81-05: System Security and Malicious Code Analysis 1 2 Data Representation
More information