C++ Compiling and Linking Flashcards

(45 cards)

1
Q

What are the 5 stages of program lifetime?

A

Code writing, compilation, linking, loading, execution

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

What is a translation unit?

A

Source code giving rise to an object file.

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

What is the output of compilation?

A

Object file.

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

What is the compilation?

A

Process of translating the code from a higher level language to a lower level language like assembly.

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

What is the decompilation?

A

Process of translating the code from a lower level language like assembly to a higher level langauge.

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

What are the compilation stages?

A

Pre-processing, linguistic analysis, assembly, optimization, code emission.

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

What does pre-processing do ?

A

Replaces all macros with appropriate constants, conditionally includes/excludes parts of code, includes files based on include directives.

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

What gcc flag can be used to get only the preprocesing output?

A

The flag is -E:

gcc -E input.c -o output.i

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

What gcc flags can be used to get a more readable preprocessed output?

A

The flags are: -E and -P:

gcc -E -P input.c -o output.i

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

What do lines starting with # in preprocessed output denote?

A

They usually mark the lines and file to which the code that follows belong to. Example:

25 hello.c

This denotes that the code which follows belongs to file hello.c starting from line 25.

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

What does -E flag do to preprocessor?

A

It removes the suplementary information in the preprocessed output like line numbers and similar.

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

What is lexical analysis?

A

Lexical analysis is a stage in linguistic analysis which splits the source into tokens.

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

What is parsing/syntax analysis?

A

It is a stage in linguistic analysis in which the order of tokens is checked against language rules and specifications.

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

What is linguistic analysis?

A

Linguistic analysis is a stage in which source is checked against language defined rules like syntax, semantics etc.

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

What is semantic analysis?

A

It is a stage in linguistic analysis in which the source statements and are checked for validity, like two objects being concatenated via operator + or similar.

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

What is assembling?

A

Compilation stage in which the source is translated to assembly language.

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

What are the two known assembly instruction printing formats?

A

AT&T and Intel.

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

What is different between AT&T and Intel assembly format?

A

One significant difference is that AT&T format uses the (operation, source, destination) order and Intel format uses the (operation, destination, source) order.

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

What is the purpose of the optimization stage?

A

To remove unused code, inline operations where possible, remove unnecessary computations and similar.

20
Q

What is the purpose of the code emission stage?

A

To create object files from assembly.

21
Q

What flag can be used to generate the assembly output?

A

The -S flag,

gcc -S -masm=att input.c -o input.s

22
Q

What flag can be used to generate the object files without linking?

23
Q

What flag can be used to get the dissasembled output of objdump ?

24
Q

What is objdump?

A

Utility program to check object files.

25
What do object files consist of?
Symbols and sections
26
What do symbols represent in object files?
References to memory addresses or data memory.
27
What is contained in .txt section in obj files?
Code
28
What is contained in .data section of obj files?
Initialized data.
29
What is contained in .bss section of obj files?
Uninitialized data.
30
Why is C/C++ building implemented as a two step procedure?
Because of code reuse and flexibility with libraries inclusion.
31
What is the main task of the linker?
To resolve all the references and create a final memory map section out of all the object files included.
32
What are the two stages of linking?
Relocation and reference resolving.
33
What is relocation in linking step?
Process in which sections from different individual obj files are combined together.
34
What is reference resolving in linking step?
Process in which memory addresses are found for the externally dependent variables and functions.
35
What is the most significant difference between the executable and the dynamic library?
Dynamic library does not include the startup routine section (crt0 or crt1) in its memory map.
36
What is the role of the shell in program execution stages?
Shell is usually used to launch the program.
37
What is the first action a shell does upon program launch?
It clones itself by calling fork().
38
Why does the shell create a copy of itself when launching a program?
To pass all the environment variables to the child process.
39
What is the role of the kernel in program launch?
It invokes one of the exec() functions which is supposed to determine the executable format and start the preparation of the process memory map.
40
What does loader do?
Loader copies the sections created by the linker into the memory map.
41
How does loader group the sections provided by the linker?
Into segments by their loading requirements. Whether the attributes are read-only, read-write, write etc.
42
What utility can be used to check the segments defined by the loader?
readelf --segments
43
What is the role of the _start() function?
To prepare arguments for the __libc_start_main function which loader calls in the final stage of loading the program.
44
What is the role of the __libc_start_main() function?
It initializes things needed before the main function starts, it registers cleanup handlers, it starts the main thread and executes the main function.
45
Where is the information about the memory address from which the program execution will start (_start() function) usually stored?
In ELF header's e_entry field.