elf

Why does compiling this simple assembly code and linking to ELF result in such a bigger size than flat binary?

我只是一个虾纸丫 提交于 2019-12-11 00:12:09
问题 I'm working with an embedded OS like environment, and so size of binaries needs to be as small as possible. I had been using simple flat binary files as an executable, but now I'm trying to use ELF. I'm just using assembly code, but linking with ld. Assembly code: CPU i386 BITS 32 SECTION .text progbits alloc exec nowrite GLOBAL start start: mov eax, 0 add eax, 1 inc eax mov eax, 0x12345678 mov dword [0x100000], eax mov ebx, dword [0x100000] mov eax, ebx out 0xF3, al ;dump memory API call out

Using Contiguous Memory of C Struct Members

孤者浪人 提交于 2019-12-10 23:26:36
问题 Before you mark this as duplicate, please do read the question. So this may be a potentially very stupid question but it is bothering me. I know, from reading, as well as many other SO questions that fields in a struct in C are not guaranteed to be contiguous due to padding added by the compiler. For example, according to the C standard: 13/ Within a structure object, the non-bit-field members and the units in which bit-fields reside have addresses that increase in the order in which they are

How to count static initializer in an ELF file?

蓝咒 提交于 2019-12-10 19:59:52
问题 I'm trying to count static initializers in a C++ file. Solution I already have (which used to work with gcc-4.4) is looking at size of the .ctors ELF section. After an upgrade to gcc-4.6, this seems to no longer return valid results (calculated number of static initializers is 0, which doesn't match reality, e.g. as returned by nm). Now the issue is I'd like the solution to work even in absence of symbols (otherwise I'd have used nm). Below is the output of readelf -SW of an example

How to make duplicate sections in ELF file

只谈情不闲聊 提交于 2019-12-10 19:10:34
问题 I have a requirement where I need to create a duplicate/copy section of .data section. I've tried creating a dummy section with same size of data section in linker script and copy the contents of data section to the dummy section in the init functions of my ELF image, but that doesn't suit my requirement, as I want the copy/duplicate section to be created along with final ELF image not during the execution of it. Below is what I wanted in my linker script, SECTIONS { .data : { <data section

Easiest way to merge 2 or more ELF files

穿精又带淫゛_ 提交于 2019-12-10 18:26:42
问题 I'm working on some embedded code for a class project that currently (per requirements) creates a number of srec files and merges them. I'd like to be able to load this code into QEMU, but it is generally only happy with ELF files. What is the esiest way to merge the original ELF files instead of the srecs. Also acceptable, a method to convert the srec back into an ELF and have the resulting file be loadable (objcopy seems to produce fairly broken files doing this (no architecture amoung

Load both musl libc.so and gcc libc.so in the same process?

不羁的心 提交于 2019-12-10 17:46:33
问题 I have a shared library compiled with musl libc $ readelf -d ./libinterop_d.so Dynamic section at offset 0x8ecb0 contains 22 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [libc.so] 0x000000000000000f (RPATH) Library rpath: [/usr/local/musl/lib] 0x000000000000000c (INIT) 0x46350 0x000000000000000d (FINI) 0x7664a 0x0000000000000019 (INIT_ARRAY) 0x28e700 0x000000000000001b (INIT_ARRAYSZ) 64 (bytes) 0x000000000000001a (FINI_ARRAY) 0x28e740 0x000000000000001c (FINI

map the address of string literal to string literal, by parsing ELF C++ program

五迷三道 提交于 2019-12-10 17:43:20
问题 Address of string literals are determined at compile time. This address and the string literal can be found in the built executable program (In ELF format). For example, the following code outputs String Literal: 0x400674 printf("String Literal: %p\n", "Hello World"); And objdump -s -j .rodata test1 shows Contents of section .rodata: 400670 01000200 48 656c6c 6f20576f 726c6400 .... H ello World. .... So it looks like I can get the virtual address of "Hello World" by reading the executable

Reading ELF String Table on Linux from C

大憨熊 提交于 2019-12-10 11:13:43
问题 I want to write a program which reads the string table of a binary. Binary is in ELF running on REDHAT linux 32. I did the following - Read the Elf Header Read all the sections Below is the output of my progam. Entry Address of Binary - 0x8048340 Start of Program Header - 52 Start of section header - 3272 Size of header - 52 Number of section headers - 36 Size of each section headers - 40 Number of section headers - 36 Section header Offset - 3272 string tbl index for section[0] is 0 string

Clang produces crashing code with -nostdlib

大憨熊 提交于 2019-12-10 10:19:39
问题 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

ELF dynamic symbol table

匆匆过客 提交于 2019-12-10 10:15:56
问题 I have a question about ELF dynamic symbol table. For symbols of type FUNC, I have noticed a value of 0 in some binaries. But in other binaries, it has some non-zero value. Both these binaries were generated by gcc, I want to know why is this difference?. Is there any compiler options to control this? EDIT: This is the output of readelf --dyn-syms prog1 Symbol table '.dynsym' contains 5 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 NOTYPE