This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

How to create a library which contains absolute addresses of exported functions?


How to create a library which contains absolute addresses of exported functions?

I am developping on an embeded system. Most programs require a basic utility library 'libc'. To save memory usage, this library stays alone in a raw binary file 'libc.bin'.
The addresses of exported functions are determinate in compilation time if the base address of 'libc' is assigned. For example, the base address of libc is 0x80002000,
and the address of exported functions are:
  strcpy:   80001600
  vsprintf: 80002290
  memmove:  80001e50
  ...

On the other hand, a library is neccessary for the linker to link the programs referring to the functions in 'libc'. The question is, how to create such a library `libc.a', which does not 
contain any implementation code, but the absolute address of each exported functions?

My solution is:
1. Get the addresses of exported functions by objdump.
   ----------------------------------
   mips-elf-objdump -t libc.out
   80001600 g     F .libc	00000000 strcpy
   80002290 g     F .libc	00000000 vsprintf
   80001e50 g     F .libc	00000000 memmove

2. Create a linker script `link.xn':
   ----------------------------------
   OUTPUT_ARCH(mips) 
   
    SECTIONS
    {
    	strcpy   = 0x80001600;
    	vsprintf = 0x80002290;
    	memmove  = 0x80001e50;
    }
   ----------------------------------
   
3. Create an empty C file foo.c.

4. Create the 'libc.a' libaray from foo.c and link.xn.
   mips-elf-gcc -EL -o foo.o foo.c
   mips-elf-ld -EL -T link.xn -o libc.a foo.o
   
I wonder if there is another simple and easy way to create such a library.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]