Unformatted text preview:

CS 354 Machine Organization Programming Tuesday December 9 2025 NOTE TA consulting PM tutoring and instructor office hours end on Wednesday December 10 Finish your assignments early and take advantage of in person support while it is available Make sure to clarify any concepts and doubts while in person help is still available This Week email Complete the department s course evaluation survey using the link sent to you via Project P6 DUE by Wednesday Dec 10 NO late days or Oops point for this project Homework Quiz HW8 Due by Monday Dec 8 Available with 10 late penalty until Homework Quiz HW9 Due by Wednesday Dec 10 NO late days for this homework NO EXCEPTIONS Tuesday Dec 9 Learning Objectives Explain how a compiler resolves symbols across multiple source files Describe why relocation is necessary and how it occurs Describe the structure of an Executable Object File EOF Describe the role and functionality of a Loader This Week Tuesday Resolving Globals Symbol Relocation Executable object File EOF Loader Next Week Final Exam Wednesday December 17 12 25 PM 2 25 PM You should receive your final exam room information email by Friday December 12 If What s next Take CS 537 as soon as possible and or Compilers CS 536 if you are interested you do not receive this email let your instructor know ASAP Bring a copy of your exam room email printed or on the phone UW ID is required to take the exam Students without IDs will be the last to check in Write your Full Name on the Exam Booklet and Bubble Sheet exactly as given in Canvas 2 pencils are required to fill out the Bubble Sheet no pens or any other type of pencil Closed book exam No notes electronic devices reference sheet or any other help e g calculators phones watches etc is allowed See Exam 3 Notice on Canvas for topics and instructions Copyright 2016 2025 Jim Skrentny CS 354 F25 W15 L27 1 Resolving Globals Confusing Globals definition dete main c int m int n 11 short o def extern int x Declaration def int fun1 c int m 22 int n int o dref int x static int y 33 static int z 77 code continues edefin je deckritionn Linker evrot fun2 c int m extern int n char o static int x 33 def yes yesi yes somy lim teva 2 maprivarefthis static int y int z No No No code continues int y static int z 66 code continues What happens if multiple definitions of an identifier exist L inker error Use extern to clearly indicate when a global variable or function is only a declaration meant to be private Use static to clearly indicate when a global variable or function is TEXTBOOK and OLD NOTES describe old rules for resolving global variables Strong and Weak Symbols no such thing any more use extern when defined elsewhere strong function definitions and initialized global variables weak function declarations and uninitialized global variables Which code statements above correspond to strong symbols Rules for Resolving Globals Which code statements above correspond to definitions Recall extern is only a declaration Note extern vars must be defined in another file otherwise undefined symbol linker error 1 Multiple symbol defns in public global scope are not allowed linker error mult defined symbol Recall static makes a global private i e only visible within its source file 2 Define one symbol in one file and declare others with extern Can use gcc z muldefs to ignore uninitialized symbols defined in multiple files Copyright 2016 2025 Jim Skrentny CS 354 F25 W15 L27 2 Symbol Relocation What Symbol relocation combines ROFs into EOF so that addresses can be determined for linker symbols How 1 Merge the same sections of ROFs into one aggregate for each section type 2 Assign virtual addresses to each aggregate section and each symbol definition 3 Update symbol references listed in ROF relocation sections rel text rel data Example Consider the text and data sections of 3 object files below combined into an executable ROF EOF main o a out 1 O23 102 Main text 21020 text 1024 bytes 1 KB 1 KB Main dat a 4096 4095 si 2 KB 1 2 KB algo o 2byts is algo textWi USri text isn sy algo texot USVi data iitm usri o 1 2 KB 1 KB 1024 S 12 bs cn d256 address 1 start of section calc cnt 4096 2 offset to subsection 3 offset within subsection 120 15 1536 256 5882 Copyright 2016 2025 Jim Skrentny CS 354 F25 W15 L27 3 text data text data text data Executable Object File EOF What An EOF like an ROF is a file produced by the LINKER containing object code that can be loaded by LOADER into memory and run Executable and Linkable Format Same as ROF with additions used by loader ELF Header entry point address of 1st instruction Segment Header Table info for each segment to be loaded into memory during execution Padding requirements offset in file alignment page size size in file and size in mem run time permissions ELF Header Segment Header Table New Contains program initialization ue init text rodata data bss symtab debug line strtab Section Header Table Why aren t there relocation sections rel text or rel data in EOF Since we ve assumed static linking all symbol relocations are done Why is the data segment s size in memory larger than its size in the EOF bss is just a place holder in object files The loader must allocate the memory needed for bss symbols based on the symtab s description of each Copyright 2016 2025 Jim Skrentny CS 354 F25 W15 L27 4 Loader What The loader is kernel code that starts program execution can be invoked by any Linux program using the execve system call Loading 1 copies code and data segments from EOF into memory 2 starts program executing by jumping to its entry point Execution the final story 1 Shell creates a child process with fork 2 Child process invokes loader with execve 3 Loader creates the new runtime memory image a Deletes curr segments code data heap stack Linux Kernal b Creates new segments c Heap and stack initialized to size 0 d EOF s code and data segments are mapped in page table into page sized chunks based on Segment Hdr Table BUT THESE ARE NOT COPIED INTO MEM except some header info 4 Loader jumps to start address which causes a page fault start entry point Seiui call libc init first call init call atexit call main call exit text init text adds functions that clean up for exit our PROGRAM RUNS starting at entry point exit 0 Memory Mapped Stack Heap Data Segment Code Segment 0xFFFFFFFF 0xC0000000 0x08048000 0x00000000 esp brk Copyright 2016 2025 Jim Skrentny CS 354 F25 W15 L27 5 CS354 Project Reminders P1 Building and running an executable from C source


View Full Document

UW-Madison CS 354 - Outline

Loading Unlocking...
Login

Join to view Outline and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Outline and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?