Questions tagged [elf]

ELF stands for Executable and Linkable Format, a file format for files containing machine code. Use this tag for questions about the ELF format itself, or for questions which are specifically about reading/writing ELF files.

The Executable and Linkable Format (ELF) standard describes a layout for files containing executable machine code. The format is non-proprietary, flexible, extensible and machine architecture-independent.

Most modern open-source operating systems (e.g., Linux) use ELF for their native executables. Notable exceptions are Windows (using PE/COFF) and macOS/iOS (using Mach-O).

Questions that should use the tag:

  • Questions about the ELF format itself, e.g. how certain fields should be used or what their intention is.
  • Questions about reading/parsing ELF files, e.g. via the C elf.h standard header or with the readelf program.
  • Question about writing/modifying ELF files, e.g. using tools like objcopy or strip.

Resources:


Related tags:

  • For questions about the readelf program, which is used for parsing and dumping most non-machine code sections of an ELF file.
  • For questions about the objcopy program, which allows changing section contents or adding sections to existing ELF files.
2307 questions
21
votes
2 answers

How to make an executable ELF file in Linux using a hex editor?

Just curious. This obviously isn't a very good solution for actual programming, but say I wanted to make an executable in Bless (a hex editor). My architecture is x86. What's a very simple program I can make? A hello world? An infinite loop?…
Jamie
  • 2,181
  • 1
  • 21
  • 35
21
votes
2 answers

Where is the "Section to segment mapping" stored in ELF files?

As part of trying to write a compiler completely from scratch, I'm currently working on the part the handles ELF files. After skimming through several articles and specifications about them, I still don't quite understand where section to segment…
BizarreCake
  • 662
  • 5
  • 14
21
votes
4 answers

understanding the __libc_init_array

I viewed the source code of __libc_init_array from http://newlib.sourcearchive.com/documentation/1.18.0/init_8c-source.html . But I don't quite understand what this function does. I know that these symbols /* These magic symbols are provided by…
Pony279
  • 403
  • 1
  • 6
  • 12
21
votes
1 answer

Symbol visibility, exceptions, runtime error

I try to understand symbol visibility better. The GCC Wiki (http://gcc.gnu.org/wiki/Visibility) has a section about "Problems with C++ exceptions". According to GCC Wiki it is possible the have runtime error because of not exported exceptions.…
VargaD
  • 496
  • 1
  • 5
  • 9
20
votes
1 answer

Why does a fully static Rust ELF binary have a Global Offset Table (GOT) section?

This code, when compiled for the x86_64-unknown-linux-musl target, produces a .got section: fn main() { println!("Hello, world!"); } $ cargo build --release --target x86_64-unknown-linux-musl $ readelf -S hello There are 30 section headers,…
kreo
  • 2,613
  • 2
  • 19
  • 31
20
votes
3 answers

Why Linux/gnu linker chose address 0x400000?

I'm experimenting with ELF executables and the gnu toolchain on Linux x86_64: I've linked and stripped (by hand) a "Hello World" test.s: .global _start .text _start: mov $1, %rax ... into a 267 byte ELF64…
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
20
votes
1 answer

which part of ELF file must be loaded into the memory?

An ELF file for executables has a program (segment) header and a section header, which can be seen through readelf -a, here is an example: The two pictures above are section header and program (segment) header, respectively. It can be seen that a…
venus.w
  • 2,171
  • 7
  • 28
  • 42
19
votes
1 answer

What are the ELF header differences between an ELF object file and shared object?

First of all, I'm asking this from a technical perspective, not a perspective of the user of library code. One example of a difference is that shared objects contain program headers and ordinary object files don't. What are the other differences? As…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
19
votes
3 answers

Remove file paths from TEXT directives in go binaries

I want to remove all path information like /Users/myuser/dev/go/src/fooapi/spikes/mongoapi.go from the executable that I created with go build. I'm compiling the code like this: CGO_ENABLED=0 go build -v -a -ldflags="-w -s" -o ./fooapi…
Inanc Gumus
  • 25,195
  • 9
  • 85
  • 101
19
votes
1 answer

How do I add contents of text file as a section in an ELF file?

I have a NASM assembly file that I am assembling and linking (on Intel-64 Linux). There is a text file, and I want the contents of the text file to appear in the resulting binary (as a string, basically). The binary is an ELF executable. My plan is…
David Jones
  • 4,766
  • 3
  • 32
  • 45
19
votes
2 answers

Why does objdump not show .bss, .shstratab, .symtab and .strtab sections?

I'm currently doing my own objdump implementation in C. For my -s option, I have to show the full contents of the sections of an ELF file. I'm doing it well, but I'm showing more sections than the "real" objdump. In fact, it does not output the…
user1746732
19
votes
5 answers

Clarification on Binary file (PE/COFF & ELF) formats & terminology

I'm confusing little in terminology. A file that is given as input to the linker is called Object File. The linker produces an Image file, which in turn is used as input by the loader. I got this from "MS PE & COFF Specification" Q1. Image file is…
claws
  • 52,236
  • 58
  • 146
  • 195
19
votes
4 answers

COFF on Linux or ELF on Windows

Is it possible to run the COFF executable files on UNIX or the ELF executable files on Windows? And what would be the steps to be able to run either file type on Windows and UNIX. I'm just curious.
PJT
  • 3,439
  • 5
  • 29
  • 40
18
votes
5 answers

ELF core file format

Short of digging through GDB source, where can I find documentation about the format used to create core files? The ELF specification leaves the core file format open, so I guess this should be part of the GDB specifications! Sadly, I did not find…
NoJunkNoNoise
  • 191
  • 1
  • 1
  • 5
18
votes
2 answers

How can I override a class scoped __declspec(dllexport) annotation on a per-member basis?

On ELF targets, if I have class Foo and I have given it default visibility via a declaration like class __attribute__((visibiility("default"))) Foo, I can then selectively exempt certain members of the class from having default visibility by…
acm
  • 12,183
  • 5
  • 39
  • 68