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.

A

True

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.

A

False

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”);
}

A

BSS

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”);
}

A

Text

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”);
}

A

Stack

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”);
}

A

Heap

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
Q

What does the “core file” contain?

A

The core file contains the value of the variables global and local at the time of the SEGV.

26
Q

What file can be used for “post mortem” debugging?

A

The core file.

27
Q

What is a program?

A

a file in a special format that contains
all the necessary information to load an application into memory and make it run

28
Q

What does a program file include?

A

● 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
Q

True or false, there are different executable file formats?

A

True

30
Q

What is ELF – Executable Link File used in?

A

It is an executable file format used in most UNIX systems (Solaris, Linux).

31
Q

What is COFF – Common Object File Format used in?

A

It is used in Windows systems

32
Q

What is a.out used in?

A

Used in BSD (Berkeley Standard Distribution) and early UNIX
It was very restrictive. It is not used anymore.

33
Q

What are the steps to building a program? (extensive maybe split up flashcard)

A

● 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
Q

What line generates a hello executable?

A

“gcc –o hello hello.c”

35
Q

What are the steps to loading a program? (extensive maybe split up flashcard)

A

● 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
Q

What is the difference between static and shared libraries?

A

●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
Q

Do Static or Dynamic events happen during program building?

A

Static – Events that happen during
program building.

Example: Static linker,

Static type checking.

38
Q

Do Static or Dynamic events happen while the program is running?

A

Dynamic – Events that happen while
program is running.

Also called “Runtime”.
Example: Dynamic linker or
Runtime linker,
Dynamic Type checking