I was step tracing uboot execution right from power on. During initial boot, uboot relocates itself. In my case the relocated address (relocaddr
) is 0x3bf53000. So I did the following and was able to do step debugging even after relocation :
>>> p /x ((struct global_data)*0x3bb4eda0)->relocaddr
$1 = 0x3bf53000
>>> add-symbol-file u-boot 0x3bf53000
add symbol table from file "u-boot" at
.text_addr = 0x3bf53000
(y or n) y
Reading symbols from u-boot...
>>> b board_init_r
Breakpoint 4 at 0x9ab54: board_init_r. (2 locations)
>>> info b
Num Type Disp Enb Address What
1 breakpoint keep n 0x00000000000825f8 <relocate_code+20>
breakpoint already hit 1 time
2 breakpoint keep y <MULTIPLE>
2.1 y 0x000000000009ab58 <board_init_r+4>
2.2 y 0x000000003bf6db54 in board_init_r at common/board_r.c:797
All good so far. When I look at the binary, the symbols is located at the following offset.
naveen@workstation:~/.repos/src/arm64/u-boot$ readelf -s u-boot | grep board_init_r
5162: 000000000009ab54 132 FUNC GLOBAL DEFAULT 3 board_init_r
So why can't I simply put a breakpoint at address 0x3bf53000 (relocaddr) + 0x9ab54 (offset) = 0x3BFEDB54
? Instead when used gdb command add-symbol-file u-boot 0x3bf53000
, it set breakpoint at 0x3bf6db54
. Why a difference of 0x80000
? Now this is a special value because if I am not wrong, this is also the load address where u-boot is originally loaded. So this is indicating that 0x9ab54
is an absolute load address and I should be subtracting 0x80000
from it and add that difference to the relocaddr
to get the new breakpoint address. Is my understanding correct? If yes, can someone please help with some readelf or similar commands that I can use to confirm this logic?
I tried it but not sure why there are 4 entries for same address. I was expecting just _start
.
naveen@workstation:~/.repos/src/arm64/u-boot$ readelf -s u-boot | grep 0000000000080000
1: 0000000000080000 0 SECTION LOCAL DEFAULT 1
26: 0000000000080000 0 NOTYPE LOCAL DEFAULT 1 $x
5419: 0000000000080000 0 NOTYPE GLOBAL DEFAULT 1 _start
6138: 0000000000080000 0 OBJECT GLOBAL DEFAULT 1 __image_copy_start