Learning summary based on linux program

  • 2020-05-06 12:11:03
  • OfStack

The linux program has been in touch with some segments in succession. Today, I will make a proper summary. The time is short and the summary is scattered.
linux paragraph:
text: machine code for a compiled program.
.rodata: read only data. Format strings in printf, or jump tables for switch statements.
data: initialized global variable.
bss: uninitialized global variable.
symtab: symbol table.
note:
1. If a global variable is defined, int i = 0; It's initialized to 0, but it's not in data, it's in bss. Because the compiler might do some optimization, if it initializes to 0, it equates it to an uninitialized variable. This may require him to initialize all uninitialized global variables (bss segment) to 0. But this may be related to the compiler.
2. For the static global variable, it has an attribute in the symbol table to indicate that it is local, not global. The symbols of local are not allowed to be referenced by other files.
3. Local variables defined by static, which are treated by the compiler as static global variables. It is present in the symbol table (local variables are not present). The only difference is that it changes its name in the symbol table, usually adding a suffix: ".1788 ". Use this method to prevent global variables from being renamed with other global variables. It also prevents calls to it.
4. Segments are aligned. If you define an char character, you will find that it sometimes increases by four bytes, and then by definition, segment defecation does not increase.
5. Tools for viewing program segments include: readelf, objdump(plus -t to see which segment the variable belongs to), and size (to see the size of each segment).

Related articles: