lecture 9 Flashcards
Assemble, Link, and load
given assembly program (pl.s), what will the assembler do?
assembler will create one relocatable object file
pl.s –> pl.o
what format is the relocatable object file?
bytes are in Executable Linkable File (ELF) format
what happens to each machine instruction in the assembly program when translated to ELF format?
each machine instruction generated by the assembler gets assigned to a specific ELF section with a temporary memory address
ELF sections
.text
.rodata
.data
.symtab
.reltext
.reldata
what gets placed in the .text section?
machine instructions (ie your program)
what gets placed in the .rodata section?
read only data (ie constants)
what gets placed in the .data section?
initialized global and static variables
what gets placed in the .symtab section?
symbol table
- holds the name and address
locations of functions and
global/static variables
what gets placed in the .reltext section?
relocation info for .text section
- linker will relocate unresolved
instructions and addresses (later
step) –> linker must resolve these
to create an executable
what gets placed in the .reldata section?
relocation info for .data section
- linked will relocate unresolved
data and addresses (later step) –>
linker must resolve these to
create an executable
what are the 3 types of ELF binary object files?
- relocatable object file (only created by the assembler, .o)
- executable object file (a.out)
- shared object file (.so)
what counts as symbols in the .symtab?
name of function
global variable
static variable
what is included in a symbol table entry?
symbol name
section symbol (will go in either .text or .data)
32-bit address in memory
pl.o: * assembly lang (in c for example)
int sum (int *a, int n);
int array[2] = {1, 2};
int main() {
int val = sum(array, 2);
return val;
}
.symtab section:
.symtab (pl) symbol | section | address -------------------------------------------- main | .text | ? sum | .text | ? array | .data | ?
what does the assembler do first?
assembler identifies all symbols in the assembly program and updates .symtab
pl.o: * assembly lang (in c for example)
int sum (int *a, int n);
int array[2] = {1, 2};
int main() {
int val = sum(array, 2);
return val;
}
.symtab section:
.symtab (pl) symbol | section | address -------------------------------------------- main | .text | ? sum | .text | ? array | .data | ?
what does the ‘?’ mean under address?
for those symbols –> they have unknown address locations within the program
*must be resolved by either assembler (second pass) or linker (next step)
what sections will the symbols be from in ELF?
.text or .data only
pl.o: * assembly lang (in c for example)
int sum (int *a, int n);
int array[2] = {1, 2};
int main() {
int val = sum(array, 2);
return val;
}
.data section:
.data (pl) address| global variable (read/write) -------------------------------------------- 0 | array = {1, 2}
what does the assembler do second?
assembler then translates the assembly data to machine data
- updates the .data section with
each variable with an assigned
address within .data
pl.o: * assembly lang (in c for example)
int sum (int *a, int n);
int array[2] = {1, 2};
int main() {
int val = sum(array, 2);
return val;
}
.data section:
.data (pl) address| global variable (read/write) -------------------------------------------- 0 | array = {1, 2}
how much memory is allocated within the .data section for the array variable?
8 bytes
array holds 2 integer variables –> 1 int = 4 bytes
4 + 4 = 8 bytes in total
*array address starts at 0 and would go to 8
pl.o: * assembly lang (in c for example)
int sum (int *a, int n);
int array[2] = {1, 2};
int main() {
int val = sum(array, 2);
return val;
}
.data section:
.data (pl) address| global variable (read/write) -------------------------------------------- 0 | array = {1, 2}
are the total number of bytes for array fixed?
yes
pl.o: * assembly lang (in c for example)
int sum (int *a, int n);
int array[2] = {1, 2};
int main() {
int val = sum(array, 2);
return val;
}
.data section:
.data (pl) address| global variable (read/write) -------------------------------------------- 0 | array = {1, 2}
how many bytes is the .data section after the assembler updated it with the global variable, array?
8 bytes in total
pl.o: * assembly lang (in c for example)
int sum (int *a, int n);
int array[2] = {1, 2};
int main() {
int val = sum(array, 2);
return val;
}
.text section:
.text (pl) address| global variable (read/write) -------------------------------------------- 0 | array = {1, 2}
how many bytes is the .data section after the assembler updated it with the global variable, array?
8 bytes in total
steps of assembler translating file to machine language:
- recognizes all symbols in the program and adds them to .symtab (function names, globals, statics)
- goes to .data –> translates variables to machine language, and adds to .data section with address location
- goes to .text –> translates instructions to machine language, and adds to .text section with address location
- second pass –> goes back to .symtab and updates all the addresses of the found symbols within the program
- if any symbols that are variables are unknown –> assembler adds them to .reldata for linker to resolve
- if any symbols that are instructions are unknown –> assembler adds them to .reltext for linker to resolve
what does the linker create?
executable object file
whats an executable object file
object file that combines relocatable object files and shared object files (libraries)
*includes all data and instructions that can be copied into memory and ran (executed)