SampleFinalCS3214S10

- CS 3214 Sample Final Exam(Spring 2010 Sample Final Exam(Spring 2010 Solutions are shown in this style This exam was given Spring 2010 1 Linking

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 3214 Sample Final Exam (Spring 2010) 1/12 Sample Final Exam (Spring 2010) Solutions are shown in this style. This exam was given Spring 2010. 1. Linking and Loading (12 pts) The following questions are related to linking and loading in a C/Unix environment. a) (4 pts) A coding style rule that is used in many C-based projects is that variables that are used only within one compilation unit be declared static. Sketch briefly how you could create a script as part of the build process that would check if programmers followed this rule! Use nm or a similar tool and verify that for every defined global symbol (recognizable with a capital letter such as ‘T’, ‘C’, or ‘D’ in nm), there exists at least one undefined (‘U’) reference in another .o file. Some answers suggested a source code analysis approach by looking for ‘extern’ declarations. While possible, this is more difficult because simply declaring a variable or function extern does not produce an undefined reference unless the variable or function is actually used. A common mistake was to propose an algorithm that would check that static variables with the same name aren’t used outside the current compilation unit. This is wrong: static variables are local to a compilation unit, so using a static variable with the same name in different files is entirely ok (and occurs quite often). b) (4 pts) Consider the following two .c files: // inck.c extern int k; void inc_k() { k++; } // main.c extern void inc_k(); int main() { inc_k(); return 0; } What error message would the command gcc inck.c main.c -o main produce if one attempted to compile and link this program? $ gcc -Wall inck.c main.c -o main /tmp/cc4HL3gU.o: In function `inc_k': inck.c:(.text+0x4): undefined reference to `k' inck.c:(.text+0xc): undefined reference to `k'
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 3214 Sample Final Exam (Spring 2010) 2/12 collect2: ld returned 1 exit status The symbol ‘k’ is referenced in inck.o, but never defined. ‘extern’ declares, but does not define a symbol. c) (4 pts) Address space randomization is a defensive technique used to increase an attacker’s difficulty of succeeding with overflow attacks that require a priori knowledge of where a program’s data is located in its virtual address space. For instance, the location of the stack and the start of the heap are randomized on modern systems, so that they vary between different runs of a program. Could the location of global variables be similarly randomized? State your assumptions if necessary! No or yes, depending on your assumptions. Assuming the way executables are customarily built, the answer is no because the linker determines the location of all global variables at link time, then places the computed addresses directly into the executable. This could be avoided by building position-independent executables that use
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/31/2011 for the course CS 3214 taught by Professor Staff during the Fall '11 term at Virginia Tech.

Page1 / 12

- CS 3214 Sample Final Exam(Spring 2010 Sample Final Exam(Spring 2010 Solutions are shown in this style This exam was given Spring 2010 1 Linking

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online