This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: My-first-libelf-program breaks libraries
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Fri, 20 May 2011 16:21:14 +0200
- Subject: Re: My-first-libelf-program breaks libraries
Hi Daniel,
On Fri, 2011-05-20 at 14:54 +0100, Daniel Drake wrote:
> I narrowed it down to a simple test case which can easily be shown to
> break libc, even though my understanding is that this code should do
> (almost) nothing:
> http://dev.laptop.org/attachment/ticket/10898/libelf_library_eater.c
>
> $ gcc libelf_library_eater.c -lelf -o eater
> $ cp /lib/libc-2.13.so .
> $ ./libc-2.13.so
> GNU C Library stable release version 2.13, by Roland McGrath et al.
> $ ldd libc-2.13.so
> /lib/ld-linux.so.2 (0x0030d000)
> linux-gate.so.1 => (0x00909000)
> $ ./eater libc-2.13.so
> $ ./libc-2.13.so
> Segmentation fault
> $ ldd libc-2.13.so
> statically linked
>
> What am I missing?
For non-ET_REL files (shared libraries, executables already linked) you
don't want to change the section layout. Unless you explicitly tell
libelf you want to keep the current section setup (offsets, alignment,
etc) it will feel free to rearrange them. So you want to add an explicit
elf_flagelf (e, ELF_C_SET, ELF_F_LAYOUT); before you call elf_update.
Cheers,
Mark