ELF Shared Library compilation troubles (badly aligned ptrs)
Posted: Thu May 21, 2009 4:51 am
When attempting to implement dynamic linking in my OS I started implementing my own version of libc to use in link testing.
After blaming my kernel, then the dynamic linker it seems that the problem is in the binary file itself.
The problem is that when the code tries to get the address of the GOT, the address is two bytes out.
objdump output:
The address of the GOT obtained from the LD linking map is 0x23d8, but the value in EBX after the second instruction is 0x23d6.
I am using the standard linux toolchain (Ubuntu 9.04, gcc 4.3.3, binutils 2.19.1), compiling the library with
and linking with
Does anyone know what could be causing this error?
After blaming my kernel, then the dynamic linker it seems that the problem is in the binary file itself.
The problem is that when the code tries to get the address of the GOT, the address is two bytes out.
objdump output:
Code: Select all
627: e8 00 05 00 00 call b2c <_sbrk+0xa5>
62c: 81 c3 aa 1d 00 00 add $0x1daa,%ebx
632: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp)
639: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
640: 8b 83 f8 ff ff ff mov -0x8(%ebx),%eax
646: 8b 00 mov (%eax),%eax
**SNIP**
b2c: 8b 1c 24 mov (%esp),%ebx
b2f: c3 ret
I am using the standard linux toolchain (Ubuntu 9.04, gcc 4.3.3, binutils 2.19.1), compiling the library with
Code: Select all
$(CC) -Wall -fPIC -nostdinc -fno-builtin -I./include -fleading-underscore -DBUILD_SO -o $@ -c $<
Code: Select all
$(LD) -x -shared -soname libc.so.1 $(OBJ_LIBC) -o $@ -Map map.txt -e _SoMain