I am trying to get the address of an instruction marked by a label in ARM assembly, in relation to it's section without rewriting an assembler. For example:
.text
nop # 0
mov r1, r2 # 4
loop:
mov r0, #170 # 8
If I want the address of loop
then I get 8, because each instruction here is 4 bytes long and it begins after two instructions.
I have to clarify I'm not looking for ldr r0, =loop
, I'm looking for a command like GCC which I feed a .s
file to and get something like
loop=.text+0x0000ad4e
abc=.data+0x0000007a
Thanks in advance!
Use either the nm
or the objdump -t
command to retrieve the information you are interested in: Before relocation happens, the symbol values printed by nm
are relative to the segment beginning as you wanted.
The output looks like this:
$ nm moves.o
00000000 T attack_map
00000280 T generate_moves
00000160 T gote_in_check
U moves_for
00000320 T play_move
00000110 T sente_in_check
000001b0 T turn_board
00000000 r turn_board.turned_board
and for objdump -t
:
$ objdump -t moves.o
moves.o: file format elf32-i386-freebsd
SYMBOL TABLE:
00000000 l df *ABS* 00000000 moves.c
00000000 l O .rodata 0000001d turn_board.turned_board
00000000 l d .rodata 00000000 .rodata
00000000 g F .text 00000106 attack_map
00000280 g F .text 00000099 generate_moves
00000160 g F .text 00000047 gote_in_check
00000000 *UND* 00000000 moves_for
00000320 g F .text 00000169 play_move
00000110 g F .text 0000004a sente_in_check
000001b0 g F .text 000000c7 turn_board
User contributions licensed under CC BY-SA 3.0