lecture 9 Flashcards

Assemble, Link, and load

1
Q

given assembly program (pl.s), what will the assembler do?

A

assembler will create one relocatable object file
pl.s –> pl.o

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what format is the relocatable object file?

A

bytes are in Executable Linkable File (ELF) format

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what happens to each machine instruction in the assembly program when translated to ELF format?

A

each machine instruction generated by the assembler gets assigned to a specific ELF section with a temporary memory address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ELF sections

A

.text
.rodata
.data
.symtab
.reltext
.reldata

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what gets placed in the .text section?

A

machine instructions (ie your program)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what gets placed in the .rodata section?

A

read only data (ie constants)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what gets placed in the .data section?

A

initialized global and static variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what gets placed in the .symtab section?

A

symbol table
- holds the name and address
locations of functions and
global/static variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what gets placed in the .reltext section?

A

relocation info for .text section
- linker will relocate unresolved
instructions and addresses (later
step) –> linker must resolve these
to create an executable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what gets placed in the .reldata section?

A

relocation info for .data section
- linked will relocate unresolved
data and addresses (later step) –>
linker must resolve these to
create an executable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what are the 3 types of ELF binary object files?

A
  1. relocatable object file (only created by the assembler, .o)
  2. executable object file (a.out)
  3. shared object file (.so)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what counts as symbols in the .symtab?

A

name of function
global variable
static variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is included in a symbol table entry?

A

symbol name
section symbol (will go in either .text or .data)
32-bit address in memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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?

A

assembler identifies all symbols in the assembly program and updates .symtab

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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?

A

for those symbols –> they have unknown address locations within the program

*must be resolved by either assembler (second pass) or linker (next step)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what sections will the symbols be from in ELF?

A

.text or .data only

17
Q

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?

A

assembler then translates the assembly data to machine data
- updates the .data section with
each variable with an assigned
address within .data

18
Q

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?

A

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

19
Q

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?

A

yes

20
Q

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?

A

8 bytes in total

21
Q

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?

A

8 bytes in total

22
Q

steps of assembler translating file to machine language:

A
  1. recognizes all symbols in the program and adds them to .symtab (function names, globals, statics)
  2. goes to .data –> translates variables to machine language, and adds to .data section with address location
  3. goes to .text –> translates instructions to machine language, and adds to .text section with address location
  4. second pass –> goes back to .symtab and updates all the addresses of the found symbols within the program
  5. if any symbols that are variables are unknown –> assembler adds them to .reldata for linker to resolve
  6. if any symbols that are instructions are unknown –> assembler adds them to .reltext for linker to resolve
23
Q

what does the linker create?

A

executable object file

24
Q

whats an executable object file

A

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)

25
Q

what are the 2 roles of the linker?

A
  1. symbol resolution
  2. relocation
26
Q

what is symbol resolution?

A

for each symbol in symbol table that has unknown address (?) after both passes of assembler –> linker attempts to locate the same symbol (name and section type) in other symbol tables

*if not found –> linking step fails and error occurs

27
Q

what is relocation?

A

*after symbol resolution

relocates (copies) the .text and .data sections from one or more relocatable object files to the .text and .data sections in the executable object file

28
Q

relocation copies _______ FROM their ___________ ___________ TO their ____________ ____________.

A

data and instructions

relative address locations in the relocatable object file

final absolute address locations in the executable object file

29
Q

what does “fully linked” mean?

A

all data and instructions are copied to the executable object file with a memory address

30
Q

after resolution is done, do the instructions get new address in executable object file?

A

yes

31
Q

in order to run program:

A

loader –> copies sections in executable to main memory
operating system –> then starts executing the instructions that are in .text section first

32
Q

before loader can copy sections, what must happen first?

A

OS must assign/create memory:
- stack
- heap
- text
- data
*all sections in main memory that are specific to your program

33
Q

loader copies what into the read only section of main memory

A

all the instructions in the text section and all the read-only data in the read-only data section in the fully linked executable (each instruction and data is given address) into READ ONLY segment in RAM

34
Q

loader copies what into the read/write section of main memory

A

all the read/write data in .data section in executable into read/write segment in RAM