NAME=ELF: ppc relocs
FILE=bins/elf/hello.ppc
CMDS=<<EOF
ii
ir
s main
af
pdsf
EOF
EXPECT=<<EOF
nth      vaddr bind   type   lib name              
---------------------------------------------------
  1 ---------- GLOBAL FUNC       printf
  2 ---------- WEAK   NOTYPE     __gmon_start__
  3 ---------- GLOBAL FUNC       __libc_start_main
     vaddr      paddr type           name              
-------------------------------------------------------
0x10020008 0x00010008 R_PPC_GLOB_DAT __gmon_start__
0x10020064 0x10020064 R_PPC_JMP_SLOT printf
0x1002006c 0x1002006c R_PPC_JMP_SLOT __gmon_start__
0x10020074 0x10020074 R_PPC_JMP_SLOT __libc_start_main
0x100004a0 str.Simple_PPC_program. str.Simple_PPC_program.
EOF
RUN

NAME=ELF: arm relocs 1
FILE=bins/elf/r2pay-arm32.so
CMDS=<<EOF
ir~?
# ARM_RELATIVE
s 0xb58c0
pf bbbb
pd 1
# ARM_ABS32
s 0xb58c4
pf bbbb
pd 1
# ARM_ABS32
s 0xb58d8
pf bbbb
pd 1
# ARM_GLOB_DAT
s 0xb5dbc
pf bbbb
pd 1
# ARM_JUMP_SLOT
s 0xb5e08
pf bbbb
pd 1
EOF
EXPECT=<<EOF
427
0x000b58c0 = 0x24
0x000b58c1 = 0x45
0x000b58c2 = 0x00
0x000b58c3 = 0x00
            ;-- section..fini_array:
            ;-- segment.LOAD1:
            0x000b58c0      .dword 0x00004524 ; entry0 ; entry.fini0 ; section..text; RELOC 32  ; [13] -rw- section size 4 named .fini_array
0x000b58c4 = 0x60
0x000b58c5 = 0x45
0x000b58c6 = 0x00
0x000b58c7 = 0x00
            ;-- section..init_array:
            ;-- .datadiv_decode1794556967687044894:
            0x000b58c4      .dword 0x00004560 ; reloc.target..datadiv_decode1794556967687044894 ; sym..datadiv_decode1794556967687044894; RELOC 32 .datadiv_decode1794556967687044894 @ 0x00004560 ; [14] -rw- section size 364 named .init_array
0x000b58d8 = 0x44
0x000b58d9 = 0x8b
0x000b58da = 0x09
0x000b58db = 0x00
            ;-- .datadiv_decode668687990735969933:
            0x000b58d8      .dword 0x00098b44 ; reloc.target..datadiv_decode668687990735969933 ; sym..datadiv_decode668687990735969933; RELOC 32 .datadiv_decode668687990735969933 @ 0x00098b44
0x000b5dbc = 0x24
0x000b5dbd = 0x35
0x000b5dbe = 0x14
0x000b5dbf = 0x00
            ;-- x.10:
            0x000b5dbc      .dword 0x00143524 ; reloc.target.x.10 ; obj.x.10; RELOC 32 x.10 @ 0x00143524
0x000b5e08 = 0xb4
0x000b5e09 = 0x37
0x000b5e0a = 0x14
0x000b5e0b = 0x00
            ;-- __cxa_atexit:
            0x000b5e08      .dword 0x001437b4 ; reloc.target.__cxa_atexit; RELOC 32 __cxa_atexit
EOF
RUN

NAME=ELF: arm relocs 2
FILE=bins/elf/r2pay-arm32.so
CMDS=<<EOF
ir~?
s section..init_array
pd 10
EOF
EXPECT=<<EOF
427
            ;-- section..init_array:
            ;-- .datadiv_decode1794556967687044894:
            0x000b58c4      .dword 0x00004560 ; reloc.target..datadiv_decode1794556967687044894 ; sym..datadiv_decode1794556967687044894; RELOC 32 .datadiv_decode1794556967687044894 @ 0x00004560 ; [14] -rw- section size 364 named .init_array
            ;-- .datadiv_decode12875440098136793118:
            0x000b58c8      .dword 0x00004570 ; reloc.target..datadiv_decode12875440098136793118 ; sym..datadiv_decode12875440098136793118; RELOC 32 .datadiv_decode12875440098136793118 @ 0x00004570
            ;-- .datadiv_decode11893604691534341392:
            0x000b58cc      .dword 0x00098028 ; reloc.target..datadiv_decode11893604691534341392 ; sym..datadiv_decode11893604691534341392; RELOC 32 .datadiv_decode11893604691534341392 @ 0x00098028
            0x000b58d0      .dword 0x00008115 ; entry.init0            ; RELOC 32 
            0x000b58d4      .dword 0x00055049 ; entry.init1            ; RELOC 32 
            ;-- .datadiv_decode668687990735969933:
            0x000b58d8      .dword 0x00098b44 ; reloc.target..datadiv_decode668687990735969933 ; sym..datadiv_decode668687990735969933; RELOC 32 .datadiv_decode668687990735969933 @ 0x00098b44
            ;-- .datadiv_decode16868916699024037624:
            0x000b58dc      .dword 0x00098b48 ; reloc.target..datadiv_decode16868916699024037624 ; sym..datadiv_decode16868916699024037624; RELOC 32 .datadiv_decode16868916699024037624 @ 0x00098b48
            ;-- .datadiv_decode12802097292201864397:
            0x000b58e0      .dword 0x00098b4c ; reloc.target..datadiv_decode12802097292201864397 ; sym..datadiv_decode12802097292201864397; RELOC 32 .datadiv_decode12802097292201864397 @ 0x00098b4c
            ;-- .datadiv_decode12428479046606065387:
            0x000b58e4      .dword 0x00098b50 ; reloc.target..datadiv_decode12428479046606065387 ; sym..datadiv_decode12428479046606065387; RELOC 32 .datadiv_decode12428479046606065387 @ 0x00098b50
            ;-- .datadiv_decode7496105736011033460:
            0x000b58e8      .dword 0x00098b54 ; reloc.target..datadiv_decode7496105736011033460 ; sym..datadiv_decode7496105736011033460; RELOC 32 .datadiv_decode7496105736011033460 @ 0x00098b54
EOF
RUN

NAME=ELF: arm thumb relocs 1
FILE=bins/elf/mbedtls-bignum-thumb-interwork.so
CMDS=<<EOF
ir~?
# ARM_THM_PC22
s 0x08000b82
pf bbbb
pd 1
EOF
EXPECT=<<EOF
4810
0x08000b82 = 0x19
0x08000b83 = 0xf0
0x08000b84 = 0xaa
0x08000b85 = 0xfa
            ;-- memset:
            0x08000b82      bl    memset                               ; RELOC 24 memset
EOF
RUN

NAME=ELF: arm64 relocs 1
FILE=bins/elf/r2pay-arm64.so
CMDS=<<EOF
ir~?
s section..init_array
pd 10
EOF
EXPECT=<<EOF
320
            ;-- section..init_array:
            ;-- segment.LOAD1:
            ;-- .datadiv_decode9958896245423089702:
            0x00126510      .qword 0x0000000000005a6c ; reloc.target..datadiv_decode9958896245423089702 ; sym..datadiv_decode9958896245423089702; RELOC 64 .datadiv_decode9958896245423089702 @ 0x00005a6c ; [12] -rw- section size 728 named .init_array
            ;-- .datadiv_decode10476194973746341988:
            0x00126518      .qword 0x0000000000005a80 ; reloc.target..datadiv_decode10476194973746341988 ; sym..datadiv_decode10476194973746341988; RELOC 64 .datadiv_decode10476194973746341988 @ 0x00005a80
            ;-- .datadiv_decode16323044921667855934:
            0x00126520      .qword 0x00000000000efddc ; reloc.target..datadiv_decode16323044921667855934 ; sym..datadiv_decode16323044921667855934; RELOC 64 .datadiv_decode16323044921667855934 @ 0x000efddc
            0x00126528      .qword 0x0000000000009080 ; entry.init0    ; RELOC 64 
            0x00126530      .qword 0x0000000000077d14 ; entry.init1    ; RELOC 64 
            ;-- .datadiv_decode667225052219618748:
            0x00126538      .qword 0x00000000000f22e0 ; reloc.target..datadiv_decode667225052219618748 ; sym..datadiv_decode667225052219618748; RELOC 64 .datadiv_decode667225052219618748 @ 0x000f22e0
            ;-- .datadiv_decode8132880250332170398:
            0x00126540      .qword 0x00000000000f22e4 ; reloc.target..datadiv_decode8132880250332170398 ; sym..datadiv_decode8132880250332170398; RELOC 64 .datadiv_decode8132880250332170398 @ 0x000f22e4
            ;-- .datadiv_decode3655886617018729963:
            0x00126548      .qword 0x00000000000f22e8 ; reloc.target..datadiv_decode3655886617018729963 ; sym..datadiv_decode3655886617018729963; RELOC 64 .datadiv_decode3655886617018729963 @ 0x000f22e8
            ;-- .datadiv_decode16406252260792032531:
            0x00126550      .qword 0x00000000000f22ec ; reloc.target..datadiv_decode16406252260792032531 ; sym..datadiv_decode16406252260792032531; RELOC 64 .datadiv_decode16406252260792032531 @ 0x000f22ec
            ;-- .datadiv_decode13403071575248320347:
            0x00126558      .qword 0x00000000000f22f0 ; reloc.target..datadiv_decode13403071575248320347 ; sym..datadiv_decode13403071575248320347; RELOC 64 .datadiv_decode13403071575248320347 @ 0x000f22f0
EOF
RUN

NAME=ELF: R_ARM_RELATIVE patch reloc
FILE=bins/arm/elf/hello_world
CMDS=<<EOF
pxw 4 @ 0x00010f08
pxw 4 @ 0x00010f0c
pxw 4 @ 0x00011020
pxw 4 @ 0x00011030
pxw 4 @ 0x00011034
pxw 4 @ 0x00011040
EOF
EXPECT=<<EOF
0x00010f08  0x00000509                                   ....
0x00010f0c  0x000004c9                                   ....
0x00011020  0x00000565                                   e...
0x00011030  0x00000525                                   %...
0x00011034  0x0000050d                                   ....
0x00011040  0x00011040                                   @...
EOF
RUN

NAME=ELF: arm64 relocs 2
FILE=bins/elf/graphascii.c-gcc-arm64-O0.o
CMDS=<<EOF
ir~?
s 0x8000444
pf bbbb
pi 1
s 0x8000460
pf bbbb
pi 1
s 0x800046c
pf bbbb
pi 1
s 0x80003d8
pf bbbb
pi 1
EOF
EXPECT=<<EOF
315
0x08000444 = 0x00
0x08000445 = 0x00
0x08000446 = 0x00
0x08000447 = 0xf0
adrp x0, 0x8003000
0x08000460 = 0x1c
0x08000461 = 0x0d
0x08000462 = 0x00
0x08000463 = 0x94
bl reloc.target.stackCursor
0x0800046c = 0x00
0x0800046d = 0x64
0x0800046e = 0x44
0x0800046f = 0xf9
ldr x0, [x0, 0x8c8]
0x080003d8 = 0x3a
0x080003d9 = 0x0d
0x080003da = 0x00
0x080003db = 0x94
bl reloc.target.fputs
EOF
RUN
