layout
layout
Process Anatomy
Ethan Blanton
Department of Computer Science and Engineering
University at Buffalo
Introduction Executable Format Memory Layout Summary Coming Up References
Last Time
Processes
What is a process?
From the text:
Programs
UNIX Processes
This Lecture
Executable Formats
Each executable is stored in an executable format.
An executable format provides:
Information about the environment the program requires
The program code itself
Other metadata
ELF
Linking
Linking is the process of creating an executable or shared library
from multiple object files.
The linker in the C compiler toolchain performs this task.
It involves:
Cataloging symbols provided by various object files
Cataloging symbols provided by external libraries
Identifying symbols required by objects and libraries
Binding provided symbols to required symbols
Loading
Loading is the process of moving an executable or shared
library into memory for execution.
On Linux, the kernel begins loading, and ld-linux.so finishes it.
The kernel moves various portions of the ELF executable
into place
The kernel moves the loader into place
The kernel invokes the loader, which performs various
changes to the in-memory program data
The loader jumps to the start of the program
ELF Structure
ELF Sections
Each part of a process is represented in some section.
There are many possible sections, but we will consider:
Text1 : The actual program code, as executed by the
processor. ELF calls this .text.
Data: Non-code data that has some value defined at
compile time; for example: strings, constants, some global
variables, etc. ELF calls this .data.
BSS: The “block started by segment”. This is non-code data
that has no value defined at compile time. For example,
declared global variables with no initializer. ELF calls this
.bss.
1
Text, data, and BSS are all historical names.
© 2018 Ethan Blanton / CSE 410: Systems Programming
Introduction Executable Format Memory Layout Summary Coming Up References
Basic Layout
0xffffffffffffffff Kernel
Layout Caveats
The Stack
Base of Stack System Info
The stack grows downward as
functions are called and shrinks
when they return.
main argv
arguments
Each function called has a stack function
frame that contains: called by
main local variables
The arguments to the
function Top of Stack
Local variables (Stack Pointer)
Toward Heap
The Heap
Summary
A program is code that can be executed, a process is that
code running on a system.
The linker joins multiple objects into an executable.
A loader prepares a program that has been copied into
memory for execution.
Program code (text), initalized data (data), and uninitialized
data (bss) are present in both a program and a process.
The heap and stack can both grow, the former “upward”
toward higher addresses and the latter “downward” toward
lower addresses.
Next Time …
Process creation
Kernel services
More about the execution environment
References I
Required Readings
[1] Randal E. Bryant and David R. O’Hallaron. Computer Science: A Programmer’s
Perspective. Third Edition. Chapter 7: Intro, 7.1-7.5. Pearson, 2016.
Optional Readings
[2] John R. Levine. Linkers & Loaders. Chapter 3: 3.1, 3.7. Morgan Kaufmann Publishers,
2000.
License