# merged: ELF: CREL ET_REL import pinned (no dynstr, no phdr: plt lookup masked)
NAME=compact relocs
FILE=bins/elf/new/compact-relocs.oo
CMDS=<<EOF
iS;ir;s0x08000040;af;pdf
?e --
ii
ir
EOF
EXPECT=<<EOF
nth paddr       size vaddr       vsize perm flags type     name
---------------------------------------------------------------
0   0x00000000   0x0 0x08000000    0x0 ---- 0x0   NULL
1   0x0000017a  0x5f 0x0800017a   0x5f ---- 0x0   STRTAB   .strtab
2   0x00000040  0x14 0x08000040   0x14 -r-x 0x6   PROGBITS .text
3   0x00000170   0x5 0x08000170    0x5 ---- 0x40  ----     .crel.text
4   0x00000054  0x16 0x08000054   0x16 ---- 0x30  PROGBITS .comment
5   0x0000006a   0x0 0x0800006a    0x0 ---- 0x0   PROGBITS .note.GNU-stack
6   0x00000070  0x40 0x08000070   0x40 -r-- 0x2   PROGBITS .eh_frame
7   0x00000175   0x5 0x08000175    0x5 ---- 0x40  ----     .crel.eh_frame
8   0x000000b0  0xc0 0x080000b0   0xc0 ---- 0x0   SYMTAB   .symtab
vaddr      paddr      type   ntype name
---------------------------------------
0x08000048 0x00000048 ADD_64 283   callee
0x0800008c 0x0000008c ADD_64 261   .text
            ;-- section..text:
/ 20: sym.caller ();
|           0x08000040      fd7bbfa9       stp x29, x30, [sp, -0x10]!  ; [02] -r-x section size 20 named .text
|           0x08000044      fd030091       mov x29, sp
|           ;-- reloc.callee:
|           0x08000048      00000094       bl reloc.callee             ; RELOC 64 callee
|           0x0800004c      fd7bc1a8       ldp x29, x30, [sp], 0x10
\           0x08000050      c0035fd6       ret
--
nth vaddr      bind   type   lib name
-------------------------------------
7   ---------- GLOBAL NOTYPE     callee
vaddr      paddr      type   ntype name
---------------------------------------
0x08000048 0x00000048 ADD_64 283   callee
0x0800008c 0x0000008c ADD_64 261   .text
EOF
RUN


NAME=ELF: i386 implicit-addend crel patches with the in-place word
FILE=bins/elf/i386-crel-implicit.o
ARGS=-e bin.relocs.apply=true
CMDS=<<EOF
pxw 4 @ 0x08000035
pxw 4 @ 0x0800003a
pxw 4 @ 0x08000048
EOF
EXPECT=<<EOF
0x08000035  0x00000006                                   ....
0x0800003a  0x08000044                                   D...
0x08000048  0x08000048                                   H...
EOF
RUN

NAME=ELF: CREL relocs are parsed again for a second bin object
FILE=bins/elf/new/compact-relocs.oo
CMDS=<<EOF
o bins/elf/new/compact-relocs.oo
ob 1
ir~ADD_64?
EOF
EXPECT=<<EOF
2
EOF
RUN

NAME=ELF: i386 crel relocs from every crel section are listed
FILE=bins/elf/i386-crel-implicit.o
CMDS=<<EOF
ir~0x08
EOF
EXPECT=<<EOF
0x08000035 0x00000035 SET_32 2     g
0x0800003a 0x0000003a SET_32 1     v
0x08000048 0x00000048 SET_32 1     v
0x0800004c 0x0000004c SET_32 1     f
EOF
RUN

NAME=ELF: crel oversized count ending at the section end keeps both sections
FILE=malloc://488
CMDS=<<EOF
wx 7f454c4601010100000000000000000001000300010000000000000000000000d000000000000000340000000000280007000100e8fcffffffa104000000c3c30000000000000000080000000200000000000000000000000000000000000000100000000000000000000000100002000e0000000b0000000000000010000200010000000000000000000000100004007807020217017f7f0810230301117e7e7a0076002e6372656c2e7465787400670066002e737472746162002e73796d746162002e6372656c2e646174610000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000030000000000000000000000a10000002d0000000000000000000000010000000000000008000000010000000600000000000000340000000c000000000000000000000004000000000000000300000014000040400000000000000090000000070000000600000002000000010000000100000027000000010000000300000000000000400000001000000000000000000000000100000000000000220000001400004040000000000000009900000006000000060000000400000001000000010000001a000000020000000000000000000000500000004000000001000000010000000400000010000000
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000035 0x00000035 SET_32 2     g
0x0000003a 0x0000003a SET_32 1     v
0x00000048 0x00000048 SET_32 1     v
0x0000004c 0x0000004c SET_32 1     f
EOF
RUN

NAME=ELF: crel oversized count does not decode into the next section
FILE=malloc://488
CMDS=<<EOF
wx 7f454c4601010100000000000000000001000300010000000000000000000000d000000000000000340000000000280007000100e8fcffffffa104000000c3c30000000000000000080000000200000000000000000000000000000000000000100000000000000000000000100002000e0000000b0000000000000010000200010000000000000000000000100004007807020217017f7f0810230301117e7e7a0076002e6372656c2e7465787400670066002e737472746162002e73796d746162002e6372656c2e646174610000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000030000000000000000000000a10000002d0000000000000000000000010000000000000008000000010000000600000000000000340000000c000000000000000000000004000000000000000300000014000040400000000000000090000000050000000600000002000000010000000100000027000000010000000300000000000000400000001000000000000000000000000100000000000000220000001400004040000000000000009900000006000000060000000400000001000000010000001a000000020000000000000000000000500000004000000001000000010000000400000010000000
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000035 0x00000035 SET_32 2     g
0x00000048 0x00000048 SET_32 1     v
0x0000004c 0x0000004c SET_32 1     f
EOF
RUN

NAME=ELF: crel truncated header is not read past the section
FILE=malloc://488
CMDS=<<EOF
wx 7f454c4601010100000000000000000001000300010000000000000000000000d000000000000000340000000000280007000100e8fcffffffa104000000c3c30000000000000000080000000200000000000000000000000000000000000000100000000000000000000000100002000e0000000b0000000000000010000200010000000000000000000000100004001007020217017f7f0890230301117e7e7a0076002e6372656c2e7465787400670066002e737472746162002e73796d746162002e6372656c2e646174610000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000030000000000000000000000a10000002d0000000000000000000000010000000000000008000000010000000600000000000000340000000c000000000000000000000004000000000000000300000014000040400000000000000090000000070000000600000002000000010000000100000027000000010000000300000000000000400000001000000000000000000000000100000000000000220000001400004040000000000000009900000001000000060000000400000001000000010000001a000000020000000000000000000000500000004000000001000000010000000400000010000000
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000035 0x00000035 SET_32 2     g
0x0000003a 0x0000003a SET_32 1     v
EOF
RUN

NAME=ELF: dynamic crel oversized count does not decode into the next section
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000005000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_32 1
EOF
RUN

NAME=ELF: dynamic crel section covering both entries lists both
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000008000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_32 1
0x00000020 0x00000020 SET_32 2
EOF
RUN

NAME=ELF: dynamic crel inside its section does not decode into the next section
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000005000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
wx 9c0000009c00000009000000 @ 0x134
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_32 1
EOF
RUN

NAME=ELF: dynamic crel inside a section covering both entries lists both
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000005000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
wx 9c0000009c0000000c000000 @ 0x134
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_32 1
0x00000020 0x00000020 SET_32 2
EOF
RUN

NAME=ELF: pltrel crel truncated stream is not read past the section
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000005000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
wx 140000002600000017000000a0000000020000000c0000000000000000000000 @ 0x80
wx 2000000020000000 @ 0x64
wx 20000000 @ 0x164
wx 03000000 @ 0x13c
oba 0
ir~0x0~?
EOF
EXPECT=<<EOF
0
EOF
RUN

NAME=ELF: pltrel crel stream within its section is listed
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000005000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
wx 140000002600000017000000a0000000020000000c0000000000000000000000 @ 0x80
wx 2000000020000000 @ 0x64
wx 20000000 @ 0x164
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_32 1
EOF
RUN

NAME=ELF: crel section whose sh_addr maps elsewhere decodes its own bytes
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000005000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
wx 00000000 @ 0x80
wx a5000000 @ 0x134
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_32 1
EOF
RUN

NAME=ELF: crel section mapped onto its file bytes is listed
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000005000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
wx 00000000 @ 0x80
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_32 1
EOF
RUN

NAME=ELF: dynamic crel continuation is not read through a segment mapping the next address elsewhere
FILE=malloc://552
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000005000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
wx c8010000 @ 0x1c
wx 0300 @ 0x2c
wx 01000000000000000000000000000000a5000000a5000000050000000010000002000000800000008000000080000000100000001000000006000000040000000100000070000000a5000000a500000010000000100000000500000001000000 @ 0x1c8
wx 43000143000143000143000143000143 @ 0x70
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_32 1
EOF
RUN

NAME=ELF: dynamic crel in a section whose file range wraps is not decoded
FILE=malloc://576
CMDS=<<EOF
wx 7f454c4602010100000000000000000003003e00010000000000000000000000400000000000000040010000000000000000000040003800020040000400030001000000050000000000000000000000000000000000000000000000000000000002000000000000000200000000000000100000000000000200000006000000000100000000000000010000000000000001000000000000200000000000000020000000000000000800000000000000a0064300014300010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002600000000000000b01000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e73687374727461620000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000001000000140000000200000000000000f00f000000000000f0ffffffffffffffc5000000000000000000000000000000010000000000000000000000000000000b00000006000000030000000000000000010000000000000001000000000000200000000000000003000000000000000800000000000000100000000000000014000000030000000000000000000000000000000000000020010000000000001e00000000000000000000000000000001000000000000000000000000000000
oba 0
ir~0x0
EOF
EXPECT=<<EOF
EOF
RUN

NAME=ELF: dynamic crel in an elf64 section within the file is listed
FILE=malloc://576
CMDS=<<EOF
wx 7f454c4602010100000000000000000003003e00010000000000000000000000400000000000000040010000000000000000000040003800020040000400030001000000050000000000000000000000000000000000000000000000000000000002000000000000000200000000000000100000000000000200000006000000000100000000000000010000000000000001000000000000200000000000000020000000000000000800000000000000a0064300014300010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002600000000000000b00000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e73687374727461620000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000001000000140000000200000000000000b000000000000000b00000000000000008000000000000000000000000000000010000000000000000000000000000000b00000006000000030000000000000000010000000000000001000000000000200000000000000003000000000000000800000000000000100000000000000014000000030000000000000000000000000000000000000020010000000000001e00000000000000000000000000000001000000000000000000000000000000
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_64 1
0x00000020 0x00000020 SET_64 2
EOF
RUN

NAME=ELF: dynamic crel address in no section decodes nothing
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000008000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
wx 01 @ 0x12c
wx 00030000 @ 0x84
oba 0
ir~0x0
EOF
EXPECT=
EXPECT_ERR=
RUN

NAME=ELF: dynamic crel address in a non-crel section lists its entries
FILE=malloc://456
CMDS=<<EOF
wx 7f454c460101010000000000000000000300030001000000000000003400000000010000000000003400200002002800050004000100000000000000000000000000000000010000000100000500000000100000020000008000000080000000800000001000000010000000060000000400000000000000000000000000000026000000a0000000000000000000000000000000000000000000000000000000a006430001430001000000000000000000000000000000000000000000000000002e6372656c2e64796e002e64796e616d6963002e6e657874002e7368737472746162000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000001400000002000000a0000000a000000008000000000000000000000001000000000000000b000000060000000300000080000000800000001000000000000000000000000400000008000000140000000100000002000000a5000000a500000003000000000000000000000001000000000000001a000000030000000000000000000000c00000002400000000000000000000000100000000000000
wx 01 @ 0x12c
oba 0
ir~0x0
EOF
EXPECT=<<EOF
0x00000010 0x00000010 SET_32 1
0x00000020 0x00000020 SET_32 2
EOF
RUN

NAME=ELF: CREL patched call site keeps its reloc and the slot keeps its name
FILE=bins/elf/new/compact-relocs.oo
ARGS=-e bin.relocs.apply=true
CMDS=<<EOF
pd 1 @ 0x08000048
pd 1 @ 0x080001e0
EOF
EXPECT=<<EOF
            0x08000048      66000094       bl reloc.callee             ; RELOC 64 callee
            ;-- reloc.callee:
            0x080001e0      .qword 0x0000000000000000                  ; RELOC 64 callee
EOF
RUN
