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
1
vote
1 answer

Check if an elf executable is running with GUI or CUI on UNIX

In Windows you can check if IMAGE_OPTIONAL_HEADERS.Subsystem from the PE header is equal to either IMAGE_SUBSYSTEM_WIN_GUI or IMAGE_SUBSYSTEM_WIN_CUI. Is there a UNIX/ELF equivalent? I've…
clark
  • 395
  • 5
  • 12
1
vote
2 answers

I need to link C program on a shared object with no section headers

I've written an interface to the code generator that lets me produce shared objects. Though I do not want o implement support for section header table because that's where the majority complexity of ELF file format remains in. GNU ld uses section…
Cheery
  • 24,645
  • 16
  • 59
  • 83
1
vote
1 answer

How to insert/remove some garbage instructions into ELF/PE file without changing its functionality?

I am trying to do a academic experiments and basically what I am trying to do is insert and remove some garbage instructions like these into the ELF or PE file. Pop eax NOP NOP NOP Push eax So my questions are how to insert certain instructions…
lllllllllllll
  • 8,519
  • 9
  • 45
  • 80
1
vote
1 answer

Segment mapping in an ELF file

ELF files consists of sections based on their contents such as .data,.text, .rodata etc and these sections are grouped into segments that guide how the ELF is mapped/loaded into the memory (Virtual/Physical mappings). These segments are formed by…
Steve H
  • 461
  • 2
  • 10
  • 18
1
vote
1 answer

Linker assigns improper LMA to a section (using AT>)

I have a simple asm file with 3 sections: .code 32 .section sec1 MOV R3, #10 .section sec2 MOV R1, #10 .section sec3 MOV R2, #10 .end And a linker script: MEMORY { ram : ORIGIN = 0x00200000, LENGTH = 1K rom : ORIGIN =…
Bart
  • 420
  • 3
  • 18
1
vote
0 answers

Undefined symbols in .bin created from .elf

Let's say I have an object file (elf file) created from asm source: .text .code 32 MOV R1, #10 LDR R2, [R1] .string "hello world" fun1: MOV R1, #1 LDR R2, =_symbol1 LDR R3, =_symbol2 b _reset .end Running arm-elf-nm gives me…
Bart
  • 420
  • 3
  • 18
1
vote
1 answer

Why does sections related to dynamic linking like .got exist in an executable file generated with static linking?

I am learning linking, and came across a question. If I have a source file main.c: int main() { return 0; } I compiled it with static linking: gcc -static -o a.out main.c And then I found that sections related to dynamic linking like .got is…
feirainy
  • 497
  • 1
  • 4
  • 11
1
vote
1 answer

Accessing the code section of a C++ program

Based upon my understanding, a C/C++ program looks something like this in the memory: I wanted to know the following : Can I access the "text section" of the running program? By accessing I mean printing the start and end addresses and examining…
sud03r
  • 19,109
  • 16
  • 77
  • 96
1
vote
1 answer

Android shared library sum of sections size is greater than shared lib size

In Android, if I analyse a shared library using objdump tool, I observe the following: sum of the section sizes in the shared library is less than the binary file size. Which is understandable as, Binary size = ELF header size + Program header size…
Abhirup Ghosh
  • 153
  • 1
  • 6
1
vote
0 answers

How to break a file down per static library in linux

I'm trying to reduce the size of files in my project to reduce its overall size. One of the ways I'm looking at is replacing some of the static libraries the files are made of with a dependency on shared objects. Before I start doing that, I'd like…
nitzanms
  • 1,786
  • 12
  • 35
1
vote
1 answer

GCC, What's the effect of declaring visibility "default" and "hidden", from objdump perspective

A very concrete question here. I have two sample foo2d.c files like this: First, #include __attribute__((visibility("default"))) void FooX(int i); void Foo2(int i) { printf("Via Foo2(%d)\n", i); FooX(i); } Second, #include…
Jimm Chen
  • 3,411
  • 3
  • 35
  • 59
1
vote
1 answer

Finding address of a C struct inside an ELF file compatible to ARM Architecture

In my project I defined: (This is not the real code - for abstraction purpose) typedef struct { ... } my_struct; In some C file I declared: my_struct my_struct_inst; And in other 2 C files I used that struct by declaring: extern my_struct…
Bush
  • 2,433
  • 5
  • 34
  • 57
1
vote
1 answer

Translate from MCInst to ELF Binary in LLVM

I am doing an LLVM project aimed to disassemble an ARM ELF binary executable to the MCInst format, inserting some instructions or doing some modification, and re-assemble the MCInst to an ELF binary. I used llvm-objdump to do the first part of the…
WindChaser
  • 960
  • 1
  • 10
  • 30
1
vote
2 answers

Insert a new section to a binary file?

I try to coding a program to insert a empty (as the first step) phdr struct to any elf binary, so I coding like below: cat add_phdr.c #include #include #include #include #include #include…
liunx
  • 751
  • 4
  • 13
  • 32
1
vote
1 answer

how to get minimum executable opcodes for c program?

to get opcodes author here does following: [bodo@bakawali testbed8]$ as testshell2.s -o testshell2.o [bodo@bakawali testbed8]$ ld testshell2.o -o testshell2 [bodo@bakawali testbed8]$ objdump -d testshell2 and then he gets three sections (or…
4pie0
  • 29,204
  • 9
  • 82
  • 118
1 2 3
99
100