COP 3515 IT Program DesignAlessio Gaspar … 1 C Development Environment.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
Fabián E. Bustamante, Spring 2007 Linking Today Static linking Object files Static & dynamically linked libraries Next time Exceptional control flows.
Architecture Chapter 2 - Supplement Additional Features In Chapter 2.
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 7, 2012 CSCE 212Honors Computer Organization.
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.
Lecture 2. Instructions and High-level to Machine Code Prof. Taeweon Suh Computer Science Education Korea University ECM534 Advanced Computer Architecture.
Beginning Assembly, Part 2 The Assembling! Poorly Presented by Gleep.
Linking and Loading Fred Prussack CS 518. L&L: Overview Wake-up Questions Terms and Definitions / General Information LoadingLinking –Static vs. Dynamic.
C Module System C and Data Structures Baojian Hua
1 Simple C Programs. 2 Goals for this Lecture Help you learn about: Simple C programs Program structure Defining symbolic constants Detecting and reporting.
Cse322, Programming Languages and Compilers 1 6/18/2015 Lecture #16, May 24, 2007 Runtime.c Running the code debugging assembler division strings for println.
Recitation 1 Session 5 Ishani Chakraborty. Machine Level Representation What happens to a C program when we compile it ? $ gcc prog.c Preprocessor (expands.
C Module System C and Data Structures Baojian Hua
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
1-1 Embedded Software Development Tools and Processes Hardware & Software Hardware – Host development system Software – Compilers, simulators etc. Target.
Computer Architecture and Assembly Languages Course’s web site: Teaching Assistant: Or Peri Office Hours: Thursday 37/-108.
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
F13 Forensic tool analysis Dr. John P. Abraham Professor UTPA.
Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages.
嵌入式處理器架構與程式設計 王建民 中央研究院 資訊所 2008 年 7 月. 2 Contents Introduction Computer Architecture ARM Architecture Development Tools  GNU Development Tools ARM Instruction.
CSU System Programming, NTNU CSIE1 / 99 Linkers and Libraries Advisor: Dr. Gwan-Hwan Hwang Lecturer: Che-Sheng Lin.
Lecture 7. Instructions and High-Level to Machine Code Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Lecture-1 Compilation process
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Lecture 1. General-Purpose Computer Systems
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
1 Linking. 2 Outline What is linking and why linking Complier driver Static linking Symbols & Symbol Table Suggested reading: 7.1~7.5.
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
Linking I Topics Assembly and symbol resolution Static linking Systems I.
Hello world !!! ASCII representation of hello.c.
Lecture 2. Instructions and High-level to Machine Code Prof. Taeweon Suh Computer Science & Engineering Korea University COSE222, COMP212, CYDF210 Computer.
Operating Systems A Biswas, Dept. of Information Technology.
The World Leader in High Performance Signal Processing Solutions Toolchain Basics.
Object Files & Linking. Object Sections Compiled code store as object files – Linux : ELF : Extensible Linking Format – Windows : PE : Portable Execution.
Visual Linker ADD presentation. slide 2  Project Overview And Vision  Project System View  The System Life Cycle  Data Model and.
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Programs – Preprocessing, Compilation and Linking
Precept I : Lab Environment, Unix, Bash, Emacs
Instruction Set Architecture
Credits and Disclaimers
Linking Topics Static linking Object files Static libraries Loading
Tools of the Trade
Conditional Branch Example
Homework In-line Assembly Code Machine Language
Program Execution in Linux
Assembly Language Programming V: In-line Assembly Code
and Executing Programs
C Programming Lecture Series
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
“The course that gives CMU its Zip!”
Assembly Language Programming II: C Compiler Calling Sequences
“The course that gives CMU its Zip!”
CSE 303 Concepts and Tools for Software Development
Program Execution in Linux
Appendix F C Programming Environment on UNIX Systems
Grades so far (max was 31).
Video Notes.
Machine-Level Programming I: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Credits and Disclaimers
“The course that gives CMU its Zip!”
Computer Architecture and System Programming Laboratory
The ‘asm’ construct An introduction to the GNU C/C++ compiler’s obscure syntax for doing inline assembly language.
Presentation transcript:

COP 3515 IT Program DesignAlessio Gaspar … 1 C Development Environment

COP 3515 IT Program DesignAlessio Gaspar … 2 Designing[Your Brain™] Editing[xemacs, vi ?!] Compiling[gcc] Code Checking[lint, smash] Testing / Debugging [gdb, gof printf] Purifying [e-fence, valgrind, purify] Profiling & Optimizing[gcov, gprof] Packaging[deb, rpm] Life Cycle of a C program Development

COP 3515 IT Program DesignAlessio Gaspar … 3 Compiling with GCC GCC -o hw hw.c Let’s get it done the simplest way first #include int main ( ) { printf (“hi\n”); } #include int main ( ) { printf (“hi\n”); } Source code File hw.c hw Executable File

COP 3515 IT Program DesignAlessio Gaspar … 4 Compiling with GCC in one step gcc -o hw hw.c Source File hw Executable File [tux:~/hw]: GCC -o hw hw.c [tux:~/hw]: ls -l hw -rwxr-xr-x 1 gaspara voicedb Aug 8 15:05 hw [tux:~/hw]:./hw hi [tux:~/hw]: GCC -o hw hw.c [tux:~/hw]: ls -l hw -rwxr-xr-x 1 gaspara voicedb Aug 8 15:05 hw [tux:~/hw]:./hw hi hw.c [tux:~/hw]: file hw hw: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked (uses shared libs), not stripped [tux:~/hw]: more /usr/share/magic [tux:~/hw]: file hw hw: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked (uses shared libs), not stripped [tux:~/hw]: more /usr/share/magic

COP 3515 IT Program DesignAlessio Gaspar … 5 Compiling with GCC in two steps gcc -c hw.c Source File hw.o Object File [tux:~/hw]: GCC -c hw.c [tux:~/hw]: ls -l hw.o [tux:~/hw]: file hw.o [tux:~/hw]: GCC -o hw2 hw.o [tux:~/hw]: ls -l hw hw2 [tux:~/hw]: file hw2 [tux:~/hw]: GCC -c hw.c [tux:~/hw]: ls -l hw.o [tux:~/hw]: file hw.o [tux:~/hw]: GCC -o hw2 hw.o [tux:~/hw]: ls -l hw hw2 [tux:~/hw]: file hw2 hw.c hw Executable File gcc -o hw hw.o

COP 3515 IT Program DesignAlessio Gaspar … 6 What’s behind GCC ? cpp0 Source File hw.i Expanded Source File hw.c hw.s asm File ccl Preprocessor hw.o obj File as hw Exec File ld collect2 /usr/lib Libraries /usr/lib Libraries Compiler Assembler Link Editor / Linker Other User.o Files Other User.o Files

COP 3515 IT Program DesignAlessio Gaspar … 7 More Informations about GCC ? hw.i Expanded Source File hw.s Asm File hw.o Obj File hw Exec File Different Types of Files’ Extensions are detailed in man gcc Similarly, options to stop GCC at any step of the source code processing chain are available -cStops after hw.o -SStops after hw.s -EStops after hw.i Different Types of Files’ Extensions are detailed in man gcc Similarly, options to stop GCC at any step of the source code processing chain are available -cStops after hw.o -SStops after hw.s -EStops after hw.i

COP 3515 IT Program DesignAlessio Gaspar … 8 Precompiling hw.i Expanded Source File hw.s Asm File hw.o Obj File hw Exec File cpp #include int main ( ) { printf (“hi\n”); } #include int main ( ) { printf (“hi\n”); } Source code File hw.c int main ( ) { printf (“hi\n”); } int main ( ) { printf (“hi\n”); } Expanded Source File hw.i Contents of /usr/include/stdio.h Contents of /usr/include/stdio.h GCC -E hw.c

COP 3515 IT Program DesignAlessio Gaspar … 9 Compiling hw.i Expanded Source File hw.s Asm File hw.o Obj File hw Exec File ccl int main ( ) { printf (“hi\n”); } int main ( ) { printf (“hi\n”); } Expanded Source File hw.i Contents of /usr/include/stdio.h Contents of /usr/include/stdio.h Asm Source File hw.s (…) main: pushl %ebp movl %esp, %ebp subl $8, %esp subl $12, %esp pushl $.LC0 call printf addl $16, %esp (…) main: pushl %ebp movl %esp, %ebp subl $8, %esp subl $12, %esp pushl $.LC0 call printf addl $16, %esp (…) GCC -S hw.c

COP 3515 IT Program DesignAlessio Gaspar … 10 Assembling hw.i Expanded Source File hw.s Asm File hw.o Obj File hw Exec File as Asm Source File hw.s (…) main: pushl %ebp movl %esp, %ebp subl $8, %esp subl $12, %esp pushl $.LC0 call printf addl $16, %esp (…) main: pushl %ebp movl %esp, %ebp subl $8, %esp subl $12, %esp pushl $.LC0 call printf addl $16, %esp (…) hw.o Obj File Relocatable Object File = assembled asm code (architecture dependent) = ELF32_i386 format (linux) Ready for link w/ other obj to form an executable file Relocatable Object File = assembled asm code (architecture dependent) = ELF32_i386 format (linux) Ready for link w/ other obj to form an executable file GCC -c hw.c

COP 3515 IT Program DesignAlessio Gaspar … 11 Linking hw.i Expanded Source File hw.s Asm File hw.o Obj File hw Exec File ld hw.o Obj File Gathering altogether Your Object Files Object Files from libraries The C runtime code Gathering altogether Your Object Files Object Files from libraries The C runtime code hw Exec File GCC -o hw hw.c

COP 3515 IT Program DesignAlessio Gaspar … 12 Linking hw.i Expanded Source File hw.s Asm File hw.o Obj File hw Exec File ld hw.o Obj File A taste of what linking is really about… (edited) ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o hw /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/lib/ hw.o -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crtn.o A taste of what linking is really about… (edited) ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o hw /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/lib/ hw.o -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crtn.o hw Exec File

COP 3515 IT Program DesignAlessio Gaspar … 13 Blank Slide…