elf

In an ELF file, how does the address for _start get detemined?

让人想犯罪 __ 提交于 2019-11-28 13:51:30
I've been reading the ELF specification and cannot figure out where the program entry point and _start address come from. It seems like they should have to be in a pretty consistent place, but I made a few trivial programs, and _start is always in a different place. Can anyone clarify? The _start symbol may be defined in any object file. Normally it is generated automatically (it corresponds to main in C). You can generate it yourself, for instance in an assembler source file: .globl _start _start: // assembly here When the linker has processed all object files it looks for the _start symbol

How can I find which ELF dependency is not fulfilled?

旧巷老猫 提交于 2019-11-28 12:02:19
I've built a test ELF program using the LSB SDK ( note that my question is not specific to LSB ): $ /opt/lsb/bin/lsbcc tst.c $ ls -l a.out -rwxr-xr-x 1 math math 10791 2009-10-13 20:13 a.out $ file a.out a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped But I am unable to launch it ( yes, I assure you the file is in the directory... ): $ ./a.out bash: ./a.out: No such file or directory $ uname -a Linux math 2.6.28-15-generic #52-Ubuntu SMP Wed Sep 9 10:48:52 UTC 2009 x86_64 GNU/Linux I think there is an ELF

How to print the name of the symbols of ELF files like the nm?

梦想的初衷 提交于 2019-11-28 11:28:49
问题 I know the name of the symbols are in the shstrtab. But I don't get how to catch them. Should I cast my shstrab into a Elf64_Sym so that I can use the st_name? Elf64_Shdr *shdr = (Elf64_Shdr *) (data + elf->e_shoff); Elf64_Shdr *symtab; Elf64_Shdr *shstrtab; Elf64_Shdr *strtab; char *str = (char *) (data + shdr[elf->e_shstrndx].sh_offset); for (int i = 0; i < elf->e_shnum; i++) { if (shdr[i].sh_size) { printf("%s\n", &str[shdr[i].sh_name]); if (strcmp(&str[shdr[i].sh_name], ".symtab") == 0)

getting the sh_name member in a section header elf file

前提是你 提交于 2019-11-28 09:17:53
I'm trying to get the correct offset to the section name by accessing the sh_name member of an elf file, but it keep giving me zero, or null... I'm supposed to only use mmap() and the elf.h - no helper functions So I did: void* map_start = mmap(0, fd_stat.st_size, PROT_READ | PROT_WRITE , MAP_SHARED, fd, 0)) header = (Elf32_Ehdr *) map_start; secoff = header->e_shoff; section = (Elf32_Shdr *)(map_start + secoff); but when I do: printf("name offset = %d\n", (section->sh_name)); it keeps giving me 0... what am I doing wrong? when i do printf("name offset = %d\n", (section->sh_name)); it keeps

Manually generate elf core dump

六月ゝ 毕业季﹏ 提交于 2019-11-28 08:54:59
问题 I am looking for manually generating an ELF Core Dump file. I have a RAM dump from my program, and can also retrieve register informations and so on. With this data, I would like to build an ELF core dump file, similar as those generated by Linux kernel when a program crashes, the goal would be to analyse this core dump with a GDB specifically made for my platform. I have been looking for core dumps specifications or detailed format, but did not find what I wanted : What sections does my core

What is default register state when program launches (asm, linux)?

南楼画角 提交于 2019-11-28 08:26:45
When the program launches (linux, elf) - is there zeros in eax , ebx , etc. or there can be anything (i'm not doing any calls or using extern libraryies)? On my machine it is really so, can I relay on such behavior when writing asm programms? This depends entirely on the ABI for each platform. Since you mention eax and ebx let's see what's the case for x86. In fs/binfmt_elf.c line #972, inside load_elf_binary() , the kernel checks if the ABI specifies any requirements for register values at program loading: /* * The ABI may specify that certain registers be set up in special * ways (on i386

How to find the offset of the section header string table of an elf file?

房东的猫 提交于 2019-11-28 07:03:10
I have to write a C program that prints an ELF file. I'm having trouble figuring out where the section header string table is. Let's say I have a file that gave me the following output with: readelf -h ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: REL (Relocatable file) Machine: Intel 80386 Version: 0x1 Entry point address: 0x0 Start of program headers: 0 (bytes into file) Start of section headers: 17636 (bytes into file) Flags: 0x0 Size of this header: 52

Has anyone been able to create a hybrid of PE COFF and ELF?

﹥>﹥吖頭↗ 提交于 2019-11-28 06:36:50
I mean could a single binary file run in both Win32 and Linux i386 ? This is not possible, because the two types have conflicting formats: The initial two characters of a PE file must be 'M' 'Z' ; The initial four characters of an ELF file must be '\x7f' 'E' 'L' 'F' . Clearly, you can't create one file that satisifies both formats. In response to the comment about a polyglot binary valid as both a 16 bit COM file and a Linux ELF file, that's possible (although really a COM file is a DOS program, not Windows - and certainly not Win32). Here's one I knocked together - compile it with NASM. It

List all the functions/symbols on the fly in C code on a Linux architecture?

删除回忆录丶 提交于 2019-11-28 06:22:14
Assume main.c uses symbols from shared libs and local functions declared in main.c . Is there a nice and elegant way to print a list of all the available function names and symbols at run time? It should be possible since the data is loaded to the .code segment. Since I had the same need to retrieve all loaded symbol names at runtime, I did some research based upon R..'s answer. So here is a detailed solution for linux shared libraries in ELF format which works with my gcc 4.3.4, but hopefully also with newer versions. I mostly used the following sources to develop this solution: ELF Manpage

Difference in position-independent code: x86 vs x86-64

谁都会走 提交于 2019-11-28 05:51:59
I was recently building a certain shared library (ELF) targeting x86-64 architecture, like this: g++ -o binary.so -shared --no-undefined ... -lfoo -lbar This failed with the following error: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC Of course, it means I need to rebuild it as position-independent code, so it's suitable for linking into a shared library. But this works perfectly well on x86 with exactly the same build arguments. So the question is, how is relocation on x86 different from x86-64 and why don't I need to