elf

Extract detailed symbol information (struct members) from elf file compiled with ARM-GCC

筅森魡賤 提交于 2019-12-06 05:54:19
问题 I’m using ARM-GCC 4.7.4 to compile Code for a Cortex-M4. For our Debug tool I need knowledge about names, types and addresses of all variables in human readable format (e.g. .txt). The map file provides most of the information, unfortunately not for structure contents like below: typedef struct { float32_t Ref; // Input: Reference Value float32_t Fdb; // Variable: Feedback Value float32_t Err; // Input: Control Error float32_t Kp; // Parameter: Gain of the Proportional Part float32_t Up; //

How to debug program with custom elf interpreter?

ⅰ亾dé卋堺 提交于 2019-12-06 05:22:01
问题 I can debug some program (say /bin/ls) like this: [ks@localhost ~]$ gdb -q --args /bin/ls Reading symbols from /bin/ls...Reading symbols from /bin/ls...(no debugging symbols found)...done. (no debugging symbols found)...done. Missing separate debuginfos, use: debuginfo-install coreutils-8.22-19.fc21.x86_64 (gdb) start Temporary breakpoint 1 at 0x402990 Starting program: /usr/bin/ls [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1".

How to collect data from different .a files into one array? How to keep sections in .a files with ld script?

China☆狼群 提交于 2019-12-06 04:41:57
问题 I need to collect some data from different .a files to one array. I do it by collecting data to one section first .c file TArElement __attribute__((section(".my.special.section"))) uwiveuve = { ... second .c file TArElement __attribute__((section(".my.special.section"))) egwegwxb = { ... etc. in ld script __my_mega_array_begin = ABSOLUTE(.); KEEP(*(.my.special.section)) __my_mega_array_end = ABSOLUTE(.); in main .c file extern TArElement *__my_mega_array_begin extern TArElement *__my_mega

Loading Linux libraries at runtime

感情迁移 提交于 2019-12-06 04:14:35
问题 I think a major design flaw in Linux is the shared object hell when it comes to distributing programs in binary instead of source code form. Here is my specific problem: I want to publish a Linux program in ELF binary form that should run on as many distributions as possible so my mandatory dependencies are as low as it gets: The only libraries required under any circumstances are libpthread, libX11, librt and libm (and glibc of course). I'm linking dynamically against these libraries when I

How to extract function prototypes from an elf file?

女生的网名这么多〃 提交于 2019-12-06 03:31:00
问题 I have not been successful in finding an answer on this question. Using GDB, I can use the command "call" to get the prototype of a function. Example: (gdb) call fn $1 = {void (int, int)} 0x8048414 <fn> So, GDB is able to figure out, only from the elf-file, that fn() returns void and takes two integers as arguments. However, I need to use some other tool to extract the function prototypes from an elf file. Preferably, I want to use objdump / readelf. Does anyone know if this is possible? If

Get elf sections offsets

雨燕双飞 提交于 2019-12-06 03:19:26
问题 I'm trying to get the offset and the data of each sections of an elf file. I already have the sections names with this code: #include <elf.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> int filesize(int fd) { return (lseek(fd, 0, SEEK_END)); } void print_section(Elf64_Shdr *shdr, char *strTab, int shNum) { int i; for(i = 0; i < shNum; i++) printf("%02d: %s\n", i, &strTab[shdr[i].sh_name]); } int main(int ac, char **av) { void *data; Elf64_Ehdr *elf; Elf64

How to set the dynamic linker path for a shared library?

十年热恋 提交于 2019-12-06 02:35:11
问题 I want to compile a shared library with an .interp segment. #include <stdio.h> int foo(int argc, char** argv) { printf("Hello, world!\n"); return 0; } I'm using the following commands. gcc -c -o test.o test.c ld --dynamic-linker=blah -shared -o test.so test.o I end up without an INTERP segment, as if I never passed the --dynamic-linker=blah option. Check with readelf -l test.so . When building an executable, the linker processes the option correctly and puts an INTERP segment in the program

how __libc_start_main@plt works?

不羁的心 提交于 2019-12-06 02:19:33
问题 This question was migrated from Unix & Linux Stack Exchange because it can be answered on Stack Overflow. Migrated 4 years ago . To study how the object file loaded and run in linux, I made the simplest c code, file name simple.c. int main(){} Next, I make object file and save object file as text file. $gcc ./simple.c $objdump -xD ./a.out > simple.text From many internet articles, I could catch that gcc dynamically load initiating functions like _start, _init, __libc_start_main@plt, and so on

relationship between VMA and ELF segments

谁都会走 提交于 2019-12-06 02:01:05
I need to determine the VMAs for loadable segments of ELF executables. VMAs can be printed from /proc/pid/maps . The relationship between VMAs shown by maps with loadable segments is also clear to me. Each segment consists of one or more VMAs. what is the method used by kernel to form VMAs from ELF segments: whteher it takes into consideration only permissions/flags or something else is also required? As per my understanding, a segment with flags Read, Execute (code) will go in separate VMA having same permission. While next segment with permissions Read, Write(data) should go in an other VMA.

Clang produces crashing code with -nostdlib

本秂侑毒 提交于 2019-12-06 01:49:18
I am playing around with setting up my own runtime environment for an executable, and I can't get clang (v3.4-1ubuntu1, target: x86_64-pc-linux-gnu) to produce an executable that doesn't segfault. I have reduced the problem to the following: If I have a file crt1.c that does nothing except satisfy the linker requirement for a _start symbol: void _start(char *arguments, ...) { } Then I compile it with clang -nostdlib crt1.c , it produces the following executable (from objdump -d a.out ): a.out: file format elf64-x86-64 Disassembly of section .text: 0000000000400150 <_start>: 400150: 55 push