Concept explainers
This problem concerns the m. o module from Figure 7.5 and the following version of the swap, c function that counts the number of times it has been called:
For each symbol that is defined and referenced in swap. o, indicate if it will have a symbol table entry in the symbol section in module swap. o. If so, indicate the module that defines the symbol (swap .o or m. o), the symbol type (local, global, or extern), and the section (.text, .data, or bss) it occupies in that module.
Sections in relocatable object files:
There are many sections in a relocatable object file. They are given below:
- “.text”:
- It is the machine code of the compiled program.
- “.rodata”:
- This section is used to read only the data in the format such as
- Strings in “printf” statements.
- Jump tables for switch statements.
- This section is used to read only the data in the format such as
- “.data”:
- This section is used in the initialized “C” variables of global variable and static “C” variables.
- Local “C” variables are initialized at execution time on the stack.
- It does not show in either the “.data” or “.bss” sections.
- “.bss”:
- It is used in the uninitialized global and static “C” variables, along with any global or static variables that are assigned to zero.
- “.symtab”:
- It is a symbol table.
- It contains the information about functions and global variables that are defined and referenced in the program.
- “.rel.text”:
- This section contains a list of locations in the “.text” section.
- It will require to be changed once the linker merges this object file with others.
- This section contains a list of locations in the “.text” section.
- “.rel.data”:
- This section contains relocation information for any global variables that are referenced or defined by the module.
- “.debug”:
- It is a symbol table for debugging
- It contains entries for following
- Definition of Local variables, global variables and typedefs variables and original “C” source file.
- “.line”:
- It is a mapping between line numbers in the given program
- That is in original “C” source program and machine code instructions in the “.text” section.
- It is a mapping between line numbers in the given program
- “.strtab”:
- It is a string table.
- It contains symbol tables in the “.symtab” and “.debug” sections.
- It is the table for section names in the section headers.
- It is a string table.
Explanation of Solution
For symbol “buf”:
- “.symtab” entry:
- It is occurs in the symbol table.
- Symbol type:
- It is an “extern” type. Because, the variable “buf” is declared in “extern” type which is present in “swap.c” file.
- Module defined position:
- The “buf” type is defined in “m.o” module.
- Because, the symbol “buf” are defined in “m.c” file”.
- When converting source file “m.c” to a relocatable object file, the given file becomes “m.o”.
- Section:
- The symbol “buf” is defined in “.data” section. It is the initialized global variable of “m.c” file.
For symbol “bufp0”:
- “.symtab” entry:
- It is occurs in the symbol table.
- Symbol type:
- It is a “global” symbol type. Because, the variable “bufp0” is declared outside the function in “swap.c” file.
- Module defined position:
- The “bufp0” type is defined in “swap.o” module.
- Because, the symbol “bufp0” are defined in “swap.c” file”.
- When converting source file “swap.c” to a relocatable object file, the given file becomes “swap.o”.
- Section:
- The symbol “bufp0” is defined in “.data” section. It is the initialized global variable of “swap.c” file
For symbol “bufp1”:
- “.symtab” entry:
- It is occurs in the symbol table.
- Symbol type:
- It is a “local” type. Because, the variable “bufp1” with “static” type in “swap.c” file.
- Module defined position:
- The “bufp1” type is defined in “swap.o” module.
- Because, the symbol “bufp1” are defined in “swap.c” file”.
- When converting source file “swap.c” to a relocatable object file, the given file becomes “swap.o”.
- Section:
- The symbol “bufp1” is defined in “.bss” section. It is the uninitialized static “C” variable of “swap.c” file
For symbol “swap”:
- “.symtab” entry:
- It is occurs in the symbol table.
- Symbol type:
- It is a “global” type. Because, the symbol “swap” is used in the entire program.
- Module defined position:
- The “swap” type is defined in “swap.o” module.
- Because, the symbol “swap” are defined in “swap.c” file”.
- When converting source file “swap.c” to a relocatable file, the given file becomes “swap.o”.
- Section:
- The symbol “swap” is present in “.text” section. It is the machine code of the compiled program.
For symbol “temp”:
- “.symtab” entry:
- The local variable “temp” does not a have a symbol table entry.
- So, it does not have a symbol type, module defined position and section.
- The local variable “temp” does not a have a symbol table entry.
For symbol “incr”:
- “.symtab” entry:
- It is occurs in the symbol table.
- Symbol type:
- It is a “local” type. Because, the function “incr” uses return type of “static” in “swap.c” file.
- Module defined position:
- The “swap” type is defined in “swap.o” module.
- Because, the symbol “swap” are defined in “swap.c” file”.
- When converting source file “swap.c” to a relocatable file, the given file becomes “swap.o”.
- Section:
- The symbol “swap” is present in “.text” section. It is the machine code of the compiled program.
For symbol “count”:
- “.symtab” entry:
- It is occurs in the symbol table.
- Symbol type:
- It is a “local” type. Because, the variable “count” declared in “static” type in the “swap.c” file.
- Module defined position:
- The “swap” type is defined in “swap.o” module.
- Because, the symbol “swap” are defined in “swap.c” file”.
- When converting source file “swap.c” to a relocatable file, the given file becomes “swap.o”.
- Section:
- The symbol “swap” is present in “.bss” section. Here, the static variables “count” are initialized to “0” in “swap.c” file.
The final table is
Symbol | .symtab entry? | Symbol type | Module where defined | Section |
buf | Yes | extern | m.o | .data |
bufp0 | Yes | global | swap.o | .data |
bufp1 | Yes | local | swap.o | .bss |
swap | Yes | global | swap.o | .text |
temp | No | - | - | - |
incr | Yes | local | swap.o | .text |
count | Yes | local | swap.o | .bss |
Want to see more full solutions like this?
Chapter 7 Solutions
EBK COMPUTER SYSTEMS
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Electric Circuits. (11th Edition)
Database Concepts (8th Edition)
Mechanics of Materials (10th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (8th Edition)
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY