FAQ Database Discussion Community


Why these “exported” variables are double-defined?

c,binary,reverse-engineering,x86-64,elf
I am testing some 64-bit ELF binaries on x86/Linux. I compiled apache server using gcc, with its default configuration (optimization level O2 I guess). I stripped the httpd binary with strip command, and I use this command to check the exported variables inside the httpd ELF binary. For example, for...

ELF loading on MIPS, malloc issue

mips,elf,libc,musl
I'm loading a plain statically linked ELF binary in MIPS (32-bit). After mapping the loadable segments, this is how I set up the stack before jumping into my target ELF's CRT's _start function: __asm__(" \ addi $2, %[envN], 0 ;\ .env_loop: \ addi $2, $2, -4 ;\ lw $3, 0($2)...

Linux ELF file: How to get the shared object belonging to an imported function

shared-libraries,elf,dynamic-linking,objdump,ldd
Given a dynamically linked ELF binary, say for example /bin/less. Inside the binary, there is a call to a function provided by a shared library, for example strcpy() How can I find out from which shared library/shared object the strcp function is obtained? In other words, I want to get...

Intercept ELF loader in linux kernel: fs/binfmt_elf.c file via loadable kernel module

c,linux-kernel,kernel,kernel-module,elf
I am new to kernel coding and at present I am working with ELF files which have been modified a little bit for the security purposes for which I need to look at some of it's custom section headers and extract the unique code encryption key from it for the...

c - loading raw binaries

c,operating-system,elf
Is it possible to execute a raw binary stored in a char array? I tried doing it like so: #include "stdio.h" int main(int argc, char **argv) { FILE *f = fopen(argv[1],"r"); if(!f) return 1; fseek(f,0,SEEK_END); long l=ftell(f); rewind(f); char *buf = malloc(l+1); fread(buf,1,l,f); fclose(f); void (*func)() = (void(*))buf; func(); }...

How does the Linux kernel determine ld.so's load address?

linux,linux-kernel,x86-64,elf,dynamic-linking
I know that the dynamic linker uses mmap() to load libraries. I guess it is the kernel who loads both the executable and its .interpreter into the same address space, but how does it determine where? I noticed that ld.so's load address with ASLR disabled is 0x555555554000 (on x86_64) —...

How to compile ELF binary so that it can be loaded as dynamic library? [duplicate]

c,linux,elf,dlopen,dynamic-library
This question already has an answer here: building a .so that is also an executable 3 answers This is theoretical question. I am aware that perhaps best practice would be the use of shared libraries. But I ran into this question and cannot seem to find an answer anywhere....

Reading the contents of an ELF section(programmatically)

c,linux,file,ubuntu,elf
I am trying to retrieve the contents of an additional section within an ELF binary. At this point, I'm using the following code to retrieve the name of each section: #include <stdio.h> #include <unistd.h> #include <stdint.h> #include <stdlib.h> #pragma pack(push,1) #pragma pack(pop) #define EI_NIDENT 16 /* 32-bit ELF base types....

Reading elf structure giving zero values

c,linker,elf
I have a simple cprogram to read the elf execution file, #include <stdint.h> #include <inttypes.h> #include <elf.h> #include <stdio.h> #include <stdlib.h> #pragma pack(push,1) typedef uint32_t uint32; typedef uint16_t uint16; typedef uint8_t uint8; typedef struct { uint8 e_ident[16]; uint16 e_type; uint16 e_machine; uint32 e_version; uint32 e_entry; uint32 e_phoff; uint32 e_shoff; uint32...

Binary, produced by MSP430GCC, has strange start address for text segment

elf,msp430,texas-instruments,mspgcc
After compiling an exemplary C program with msp430-gcc (LTS 20120406 unpatched) for the MSPG2211 I got the following output using the readelf command: section header program header The address space of the MSPG2211 microcontroller is structured as follows: 0x0000 - 0x01FF - Peripherals 0x0200 - 0x027F - RAM 0x1000 -...

Assembly execve failure -14

linux,assembly,nasm,elf,syscall
Program writes executable placed in it's second segment on disk, decrypts it(into /tmp/decbd), and executes(as it was planned) file decbd appears on disk, and can be executed via shell, last execve call return eax=-14, and after end of the program, execution flows on data and gets segfault. http://pastebin.com/KywXTB0X In second...

Detecting unresolved symbols in an ELF executable

c,linux,shared-libraries,ld,elf
Let's say I have two files: // shared.c (will be compiled to 'shared.so') #include <stdio.h> int f() { printf("hello\n"); } and // exe.c (will be compiled to 'exe') #include <stdio.h> int f(); int main() { int i; scanf("%d", &i); if (i == 5) f(); } I compile both files as...

Where does this call go?

c++,linux,assembly,x86,elf
Maybe this is too simple for cpp developers bui I can not figure out.. How does addressing work in this simple object file on lines "3f" and "2d"? Where does 14 and 0 indexes come from? 2d: e8 e2 ff ff ff callq 14 <_ZL9privatef2v> 3f: e8 bc ff ff...

How to make my ELF run with both new and old version of glibc?

linux,linker,glibc,elf
When I'm compiling my elf, it is "best practice" to make it link against the oldest version of glibc I can, so it will work both on new and old versions of glibc. i.e. if I use realpath, which in readelf output of glibc we can see has both a...

What type of symbols does AC_CHECK_LIB check for?

c,elf,autoconf
I'd like to know what type of symbols does AC_CHECK_LIB check for. If I use readelf -a libsomelib.so it prints me a huge bunch of symbols of different categories, including the one I want to check for in AC_CHECK_LIB. Nevertheless, my AC_CHECK_LIB tells that this library cannot be found. Does...

How to change the name of executable entry point from main to something else?

c,gcc,linker,ld,elf
I'm trying to compile third party source code using gcc 4.8 on Ubuntu Linux (12.04 x64) with a lot of utilities and test applications where executable entry point is not called main. Don't ask me why - I don't know the answer. Linker of course complains: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':...

Is it possible to uniquely identify dynamically imported functions by their name?

dynamic-linking,elf,systems-programming,dynamic-loading
I used readelf --dyn-sym my_elf_binary | grep FUNC | grep UND to display the dynamically imported functions of my_elf_binary, from the dynamic symbol table in the .dynsym section to be precise. Example output would be: [...] 3: 00000000 0 FUNC GLOBAL DEFAULT UND [email protected]_2.0 (3) 4: 00000000 0 FUNC GLOBAL...

Gdb struct values all become 0 after “next”

c,struct,gdb,elf
So my struct values are becoming 0 after a "next" command in gdb, which should have no effect. 166 RawElfSymbol *currSymb = symbolTabSec; (gdb) p *currSymb $8 = {name = 623313010, addr = 540682099, size = 1931505518, type_and_bind = 117 'u', ignored = 99 'c', section_tag = 8296} (gdb) next...

How set set entry point in a elf target using ld script

c,gcc,elf
I want to specify the entry point to my ELF file using the linker script. I already defined some sections in my ELF, so want to set an entry point also withit. Can anyone tell me how to do it?

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

glibc,elf,libc,musl
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...

How to debug program with custom elf interpreter?

debugging,gdb,ld,elf
I can debug some program (say /bin/ls) like this: [[email protected] ~]$ 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]...

How does TRACE32 know the type of a global symbol loaded from an ELF?

types,elf,trace32
I have a strange behaviour: I load an ELF file containing two global variables : E1 and S1 Those two variable are both declared as "int" but TRACE32 see E1 as a FLOAT and S1 as an int. I try to use "readelf" but it only say that E1 and...

Why should “data = .;” be repeated three times in a linker script?

linker,ld,elf
I saw this link script in http://www.jamesmolloy.co.uk/tutorial_html/1.-Environment%20setup.html SECTIONS { .text 0x100000 : { code = .; _code = .; __code = .; // What is this line for? *(.text) . = ALIGN(4096); } .data : { data = .; _data = .; __data = .; *(.data) *(.rodata) . = ALIGN(4096);...

ELF executables: required version information for imported symbols

linux,linker,shared-libraries,elf,dynamic-linking
I was hoping that every dynamically linked ELF binary has a .gnu.version_r section (or another section tagged DT_VERNEED), and that this section contains a required version for every symbol imported from a dynamically linked shared object. Yet, there seem to be cases possible in which the compiler/linker adds an DT_NEEDED...

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

c++,elf
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...

Call near in amd64

linux,x86-64,elf,disassembling
I am reading the amd64 manual and in the CALL near section it says: For near calls in 64-bit mode, the operand size defaults to 64 bits. The E8 opcode results in RIP = RIP + 32-bit signed displacement and the FF /2 opcode results in RIP = 64-bit offset...

typedef struct name name without a subsequent struct definition

c++,c,struct,typedef,elf
I found the following code at lines 153-154 in the libelf.h of the libelf library: /* Descriptor for the ELF file. */ typedef struct Elf Elf; I was looking for a struct definition of Elf but did not find it. Later in the code, Elf is used, e.g. /* Return...

gcc error wrong ELF class: ELFCLASS64, despite haveing -m64 flag

c++,unix,gcc,solaris,elf
I have been trying to build a library in solaris using gcc, and keep on hitting wrong ELF class: ELFCLASS64 error. I have googled and found out this is due to trying to link with a 32 bit file which compiling as a 64 bit library. But I have made...