Level 1 — RecognitionBuild Systems & Toolchain

Build Systems & Toolchain

20 minutes30 marksprintable — key stays hidden on paper

Level: 1 (Recognition) Time limit: 20 minutes Total marks: 30


Section A — Multiple Choice (1 mark each) [10 marks]

Choose the single best answer.

Q1. Which compilation stage expands #include and #define directives?

  • A) Compilation
  • B) Preprocessing
  • C) Assembly
  • D) Linking

Q2. What does the linker primarily do?

  • A) Translate C to assembly
  • B) Expand macros
  • C) Resolve symbol references across object files and libraries
  • D) Convert assembly to machine code

Q3. A static library on Linux typically has the extension:

  • A) .so
  • B) .o
  • C) .a
  • D) .dll

Q4. The GCC flag that turns off all optimization (useful for debugging) is:

  • A) -O3
  • B) -Os
  • C) -O0
  • D) -Ofast

Q5. In a Makefile, the automatic variable $@ refers to:

  • A) The first prerequisite
  • B) All prerequisites
  • C) The target name
  • D) The recipe

Q6. Which sanitizer is designed to detect heap/stack buffer overflows and use-after-free at runtime?

  • A) UBSan
  • B) TSan
  • C) ASan
  • D) MSan

Q7. In CMake, the command that links a library to a target is:

  • A) add_library
  • B) add_executable
  • C) target_link_libraries
  • D) include_directories

Q8. "PIC," essential for shared libraries, stands for:

  • A) Program Instruction Counter
  • B) Position-Independent Code
  • C) Precompiled Include Cache
  • D) Pointer Indirection Code

Q9. Which tool disassembles an object file to show its assembly instructions?

  • A) gprof
  • B) objdump
  • C) ar
  • D) nm

Q10. The CMake build type that produces optimized code while retaining debug symbols is:

  • A) Debug
  • B) Release
  • C) RelWithDebInfo
  • D) MinSizeRel

Section B — Matching (1 mark each) [8 marks]

Match each tool/flag in Column X to its purpose in Column Y. Write pairs like Q11→(c).

Column X Column Y
Q11. -Wall (a) Detect data races between threads
Q12. gprof (b) Enable common compiler warnings
Q13. TSan (c) Sampling profiler / performance counters
Q14. ar (d) Function-level profiling via instrumentation
Q15. perf (e) Create/manage a static library archive
Q16. GDB watchpoint (f) Stop execution when a variable's value changes
Q17. UBSan (g) Detect signed overflow, misaligned access
Q18. sysroot (h) Root dir of target headers/libs in cross-compilation

Section C — True/False WITH Justification (2 marks each) [12 marks]

State True or False (1 mark) and give a one-line justification (1 mark).

Q19. In the linker command gcc main.o -lfoo -lbar, the order of -lfoo and -lbar never affects whether the build succeeds.

Q20. A .PHONY target in a Makefile is always executed even if a file of the same name exists.

Q21. An object file's symbol table can contain undefined (external) symbols that must be resolved at link time.

Q22. Address Sanitizer detects buffer overflows purely by static analysis at compile time, without running the program.

Q23. In a Makefile pattern rule %.o: %.c, the % matches the same stem in both target and prerequisite.

Q24. Compiling with -O3 guarantees the program will always run faster than with -O0, in every case.

Answer keyMark scheme & solutions

Section A (1 mark each)

Q1 — B. Preprocessing handles #include, #define, #if before compilation proper.

Q2 — C. The linker resolves symbols and combines objects/libraries into an executable; translation is done earlier.

Q3 — C. .a is the Unix static archive; .so/.dll are dynamic, .o a single object.

Q4 — C. -O0 disables optimization for predictable debugging.

Q5 — C. $@ = target; $< = first prerequisite; $^ = all prerequisites.

Q6 — C. ASan (AddressSanitizer) instruments memory to catch overflows/use-after-free at runtime.

Q7 — C. target_link_libraries(<target> <lib>) links libraries.

Q8 — B. Position-Independent Code allows loading a shared library at any address.

Q9 — B. objdump -d disassembles; nm lists symbols, ar archives, gprof profiles.

Q10 — C. RelWithDebInfo = optimizations (-O2) plus -g debug info.

Section B (1 mark each)

Q11→(b), Q12→(d), Q13→(a), Q14→(e), Q15→(c), Q16→(f), Q17→(g), Q18→(h)

Each correct pairing = 1 mark. No partial marks per item.

Section C (1 mark T/F + 1 mark justification)

Q19 — False. Traditional Unix linkers process left-to-right; a library must appear after the object that references its symbols, so order can determine success. (Order matters — subtopic 5.3.5.)

Q20 — True. .PHONY decouples the target name from any file, so the recipe runs unconditionally (no up-to-date check against a file).

Q21 — True. Undefined symbols (marked U by nm) are external references the linker resolves from other objects/libraries.

Q22 — False. ASan is a runtime instrumentation tool; it detects errors only along paths actually executed, not statically.

Q23 — True. In pattern rules % is the stem, and the same stem substitutes into target and prerequisite (e.g., foo.o from foo.c).

Q24 — False. -O3 is usually faster but not guaranteed; aggressive inlining/unrolling can hurt cache behavior or expose miscompilations, so it can be slower in some cases.

[
  {"claim":"Section A has 10 single-mark MCQs summing to 10","code":"section_a = 10*1\nresult = (section_a == 10)"},
  {"claim":"Section B has 8 matching items at 1 mark each = 8","code":"section_b = 8*1\nresult = (section_b == 8)"},
  {"claim":"Section C has 6 T/F items at 2 marks each = 12","code":"section_c = 6*2\nresult = (section_c == 12)"},
  {"claim":"Total marks equal 30","code":"total = 10 + 8 + 6*2\nresult = (total == 30)"}
]