Understanding Executable and Linkable Format (ELF)

Slide Note
Embed
Share

Executable and Linkable Format (ELF) is a crucial file format for running programs, managing memory permissions, controlling program execution, and handling shared libraries. This article discusses the significance of executable formats, the common executable formats like ELF, PE, Mach-O, and ORC, as well as how ELF works in terms of headers, sections, and segments.


Uploaded on Sep 14, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Executable and Linkable Format (ELF)

  2. Why Executable Formats? - All code in one file - But libraries! We need a way to combine files - Distribute as binary ( object files ) Linkers We need a way to control how our programs run - Memory permissions - Loading addresses Loaders We want PIE code! And shared libraries! - Dynamic linker (ld.so) - - - - -

  3. Why Executable Formats? - Provide key metadata for running programs - Memory permissions - Loading addresses, custom interpreter, etc. Provide debugging assistance - Debug symbols Allow combining (linking) programs - Relocations - Function symbols - -

  4. Common Executable Formats - - - - Executable and Linkable Format (ELF) Portable Executable (PE) Mach object file format (Mach-O) Organized Runtime Contents (ORC) - custom 595g file format! - Admittedly not so common...

  5. How does ELF work? - Reference: http://www.skyfree.org/linux/references/ELF_Format.pdf - Will be posted at http://cs595g.lockshaw.io/w20.html Your friend: readelf - readelf -S (sections) - readelf -l (segments) <- that s a lowercase L - readelf -h (headers) - readelf -a (everything) -

  6. ELF Headers e_type Program entry point virtual address e_entry

  7. Sections vs. Segment - Object file != executable file - But they re both ELFs Sections are chunks of programs we move around when linking Segments are how chunks of programs are loaded into memory No explicit mapping between sections and segments Both section table and segment table point into the overall contents - Need to maintain memory permissions To see mapping, run `readelf -l` - - - - -

  8. Sections - Metadata stored in section table `sh_flags` - permissions - `sh_type` Some sections have no runtime effect: SHT_NOTE SHT_NOBITS - .bss

  9. Common Sections

  10. Symbols `st_name` - index into strtab `st_info` - symbol type, binding STB_LOCAL STB_GLOBAL STB_WEAK

  11. Relocations How do we safely move sections around?

  12. Segments

  13. How does PIE work?

More Related Content