3

I have Linux Kernel with me and trying to generate ELF Header on it using objcopy tool, Below is the first step

     objcopy -I binary -B i386 -O elf32-i386 --rename-section .data=.text linux_kernel.bin  main.o

And after this I wanted to read symbol table using readelf -s main.o ,but getting strange symbols, below is output

   Symbol table '.symtab' contains 5 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
 0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
 1: 00000000     0 SECTION LOCAL  DEFAULT    1 
 2: 00000000     0 NOTYPE  GLOBAL DEFAULT    1 _binary_linux_kernel_bin_
 3: 004df650     0 NOTYPE  GLOBAL DEFAULT    1 _binary_linux_kernel_bin_
 4: 004df650     0 NOTYPE  GLOBAL DEFAULT  ABS _binary_linux_kernel_bin_

Now should be able to see symbols like

_binary_linux_kernel_bin_start
_binary_linux_kernel_bin__end
_binary_linux_kernel_bin_size

Can any body let me know where I am doing wrong?? or is it expected one??

Why I wanted to see proper symbol because have to do something like below one

 --entry_point=_binary_linux_kernel_bin_start
Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199

2 Answers2

10

You can use the readelf -W -s main.o command, where the -W tells readelf not to truncate the output to 80-character width.

Tuxdude
  • 47,485
  • 15
  • 109
  • 110
4

It is simply that the string is too long and readelf is truncating. Try objdump -x main.o.

artless noise
  • 21,212
  • 6
  • 68
  • 105
  • 'Thanks Bills "objdump -x main.o" shows me "_binary_linux_kernel_bin_start" but just one more wanted to know is _binary_linux_kernel_bin_start=_start ?? – Amit Singh Tomar Mar 12 '13 at 17:32
  • It will be 'zero'. The way the `objcopy` works is you can create a binary and put it in to an object. The `_start` will not be the kernel start address. If you link the 'main.o' with some other object and create a final elf, then `_binary_linux_kernel_bin_start` will be the address in the image. You can not create linux load address from the binary. That information is gone. – artless noise Mar 12 '13 at 22:39