Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

linking

Total questions: 96

Worksheet time: 48mins

Name
Class
Date
1.

What is the first stage in the compilation process?

a)

Compiler

b)

Preprocessor

c)

Assembler

d)

Linker

2.

Refer to the diagram of the Compilation Process. Which stage produces assembly code?

a)

Preprocessor

b)

Compiler

c)

Assembler

d)

Linker

3.

Refer to the diagram of the Compilation Process. Fill in the blank: The ________ combines object code and libraries to produce executable code.

a)

Linker

b)

Compiler

c)

Assembler

d)

Preprocessor

4.

Refer to the diagram of the Compilation Process. True or False: The Assembler produces object code.

a)

True

b)

False

5.

What is the final output of the compilation process?

a)

Executable code

b)

Source code

c)

Object code

d)

Assembly code

6.

Given the following C code from main.c and sum.c: main.c: int sum(int *a, int n); int array[2] = {1, 2}; int main() { int val = sum(array, 2); return val; } sum.c: int sum(int *a, int n) { int i, s = 0; for (i = 0; i < n; i++) { s += a[i]; } return s; } What is the value returned by the main function?

a)

3

b)

1

c)

2

d)

0

7.

Given the following C code from main.c and sum.c: main.c: int sum(int *a, int n); int array[2] = {1, 2}; int main() { int val = sum(array, 2); return val; } sum.c: int sum(int *a, int n) { int i, s = 0; for (i = 0; i < n; i++) { s += a[i]; } return s; } What does the function sum do?

a)

Multiplies all elements of the array

b)

Sums all elements of the array

c)

Returns the first element of the array

d)

Returns the last element of the array

8.

The purpose of the for loop in the sum function is:

a)

to iterate through each element and add them to the total sum

b)

to multiply all elements together

c)

to print each element in the list

d)

to reverse the order of elements

9.

What is the command used to compile and link the source files main.c and sum.c into an executable named prog?

a)

gcc -Og -o prog main.c sum.c

b)

gcc -o main.c sum.c prog

c)

gcc -Og -o sum.c main.c prog

d)

gcc -Og -o main.c prog sum.c

10.

Fill in the blank: The files main.c and sum.c are called ______ files in the static linking process.

a)

source

b)

object

c)

header

d)

library

11.

The linker (ld) combines separately compiled object files into a fully linked executable object file.

a)

True

b)

False

12.

Which files contain code and data for all functions defined in main.c and sum.c after linking?

a)

main.o

b)

sum.o

c)

prog

d)

main.c

13.

Why is modularity important when using linkers?

a)

It allows programs to be written as a collection of smaller source files

b)

It makes programs monolithic

c)

It prevents building libraries

d)

It increases code duplication

14.

Fill in the blank: Linkers allow you to build libraries of common functions, such as the ________ library and the standard C library.

a)

Math

b)

Graphics

c)

Network

d)

Audio

15.

Why is separate compilation considered efficient in the context of linkers?

a)

A) It allows changing one source file, compiling, and then relinking without recompiling other source files.

b)

B) It requires recompiling all source files every time.

c)

C) It does not support relinking.

d)

D) It increases compilation time.

16.

Fill in the blank: In the context of linkers, common functions can be aggregated into a single file called _________.

a)

libraries

b)

headers

c)

objects

d)

modules

17.

Executable files and running memory images contain only code for the functions they actually use.

a)

True

b)

False

18.

What is the first step that linkers perform?

a)

Symbol resolution

b)

Code optimization

c)

Memory allocation

d)

Error checking

19.

Programs define and reference ______ (global variables and functions).

a)

symbols

b)

numbers

c)

arrays

d)

pointers

20.

Where are symbol definitions stored in an object file?

a)

In the code section

b)

In the symbol table

c)

In the data segment

d)

In the stack

21.

The symbol table is an array of structs, and each entry includes the name, size, and location of the symbol.

a)

True

b)

False

22.

During the symbol resolution step, the linker associates each symbol reference with exactly one ______.

a)

symbol definition

b)

object file

c)

memory address

d)

function call

23.

What do linkers do in Step 2: Relocation? Fill in the blank: Linkers merge separate code and data sections into ______ sections.

a)

single

b)

multiple

c)

temporary

d)

external

24.

What do linkers do in Step 2: Relocation? Fill in the blank: Linkers relocate symbols from their relative locations in the .o files to their final ______ memory locations in the executable.

a)

absolute

b)

virtual

c)

temporary

d)

dynamic

25.

What do linkers do in Step 2: Relocation? Fill in the blank: Linkers update all references to these symbols to reflect their new ______.

a)

positions

b)

colors

c)

owners

d)

values

26.

Which kind of object file contains code and data in a form that can be combined with other relocatable object files to form executable object file?

a)

Relocatable object file (.o file)

b)

Executable object file (a.out file)

c)

Shared object file (.so file)

27.

Which kind of object file contains code and data in a form that can be copied directly into memory and then executed?

a)

Relocatable object file (.o file)

b)

Executable object file (a.out file)

c)

Shared object file (.so file)

28.

Fill in the blank: The shared object file (.so file) is a special type of relocatable object file that can be loaded into memory and linked dynamically, at either load time or run-time. It is called ________ by Windows.

a)

Dynamic Link Libraries (DLLs)

b)

Executable and Linkable Format (ELF)

c)

Static Object Files (SOF)

d)

Portable Executable (PE)

29.

What is the standard binary format for object files?

a)

A) ELF

b)

B) PDF

c)

C) JPEG

d)

D) TXT

30.

Which of the following is NOT a type of object file unified under ELF?

a)

Relocatable object files (.o)

b)

Executable object files (a.out)

c)

Shared object files (.so)

d)

Text object files (.txt)

31.

Fill in the blank: The generic name for the format described is ________ binaries.

a)

ELF

b)

PE

c)

Mach-O

d)

COFF

32.

Which of the following is a type of object file supported by ELF?

a)

Relocatable object files (.o)

b)

Executable object files (a.out)

c)

Shared object files (.so)

d)

All of the above

33.

What does the ELF header contain?

a)

Code

b)

Word size, byte ordering, file type, machine type

c)

Initialized global variables

d)

Uninitialized global variables

34.

Which section contains code in an ELF object file?

a)

.data section

b)

.bss section

c)

.text section

d)

.rodata section

35.

The .rodata section contains _________.

a)

Read only data: jump tables, ...

b)

Executable code: main functions, ...

c)

Stack data: local variables, ...

d)

Heap data: dynamically allocated memory, ...

36.

Which section is used for initialized global variables?

a)

.bss section

b)

.data section

c)

.text section

d)

.rodata section

37.

The .bss section contains uninitialized global variables.

a)

True

b)

False

38.

What does 'bss' stand for in the ELF object file format?

a)

Block Started by Symbol

b)

Binary Section Segment

c)

Base Symbol Section

d)

Buffer Storage Segment

39.

Which section has a header but occupies no space in the ELF object file format?

a)

.bss section

b)

.text section

c)

.data section

d)

.rodata section

40.

Which section in the ELF Object File Format contains the symbol table, procedure and static variable names, and section names and locations?

a)

.symtab section

b)

.rel.text section

c)

.data section

d)

.debug section

41.

What is the purpose of the .rel.text section in the ELF Object File Format?

a)

Contains symbol table

b)

Relocation info for .text section

c)

Info for symbolic debugging

d)

Offsets and sizes of each section

42.

The .rel.data section provides relocation info for which section?

a)

.text section

b)

.data section

c)

.debug section

d)

.symtab section

43.

Which section in the ELF Object File Format provides info for symbolic debugging?

a)

.debug section

b)

.text section

c)

.data section

d)

.bss section

44.

The Section header table in the ELF Object File Format provides ______ and sizes of each section.

a)

offsets

b)

names

c)

addresses

d)

permissions

45.

The .rel.text section contains addresses of instructions that need to be modified in the executable.

a)

True

b)

False

46.

Which section header table is required for executables in the ELF Object File Format?

a)

Segment header table

b)

Symbol table

c)

String table

d)

Relocation table

47.

What are global symbols in the context of linker symbols?

a)

Symbols defined by module m that can be referenced by other modules.

b)

Symbols defined and referenced exclusively by module m.

c)

Global symbols that are referenced by module m but defined by some other module.

d)

Local program variables.

48.

Fill in the blank: External symbols are ______ that are referenced by module m but defined by some other module.

a)

Global symbols

b)

Local symbols

c)

Static symbols

d)

Private symbols

49.

Local linker symbols are local program variables.

a)

True

b)

False

50.

Which attribute is used to define local symbols in C functions and global variables? Choose the correct option.

a)

static

b)

global

c)

external

d)

public

51.

In the file main.c, which variable is defined as a global variable?

a)

val

b)

array

c)

sum

d)

main

52.

In the file sum.c, which variable is returned by the function sum?

a)

i

b)

s

c)

a

d)

n

53.

Refer to the code snippets and annotations in the image titled 'Step 1: Symbol Resolution'. The linker knows nothing of ______ in main.c.

a)

val

b)

func

c)

main

d)

int

54.

Refer to the code snippets and annotations in the image titled 'Step 1: Symbol Resolution'. The variable 'array' is referenced as a global in main.c.

a)

True

b)

False

55.

Local non-static C variables vs. local static C variables: Which of the following statements is true?

a)

Local non-static C variables are stored in .bss

b)

Local static C variables are stored on the stack

c)

Local non-static C variables are stored on the stack

d)

Local static C variables are stored in either .bss or .data

56.

Local static C variables are stored in either ______ or ______.

a)

.bss, .data

b)

.text, .heap

c)

.stack, .heap

d)

.rodata, .stack

57.

Local non-static C variables vs. local static C variables: Consider the following code: int f() { static int x = 0; return x; } int g() { static int x = 1; return x; } Where does the compiler allocate space for each definition of x?

a)

.stack

b)

.bss or .data

c)

.heap

d)

.text

58.

Local non-static C variables vs. local static C variables: The compiler creates local symbols in the symbol table with unique names for each static local variable definition.

a)

True

b)

False

59.

Program symbols are either strong or weak. Which of the following describes a strong symbol?

a)

A) Procedures and initialized globals

b)

B) Uninitialized globals

c)

C) Local variables

d)

D) Constants

60.

Fill in the blank: Weak symbols are __________ globals.

a)

uninitialized

b)

constant

c)

volatile

d)

private

61.

In the code 'int foo=5;' in p1.c, is 'foo' a strong or weak symbol?

a)

Strong

b)

Weak

62.

Linker's Symbol Rules: According to Rule 1, what happens if multiple strong symbols are defined?

a)

Each item can be defined multiple times

b)

Each item can be defined only once

c)

Linker error

d)

Both B and C

63.

Linker's Symbol Rules: According to Rule 2, given a strong symbol and multiple weak symbols, which symbol is chosen?

a)

The weak symbol

b)

The strong symbol

c)

Both symbols

d)

None

64.

Linker's Symbol Rules: Fill in the blank for Rule 3: If there are multiple weak symbols, pick an ________ one. (Can override this with gcc -fno-common)

a)

arbitrary

b)

unique

c)

default

d)

strong

65.

Given the following code snippets: int x; p1() {} p1() {} What is the linker behavior?

a)

The linker reports a multiple definition error for p1().

b)

The linker ignores the duplicate function definitions.

c)

The linker merges both function definitions into one.

d)

The linker reports an undefined reference to p1().

66.

Given the following code snippets: int x; p1() {} int x; p2() {} What is the linker behavior?

a)

The linker will report a multiple definition error for 'x'.

b)

The linker will successfully link without errors.

c)

The linker will ignore the second definition of 'x'.

d)

The linker will merge both definitions of 'x'.

67.

The linker behavior is:

a)

Combining object files into a single executable

b)

Translating high-level code to machine code

c)

Debugging the source code

d)

Editing the source code

68.

The linker behavior is:

a)

Combining object files into a single executable

b)

Translating high-level code to machine code

c)

Debugging the source code

d)

Editing the source code

69.

Given the following code snippets: int x=7; p1() {} int x; p2() {} What is the linker behavior?

a)

The linker will report a multiple definition error for 'x'.

b)

The linker will successfully link the code without errors.

c)

The linker will ignore the second declaration of 'x'.

d)

The linker will treat both 'x' declarations as separate variables.

70.

Nightmare scenario: What happens when two identical weak structs are compiled by different compilers with different alignment rules?

a)

The structs may have different memory layouts, causing compatibility issues.

b)

The structs will always be compatible regardless of alignment rules.

c)

The compilers will automatically resolve alignment differences.

d)

The structs will be optimized for speed in both compilers.

71.

Should you avoid using global variables if you can?

a)

Yes

b)

No

72.

What keyword should you use if you can when defining a global variable?

a)

static

b)

extern

c)

global

73.

What should you do if you define a global variable? Fill in the blank.

a)

initialize

b)

delete

c)

ignore

d)

rename

74.

What keyword should you use if you reference an external global variable?

a)

static

b)

extern

c)

global

75.

What is the main purpose of the relocation step in the creation of an executable object file?

a)

To combine multiple object files into a single executable

b)

To compile source code into object files

c)

To debug the program

d)

To run the program

76.

In the context of object files, what does the '.text' section typically contain?

a)

System data

b)

Executable code

c)

Debug information

d)

Symbol table

77.

What is stored in the '.data' section of the main.o file?

a)

main()

b)

int array[2]={1,2}

c)

sum()

d)

swap()

78.

Refer to the diagram explaining 'Step 2: Relocation'. Fill in the blank: The sum.o file contains the function ______ in its .text section.

a)

sum()

b)

main()

c)

printf()

d)

multiply()

79.

Refer to the diagram explaining 'Step 2: Relocation'. Which of the following sections are present in the final executable object file?

a)

main()

b)

Headers

c)

swap()

d)

System code

e)

More system code

80.

Which struct in ELF contains the fields 'Elf32_Addr r_offset;' and 'Elf32_Word r_info;'?

a)

Elf32_Rel

b)

Elf32_Rela

c)

Elf64_Rel

d)

Elf64_Rela

81.

Fill in the blank: The struct Elf32_Rela contains the additional field ______ compared to Elf32_Rel.

a)

Elf32_Sword r_addend;

b)

Elf32_Word r_offset;

c)

Elf32_Word r_info;

d)

Elf32_Word r_type;

82.

Which data type is used for the 'r_info' field in the Elf64_Rel struct?

a)

Elf32_Word

b)

Elf64_Xword

c)

Elf32_Sword

d)

Elf64_Addr

83.

Fill in the blank: The struct Elf64_Rela contains the fields Elf64_Addr r_offset, Elf64_Xword r_info, and ______.

a)

Elf64_Sxword r_addend;

b)

Elf64_Word r_size;

c)

Elf64_Addr r_base;

d)

Elf64_Half r_type;

84.

Fill in the blank: The relocation algorithm handles two types of references: ________ and absolute references.

a)

PC-relative

b)

Stack-relative

c)

Base-relative

d)

Index-relative

85.

Which of the following is used to relocate an absolute reference?

a)

A) *refptr = (unsigned) (ADDR(r.symbol) + r.addend - refaddr);

b)

B) *refptr = (unsigned) (ADDR(r.symbol) + r.addend);

c)

C) *refptr = (unsigned) (ADDR(r.symbol) - r.addend);

d)

D) *refptr = (unsigned) (ADDR(r.symbol) + r.offset);

86.

Consider the following C code: int array[2] = {1, 2}; int main() { int val = sum(array, 2); return val; } Which function is called in the main function?

a)

add()

b)

sum()

c)

main()

d)

return()

87.

Refer to the assembly output below for the main function: 0000000000000000

: 0: 48 83 ec 08 sub $0x8,%rsp 4: be 02 00 00 00 mov $0x2,%esi 9: bf 00 00 00 00 mov $0x0,%edi # %edi = &array a: R_X86_64_32 array # Relocation entry e: e8 00 00 00 00 callq 13 # sum() f: R_X86_64_PC32 sum-0x4 # Relocation entry 13: 48 83 c4 08 add $0x8,%rsp 17: c3 retq What is the purpose of the relocation entry at address 'a'?

a)

A) To relocate the address of the 'sum' function

b)

B) To relocate the address of the 'array' variable

c)

C) To relocate the value of %esi

d)

D) To relocate the return value

88.

Fill in the blank: In the assembly output, the instruction 'callq 13 ' is used to call the function _______.

a)

sum()

b)

printf()

c)

scanf()

d)

main()

89.

Using PC-relative addressing for sum(): 0x4004e8 = 0x4004e3 + _____. Fill in the blank with the correct value.

a)

0x5

b)

0x3

c)

0xA

d)

0x7

90.

In the given assembly code, which instruction is used to call the sum() function?

a)

mov

b)

callq

c)

add

d)

jmp

91.

What is the hexadecimal address of the sum() function as shown in the relocated .text section?

a)

0x4004d0

b)

0x4004e3

c)

0x4004e8

d)

0x4004fd

92.

Which section of the Executable Object File contains the program's instructions?

a)

.data section

b)

.text section

c)

.bss section

d)

.symtab

93.

Fill in the blank: The ______ section in the Executable Object File contains uninitialized data.

a)

.bss section

b)

.data section

c)

.text section

d)

.init section

94.

Which segment in the memory layout is created by malloc at run-time?

a)

User stack

b)

Run-time heap

c)

Read-only code segment

d)

Memory-mapped region for shared libraries

95.

Fill in the blank: The ______ segment in the memory layout is loaded from the executable file and contains .data and .bss sections.

a)

Read/write data segment

b)

Stack segment

c)

Text segment

d)

Heap segment

96.

The .rodata section in the Executable Object File contains read-only data.

a)

True

b)

False