elf

What is the difference between a .o object file and a .so library file ?

Like the title says, what is the difference between a "program object file" (.o extension) and a "library file" (.so extension) ...

How to know which dynamic libraries are needed by an ELF?

Is there any tool that reading the headers prints the name of the dynamic libraries required by a Linux executable to run? I need it to know if there are some weird dependencies (i.e. not very standard) in a binary that I've just built from the source (it's the Python branch of GDB) or it's mostly statically linked. I think that would b...

Any hand-on exercise to understand how a program is loaded into memory and get executed

Hi, I am curious about the things happend before main() is called , such like load the executable into memory , dynamic load of shared library. Do you have any suggestions how to understand these things by a hand-on exercise? The tools amd things I know of ,and using now, includes: strace disassemble readelf /proc/pid/map NOTES: ...

Where do uninitialized Global Variables go after initializing?

Hi! I struck a little problem when learning. I know that uninitialized global variables in C are assigned to the .bss section in the executable ELF file. But what happens to them when I start to use them? I.e. do they get a place on the heap or somewhere else? I tried to find out by printing the address of the (still uninitialized) glo...

gcc compiled binaries w/different sizes?

If the same code is built at different times w/gcc, the resulting binary will have different contents. OK, I'm not wild about that, but that's what it is. However, I've recently run into a situation where the same code, built with the same version of gcc, is generating a binary with a different size than a prior build (by about 1900 by...

load-time ELF relocation

Hi, I am writing a simple user-space ELF loader under Linux (why? for 'fun'). My loader at the moment is quite simple and is designed to load only statically-linked ELF files containing position-independent code. Normally, when a program is loaded by the kernel's ELF loader, it is loaded into its own address space. As such, the data ...

GNU LD Script to catch C++ group / dynsym Sections

I'm maintaining a tool which can convert ELF32 relocatables to RDOFF2 format. For this process to work I need to pre-link the input files currently using the ld-script shown below: OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") OUTPUT_ARCH(i386) FORCE_COMMON_ALLOCATION SECTIONS { .text : { /* collect .init / .f...

vmlinux ELF find offsets for members of a given struct

In the Linux kernel, I need to find the offsets of member variables of a struct that is used. For example, for the init_task which is of type task_struct, I would like the offsets of its pid and tasks. I only have the vmlinux present for this. I can refer to the open source kernel code, but it may differ from the build I have. Is it p...

Converting a .so file to a .jnilib file

I've got a .so library compiled for Linux under the ELF format, which is being used by a Java program. I'm trying to port this application to Mac OS X, and have discovered that OS X uses a different extension for these files, .jnilib. I've already figured out how to set up the PATH so that it correctly finds the files. However, OS X Java...

How can I find which ELF dependency is not fulfill?

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 ...

Aligning static arrays in the .bss section of linker file

I have a function: void testfunction() { static char_t theChar1 = 1; static unsigned char smallArray[1]; static unsigned char largeArray[135]; ... } and a linker file: . = ALIGN(4); _edata = . ; PROVIDE (edata = .); .bss (NOLOAD) : { __bss_start = . ; __bss_start__ = . ; *(.bss) *(.bss.*) *(COMMO...

Loading/unloading ELF sections on demand?

For a rather obscure use case I'd like to have a (large) statically linked Linux executable made up of a small piece of control code and large pieces of static (read-only) data. Is it possible, to save memory, to get the loader to load only the sections for the control code, and then manually load the sections of RO data as they are nee...

How can I examine contents of a data section of an ELF file on Linux?

I've been using objdump to look at assembly code in Linux ELF binaries. Sometimes there is an indirect jump through a jump table that is stored in the rodata (read-only data) section. I have tried Google and SO, but I must be wearing my stupid hat, because I cannot figure out how to get objdump or any other tool to show me the contents...

Segmentation Fault With Char Array and Pointer in C on Linux

So I have the following program: int main(){ char* one = "computer"; char two[] = "another"; two[1]='b'; one[1]='b'; return 0; } It segfaults on the line "one[1]='b'" which makes sense because the memory that the pointer "one" points to must be in read only memory. However, the question is why doesn't the line "two[1]='b'" s...

Linux user-space ELF loader

I need to do a rather unusual thing: manually execute an elf executable. I.e. load all sections into right places, query main() and call it (and cleanup then). Executable will be statically linked, so there will be no need to link libraries. I also control base address, so no worries about possible conflicts. So, is there are any librar...

Add source code to elf file

Hi, I want to add my C++ source code to the corresponding elf binary file and I'm looking for the best way to do this. (I'm using several versions of my code and not every version should be committed into svn). Can I just append the source code without destroying the elf file using bash's >> operator? Or is objcopy --add-section a way ...

Why doesn't ld honor the '-rpath-link' option?

I detect this using strace: 8480 execve("/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../../i486-slackware-linux/bin/ld", [ "/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../../i486-slackware-linux/bin/ld", ... "-L/home/bjack/lib", ... "-rpath-link", "/root/src/firmware/Bj-bg/ab-BJ-gameprom-modules/src/dis...

COFF on Linux or ELF on Windows

Is it possible to run the COFF executable files on UNIX or the ELF executable files on Windows? And what would be the steps to be able to run either file type on Windows and UNIX. I'm just curious. ...

GNU gdb 6.4 on SunOS 5.10, recognized executable formats.

Hi! Below details are from a session in a sun machine. $ file devli devli: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped $ file a a: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped $ gdb GNU gdb 6.4 Copyright 2005 Free Software Foundation, Inc. GDB is free software, covered by the ...

How to load a shared library without loading its dependencies?

Say I have a library libfoo.so.1, which depends (according to ldd) on libbar.so.1. However, libbar.so.1 is not available at the moment. My app needs to call a function in libfoo.so.1 which doesn't require libbar.so.1 at all. Is there a way to load libfoo.so.1, resolve the function symbol and then call it without having libbar.so.1 to sa...