> For the complete documentation index, see [llms.txt](https://davidjosearaujo.gitbook.io/notes-mcs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://davidjosearaujo.gitbook.io/notes-mcs/reverse-engineering/binary-analysis/what-is-inside-an-object-file.md).

# What is inside an Object File?

An Object File contains information required to execute a program (not only code).

* May not include all implementations, as this can be dynamically loaded.

Information is kept in sections, which are processed differently. Some are:

* **`.rodata`**: read-only data, containing strings.
* **`.got`**: Global Offset Table - maps symbols to memory locations (offsets).
* **`.plt`**: Procedure Linkage Table – uses the PLT to transfer execution to the correct location of a symbol, dealing with external symbols and fixing the GOT.
* **`.bss`**: **Block Starting Symbol** – contains uninitialized variables.
* **`.dynsym`**: List of symbols in allocatable memory.
* … many others:
  * To read sections: `readelf -S hello`
  * To dump all code: `objdump -M intel -d hello`

<figure><img src="https://1103423335-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvyEajzuIz0PAtDiV6JcU%2Fuploads%2FVaVB1QAkUrMAzlIlKA25%2FScreenshot%20from%202024-03-26%2023-25-27.png?alt=media&amp;token=2e30bf4d-2cba-4819-8414-2db7e28629c8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1103423335-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvyEajzuIz0PAtDiV6JcU%2Fuploads%2FixU2hVmXjkO2c2KGw4ky%2FScreenshot%20from%202024-03-26%2023-25-57.png?alt=media&amp;token=7f31b6dd-58f6-4e06-b4ca-653f2cedea29" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1103423335-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvyEajzuIz0PAtDiV6JcU%2Fuploads%2FeOskkOFZx7dCMZfgwtBh%2FScreenshot%20from%202024-03-26%2023-26-21.png?alt=media&amp;token=99233a78-49bb-4c7e-a25e-e54aa37573b4" alt=""><figcaption></figcaption></figure>

## How are objects loaded?

<figure><img src="https://1103423335-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvyEajzuIz0PAtDiV6JcU%2Fuploads%2F8o6R9A3TNXtXDa3iQhH8%2FScreenshot%20from%202024-03-26%2023-27-04.png?alt=media&amp;token=1345ea90-7b10-4d92-ab8c-1c43efdb99f1" alt=""><figcaption></figcaption></figure>

The file is **split** according to existing **sections**. Each is loaded at a different location (with different access attributes).

**Libraries are also mapped** in the program address space. All code from libraries is present.

**The stack** grows **downwards**, **heap** grows **upwards**. On modern OS, growth may be limited, not on microcontrollers.

An interpreter is required to set up the binary in memory.

* `ld-Linux.so` or `ntdll.dll`
  * `readelf -p .interp filename`
* Will handle relocations, and resolve required symbols.
* If lazy-loading is used, relocation is done when the symbol is first used
