Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Mohit Mishra

Rating No ratings yet

Focusing on the Executable and Linkable Format (ELF) used in Linux and Unix systems, this book explores how code is compiled, linked, and loaded into memory, and how the operating system executes it. You’ll learn to analyse ELF files, debug and optimize programs at the binary level, write custom linker scripts, and understand dynamic linking and symbol resolution. ELF files are important because low-level programming and binary analysis are critical skills for system programmers, embedded developers, and security researchers. With the rise of performance optimization, cybersecurity, and resource-constrained environments (e.g., IoT), understanding executables is more relevant than ever. Executable Files for Linux provides a hands-on, modern approach to a topic often overlooked in learning resources today. What You Will Learn • Analyse and modify ELF files to optimize software performance • Debug and optimize programs at the binary level • Write custom linker scripts for complex projects • Understand dynamic linking, lazy loading, and symbol resolution • Explore kernel-level processes for loading and executing binaries Who This Book Is For Developers and programmers working on operating systems, embedded systems, or low-level software as well as performance engineers and security professionals

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on tour of Linux executables that turns the ELF format from a black box into a working mental model—ideal for systems programmers, embedded developers, and security engineers who want to inspect, debug, and optimize binaries at the byte level. 【Book Arc】 - **Opening (~0%–10%)**: Starts from a deceptively simple question—why a "Hello World" binary is so large—and uses it to motivate the whole book: size breakdowns, the executable lifecycle, and the four-part ELF structure (header, program header table, sections, section header table). - **Early (~10%–35%)**: Demystifies the ELF format itself: PHDR/INTERP/LOAD segments, memory permissions and W^X, PIE and ASLR, and the differences between relocatable files, executables, shared objects, and core dumps. Then moves into sections—.text, .rodata, .data, .bss—and how section permissions, layout, and stripping affect loading and performance. - **Middle (~35%–55%)**: Shifts from static structure to build-time mechanics: how global variables are initialized before main(), the linker's role in combining object files, symbol resolution, and relocation records (R_X86_64_32S, PLT32, PC32) with their performance trade-offs. - **Late (~55%–80%)**: Covers the linker's "address book"—symbol types, bindings, visibility levels, versioning, interposition, and debugging symbol problems—then introduces custom linker scripts for controlling memory layout, separating critical code, and exporting linker symbols. - **Ending (~80%–100%)**: Moves toward runtime and security: dynamic linking, lazy loading, symbol resolution at load time, kernel-level binary loading, and hardening features like stack canaries and RELRO. Excerpts do not cover the final chapters in detail. 【Key Takeaways】 - **ELF is one format with four roles** (Early): the same structure serves relocatable object files, executables, shared objects, and core dumps—each with different header tables and resolution states. Understanding this unity prevents confusion when switching between build stages. - **Sections vs. segments are different views** (Early): sections describe link-time content organization; segments (program headers) tell the kernel how to map memory. Permissions like R E vs. RW enforce W^X and are a first line of defense. - **PIE and ASLR are defaults, not options** (Early): modern Linux binaries are position-independent (type DYN), enabling address randomization. This changes how you reason about addresses, debugging, and exploitation. - **Global variable initialization is a hidden program phase** (Middle): constructors, destructors, and circular dependencies between globals create undefined behavior if mishandled—lazy initialization or a single init point are the fixes. - **Relocations are the linker's patch instructions** (Middle): absolute, PC-relative, and PLT relocations trade off speed, position independence, and lazy binding. Choosing the right model matters for shared libraries and startup cost. - **Symbols are the linker's address book** (Late): visibility levels, versioning, and interposition control what gets resolved where—and symbol resolution has measurable performance impact. - **Linker scripts are a memory map blueprint** (Late): they let you separate critical code, control load vs. runtime addresses, and debug layout problems that no compiler flag can fix. - **Binary size is a design choice** (Early): stripping debug info, understanding .bss (which doesn't occupy file space), and section locality all affect both footprint and runtime performance. 【Reading Tips】 - **Deep-read Chapters 1–3** if you're new to ELF: the "Hello World is big" framing builds intuition that pays off later. Skim if you already know readelf output. - **Keep a terminal open**: the book is tool-driven (readelf, size, nm, strip, objdump). Running commands on your own binaries is where the learning sticks. - **Treat linker scripts as the hard chapter**: concepts like load address vs. runtime address and exporting linker symbols are where most readers slow down—budget extra time and experiment with a minimal script. - **For security readers**, focus on W^X, PIE/ASLR, RELRO, and stack canaries; for embedded/performance readers, focus on sections, relocations, and linker script layout control. - **Don't skip the practical exercises** at the end of the linker script chapter—they consolidate the most abstract material. 【Coverage Limits】 This guide is based on stratified excerpts covering roughly the first half to two-thirds of the book; later chapters on dynamic linking internals, kernel loading, and advanced security hardening are referenced but not detailed in the source material.
Excerpt 1
ystem Calls 44 ELF in Different Contexts: A Comparison 44 Relocatable Files (o) 45 Executable Files 45 Shared Objects (so) 45 Core Dumps 46 The Evolution of...
View in text
Excerpt 2
0x0000000000001000 0x0000000000001000 0x0000000000001000 0x0000000000000235 0x0000000000000235 R E 0x1000 LOAD 0x0000000000002000 0x0000000000002000 0x000000...
View in text
Excerpt 3
tant “Hello, World!” is stored in the .rodata section. The magic number is typically handled by the compiler as an immediate value in the instructions rather...
View in text
Excerpt 4
bject files, which are the compiled but not yet executable versions of your source code. Understanding how the linker works is essential for building robust...
View in text
Excerpt 5
S addreSS book int global_function(int x) { return x * 2; } __attribute__((weak)) int weak_function(int x) { return x * 2; } // Hidden symbol in shared libra...
View in text
Excerpt 6
xp); } Create a version script: # mathops.map MATHOPS_1.0 { global: add; subtract; multiply; divide; mathops_version; local: MATHOPS_2.0 { global: add; # New...
View in text
Excerpt 7
} } Build and use: $ gcc -shared -fPIC -o malloc_profiler.so malloc_profiler.c -ldl -lpthread # Profile any program $ LD_PRELOAD=./malloc_profiler.so ls /usr...
View in text
Excerpt 8
const char *filename) { FILE *f = fopen(filename, "w"); fprintf(f, "#!/usr/bin/env python3\n"); fprintf(f, "import os\n"); fprintf(f, "print('Hello from Pyth...
View in text
Tags
AI categories
LinuxProgramming LanguageCybersecurity
ISBN: 8868821532
Publisher: Apress
Publish Year: 2026
Language: English
Pages: 338
File Format: PDF
File Size: 7.3 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…