Data and Program Representation Flashcards

1
Q

How is memory seen by the program?

A

As an array of bytes.

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

What is the address range of memory in bytes?

A

0 - (2^64 - 1). * this is for 64 bit architecture

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

Is all of the address space of memory used?

A

No

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

What are the sections in memory called?

A

memory mappings

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

What are the memory mappings, in order form lowest to highest in address range.

A

Text, RoData, Data, BSS, Heap - Shared libs - Stack

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

What does the text memory section hold?

A

Instructions that the program runs

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

What does the data memory section hold?

A

Initialized global variables.

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

What does the Bss memory section hold?

A

Uninitialized global variables. They are
initialized to zeroes.

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

What does the Heap memory section hold?

A

Memory returned when calling malloc/new. It grows upwards.

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

What does the Stack memory section hold?

A

It stores local variables and return
addresses. It grows downwards.

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

What does the RoData memory section hold?

A

Read Only Data. String constants

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

Which way does the Stack grow?

A

The stack grows downwards.

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

Which was does the heap grow?

A

The heap grows upwards

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

What are Dynamic Libraries?

A

They are libraries shared with other processes.

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

What does each dynamic library have its own of?

A

text, data, and bss.

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

True or False, Each program (process) has its own view of the memory that is independent of each other.

17
Q

True or False, If a process modifies a byte in its own address space, it will modify the address space of another process.

18
Q

Below, where is line x stored?

Program hello.c
int a = 5; // Line x
int b[20];
int main() {
int x;
int p;
p =(int
) malloc(sizeof(int));
*p = 5;
printf(“Hello cs250\n”);
}

A

data section

19
Q

Below, where is line x stored?

Program hello.c
int a = 5;
int b[20]; // Line x
int main() {
int x;
int p;
p =(int
) malloc(sizeof(int));
*p = 5;
printf(“Hello cs250\n”);
}

20
Q

Below, where is line x stored?

Program hello.c
int a = 5;
int b[20];
int main() { // Line x
int x;
int p;
p =(int
) malloc(sizeof(int));
*p = 5;
printf(“Hello cs250\n”);
}

21
Q

Below, where is line x stored?

Program hello.c
int a = 5;
int b[20];
int main() {
int x; //Line x
int p;
p =(int
) malloc(sizeof(int));
*p = 5;
printf(“Hello cs250\n”);
}

22
Q

Below, where is line x stored?

Program hello.c
int a = 5;
int b[20];
int main() {
int x;
int p;
p =(int
) malloc(sizeof(int)); //Line x
*p = 5;
printf(“Hello cs250\n”);
}

23
Q

What is a memory gap?

A

A space between memory sections where there is no memory mapping

24
Q

What happens if a program tries to access a memory gap?

A

The OS will send a SEGV signal that by default kills the program and dumps a core file.

25
What does the "core file" contain?
The core file contains the value of the variables global and local at the time of the SEGV.
26
What file can be used for "post mortem" debugging?
The core file.
27
What is a program?
a file in a special format that contains all the necessary information to load an application into memory and make it run
28
What does a program file include?
● machine instructions ● initialized data ● List of library dependencies ● List of memory sections that the program will use ● List of undefined values in the executable that will be known when the program is loaded into memory.
29
True or false, there are different executable file formats?
True
30
What is ELF – Executable Link File used in?
It is an executable file format used in most UNIX systems (Solaris, Linux).
31
What is COFF – Common Object File Format used in?
It is used in Windows systems
32
What is a.out used in?
Used in BSD (Berkeley Standard Distribution) and early UNIX It was very restrictive. It is not used anymore.
33
What are the steps to building a program? (extensive maybe split up flashcard)
● The programmer writes a program hello.c ● The preprocessor expands #define, #include, #ifdef etc preprocessor statements and generates a hello.i file. ● The compiler compiles hello.i, optimizes it and generates an assembly instruction listing hello.s ● The assembler (as) assembles hello.s and generates an object file hello.o ● The compiler (cc or gcc) by default hides all these intermediate steps. You can use compiler options to run each step independently. Building a program ● The linker puts together all object files as well as the object files in static libraries. ● The linker also takes the definitions in shared libraries and verifies that the symbols (functions and variables) needed by the program are completely satisfied. ● If there is symbol that is not defined in either the executable or shared libraries, the linker will give an error. ● Static libraries (.a files) are added to the executable. shared libraries (.so files) are not added to the executable file.
34
What line generates a hello executable?
“gcc –o hello hello.c”
35
What are the steps to loading a program? (extensive maybe split up flashcard)
● The loader is a program that is used to run an executable file in a process. ● Before the program starts running, the loader allocates space for all the sections of the executable file (text, data, bss etc) ● It loads into memory the executable and shared libraries (if not loaded yet) Loading a Program ● It also writes (resolves) any values in the executable to point to the functions/variables in the shared libraries.(E.g. calls to printf in hello.c) ● Once memory image is ready, the loader jumps to the _start entry point that calls init() of all libraries and initializes static constructors. Then it calls main() and the program begins. ● _start also calls exit() when main() returns. ● The loader is also called “runtime linker” or “dynamic linker”.
36
What is the difference between static and shared libraries?
●Shared libraries are shared across different processes. ● There is only one instance of each shared library for the entire system. ● Static libraries are not shared. ● There is an instance of a static library for each process.
37
Do Static or Dynamic events happen during program building?
Static – Events that happen during program building. Example: Static linker, Static type checking.
38
Do Static or Dynamic events happen while the program is running?
Dynamic – Events that happen while program is running. Also called “Runtime”. Example: Dynamic linker or Runtime linker, Dynamic Type checking