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

Similar documents
CS 342 Software Design Spring 2018 Term Project Part III Saving and Restoring Exams and Exam Components

CS 342 Software Design Spring 2018 Term Project Part II Development of Question, Answer, and Exam Classes

CS 450 Introduction to Networking Spring 2014 Homework Assignment 1 File Transfer and Data Bandwidth Analysis Tool

CS 385 Operating Systems Fall 2011 Homework Assignment 4 Simulation of a Memory Paging System

CS 342 Software Design Fall 2018 Term Project Part II Addition of Artifacts and Data File Processing

CS 385 Operating Systems Fall 2011 Homework Assignment 5 Process Synchronization and Communications

CS 361 Computer Systems Fall 2017 Homework Assignment 4 - Inter-Process Communications & I/O

CS 107 Introduction to Computing and Programming Fall 2013 Homework Assignment 7 - First Draft Atomic Weights of Compounds with Pointers to Structures

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

CS 109 C/C ++ Programming for Engineers w. MatLab Summer 2012 Homework Assignment 4 Functions Involving Barycentric Coordinates and Files

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

Ch. 3: The C in C++ - Continued -

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

COMP26120 Academic Session: Lab Exercise 2: Input/Output; Strings and Program Parameters; Error Handling

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CSE 351. Introduction & Course Tools

CS 142 Style Guide Grading and Details

CSE 303, Spring 2009 Final Exam Wednesday, June 10, 2009

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

C / C++ Coding Rules

PROGRAMMAZIONE I A.A. 2017/2018

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

CS Programming In C

York University Faculty Science and Engineering Fall 2008

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

C++ Programming for Non-C Programmers. Supplement

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False.

CSE 12 Spring 2016 Week One, Lecture Two

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

Lab 03 - x86-64: atoi

CE221 Programming in C++ Part 1 Introduction

Chapter 11 Introduction to Programming in C

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

Pointer Casts and Data Accesses

Chapter 1 Getting Started

Arrays and Pointers (part 2) Be extra careful with pointers!

Supporting Class / C++ Lecture Notes

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002

Lab 1: First Steps in C++ - Eclipse

Programming Assignment #4 Arrays and Pointers

EEL 3801 Introduction to Computer Engineering Summer Home Work Schedule

C Language Coding Standard

Online Judge and C. Roy Chan. January 12, Outline Information Online Judge Introduction to C. CSC2100B Data Structures Tutorial 1

CpSc 1111 Lab 9 2-D Arrays

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Chapter 11 Introduction to Programming in C

CS354 gdb Tutorial Written by Chris Feilbach

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CS 385 Operating Systems Spring 2013 Homework Assignment 2 Third Draft Inter-Process Communications and Synchronization

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

Announcements. Lecture 05a Header Classes. Midterm Format. Midterm Questions. More Midterm Stuff 9/19/17. Memory Management Strategy #0 (Review)

Final CSE 131B Spring 2004

Arrays and Pointers (part 2) Be extra careful with pointers!

Dynamic Memory Allocation and Command-line Arguments

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

Chapter 11 Introduction to Programming in C

CSE 374 Programming Concepts & Tools

CSE 361S Intro to Systems Software Lab #4

Declaration Syntax. Declarations. Declarators. Declaration Specifiers. Declaration Examples. Declaration Examples. Declarators include:

CIS 190: C/C++ Programming. Lecture 2 Pointers and More

PRINCIPLES OF OPERATING SYSTEMS

CS241 Computer Organization Spring Data Alignment

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz

Agenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture

COMP s1 Lecture 1

CSE 303 Midterm Exam

A tale of ELFs and DWARFs

printf( Please enter another number: ); scanf( %d, &num2);

Laboratory 1 Semester 1 11/12

CSE Theory of Computing Fall 2017 Project 3: K-tape Turing Machine

CSE 333 Midterm Exam July 24, Name UW ID#

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

CS3157: Advanced Programming. Outline

CS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016

CS 385 Operating Systems Fall 2013 Homework Assignment 2 Inter-Process Communications and Synchronization

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14

CS 211 Programming Practicum Fall 2018

just a ((somewhat) safer) dialect.

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

CSE 12 Spring 2018 Week One, Lecture Two

Absolute C++ Walter Savitch

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

Exercise Session 6 Computer Architecture and Systems Programming

CSE 351. GDB Introduction

Programming Tools. Venkatanatha Sarma Y. Lecture delivered by: Assistant Professor MSRSAS-Bangalore

C: Program Structure. Department of Computer Science College of Engineering Boise State University. September 11, /13

PROGRAMMAZIONE I A.A. 2017/2018

Problem Set 1: Unix Commands 1

QUIZ. Can you find 5 errors in this code?

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Transcription:

CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary Due: Thursday 14 Sept. Electronic copy due at 9:00 A.M., optional paper copy may be delivered to the TA during lab. Overall Assignment The point of this assignment is to examine how different types of variables are allocated and relocated in binary and executable files, by the gcc compiler / linker in C under UNIX. To do this two source code files will be created, containing a total of four functions, linked together into one executable program. Each file / function will include a variety of variables of different types and scopes, ( e.g. global/local, static/auto, basic/pointers/references/user-defined ), so that we can see how each of these are stored in each of the transition steps. Finally you are to answer some questions regarding your results, to demonstrate your ability to use the relevant tools. Required Files, Components, and Variables For this assignment you need to write two source code files in C, containing the following functions: file1<netid>.c, containing the functions: o int main( int argc, char **argv ); o double func1( <type1> func1_arg1, <type1> * func1_arg2 ); file2<netid>.c, containing o double func2( <type1> & func2_arg1, <type1> * func2_arg2 ); o static double func3( const <type1> & func3_arg1, <type1> * func3_arg2 ); Where <NetID> is replaced with your @uic.edu netid ( e.g. jbell ) and the <type1> terms are described below, ( as is the variable N ). Note the pass-by-reference in file2. Each of these files should contain the following global declarations, where <file> is replaced by the name of the file in which they are declared, (without the NetID, e.g. file1hello[ ], file2hello[ ] ). char <file>hello[] = "Hello", * <file>world = "World"; <type1> <file>global, <file>globalarray[n], * <file>globalptr, <file>initglobal = N, <file>initglobalarray[n] = {N}, * <file>initglobalptr = & <file>initglobal; static <type2> <file>staticglobal, <file>staticglobalarray[n], * <file>staticglobalptr, <file>staticinitglobal = N, <file>staticinitglobalarray[n] = {N}, * <file>staticinitglobalptr = & <file>staticinitglobal;

Each file should also contain extern references to the ( non-static ) global variables declared in the other file. In addition, each function should contain the following local declarations, where <func> is replaced by the name of the function in which they are declared, e.g. func1local, func2local, etc.: <type3> <func>local, <func>localarray[n], * <func>localptr, < func>initlocal = N, <func>initlocalarray[n] = {N}, * <func>initlocalptr = & <func>initlocal; static <type4> <func>staticlocal, <func>staticlocalarray[n], * <func>staticlocalptr, <func>staticinitlocal = N, <func>staticinitlocalarray[n] = {N}, * <func>staticinitlocalptr = & <func>staticinitlocal; Data Types and Numerical Values N should be 10 plus the last non-zero digit of your UIN number. <type1> to <type4> are based on the first 4 characters of your ACCC ID ( e.g. jbell ) as follows: Letter A to F, or blank G to M N to S T to Z, digits Data type char int float double Program Functionality and Other Details For this assignment we don t really care what the programs does, but it must do something with all of the declared variables, in order to prevent the optimizing compiler from eliminating them. So the simplest task is to simply add them all up and report the total. The overall task of each function ( including main ) is to add up the total of all of numeric variables to which it has access, including all local variables, function parameters, and whatever global variables it can see from either of the two files. ( Not including argc, argv. ) All functions ( including main ) should print the values of Hello and World followed by "from <func>" as a first step. Any variables that are not initialized should be assigned a value of N before their first use. In the case of arrays, fill the uninitialized arrays with all Ns, ( but initialize only the first value of the arrays to be initialized, as shown above. ) For uninitialized pointers, make them point to any variable of the correct type. Main prints the total that it calculates, and all other functions both print and return their totals. Main includes the results of calling func1 and func2 in its total, and func2 adds in the result of calling func3. Pass <file>global and the address of <file>global when calling the functions. In the case of pointer variables, make sure to add up the thing pointed to by the pointers, not the values of the pointers themselves.

Compilation Analysis This assignment will require use of a makefile. The TA should be able to just type make to produce files <file>.i, <file>.s, and <file.o> containing pre-processed, compiled, and assembled versions of <file>.c respectively, and then a final executable program named main. Use the -E, -S, and -c flags to gcc, and also include -g to retain the maximum amount of information in the files. Once you have the programs compiled and running, you will need to examine them using readelf and objdump. Specific questions to be answered will be provided. Required Output and Expected Results Other Details: What to Hand In: All programs should print your name and ACCC user name as a minimum when they first start. Beyond that, each of the four functions should print out their Hello and World variables along with the total that they calculated. The expected output values are: o func1 and func3 should report N ( 5N + 27 ) o func2 should report 2 N ( 5N + 27 ) = N ( 10N + 54 ) o main should report 4 N ( 5N + 27 ) 2 N = N ( 20 N + 106 ) o You should verify these expectations by evaluating your code, to see how many variables each function can see. ( Note that initialized arrays contain only one non-zero value, uninitialized arrays contain N non-zeros, and that main does not add in argc or argv. ) Your program will be evaluated on systems.cs.uic.edu. 1. Your code, including a makefile and a readme file, should be handed in electronically using Blackboard. For this assignment, include also the completed questionnaire ( see separate file ) and text files with.txt extensions containing the output you used to answer the questions. 2. The purpose of the readme file is to make it as easy as possible for the grader to understand your program. If the readme file is too terse, then (s)he can't understand your code; If it is overly verbose, then it is extra work to read the readme file. It is up to you to provide the most effective level of documentation. 3. The readme file must specifically provide direction on how to run the program, i.e. what command line arguments are required and whether or not input needs to be redirected. It must also specifically document any optional information or command line arguments your program takes, as well as any differences between the printed and electronic version of your program. 4. If there are problems that you know your program cannot handle, it is best to document them in the readme file, rather than have the TA wonder what is wrong with your program. 5. A printed copy of your program, along with any supporting documents you wish to provide, ( such as hand-drawn sketches or diagrams ) may be handed in to the TA on or shortly after the date specified above. Any hard copy must match the electronic submission exactly. 6. Make sure that your name and your ACCC account name appear at the beginning of each of your files. Your program should also print this information when it runs.

Man Pages The following man pages may be helpful for this assignment: readelf objdump make gcc Optional Enhancements: It is course policy that students may go above and beyond what is called for in the base assignment if they wish. These optional enhancements will not raise any student s score above 100 for any given assignment, but they may make up for points lost due to other reasons. Note that all optional enhancements need to be clearly documented in your readme files. The following are some ideas, or you may come up with some of your own: Explore other data storage and function parameter types, such as const and very local variables. Extend the assignment to object-oriented C++ using classes. This enhancement should involve separate files from those described above, suitably named, resulting in an executable file maincpp when the TA types make. Explore inheritance, including both overloading and overriding of methods. Explore public versus private versus protected. Explore static versus non-static class data and methods. Other ideas that you come up with Check with TA for acceptability.

CS 361 HW1 Questionnaire ( An MS Word format version of this will be provided online, editable and with more space. ) Please answer the following questions, and fill out the table shown below: 1. What is your name, ACCC ID, and the last non-zero digit of your UIN? 2. What were your data types for <type1>, <type2>, <type3>, <type4>? Type of file Entry point address Start of section headers Section numbers for.text,.data,.bss Size ( decimal ) for.text,.data,.bss Total sizes of items in.text,.data,.bss Section number, size, and offset for each of the items listed below. file1<netid>.o file2<netid>.o main Use C, U, A for COMMON, UNDEFINED, AND ABSOLUTE, or NA if Not Applicable file1global file2staticglobal file1initglobal file2initstaticglobal mainlocal func1initlocal func2staticlocalptr func3staticlocalarray mainhello func1world func1_arg1 func2_arg1 func3_arg1 main func1 func2 func3 printf start end data_start bss_start 3. What do you think about readelf versus objdump? Which do you prefer, and why? 4. Which readelf flags did you find most useful? Which objdump flags?