NAME=ELF: dynimports
FILE=bins/elf/analysis/dynimports
CMDS=ii~?
EXPECT=<<EOF
7
EOF
RUN

NAME=ELF: dynstrings section
FILE=bins/elf/elf-solaris-sparc-ls
CMDS=<<EOF
s section..dynstr
pd 10
EOF
EXPECT=<<EOF
            ;-- section..dynstr:
            0x00011b20 (1 bytes hidden)                                ; [04] -r-- section size 3037 named .dynstr
            0x00011b21     .string "xrealloc" ; len=9
            0x00011b2a     .string "nstrftime" ; len=10
            0x00011b34     .string "argmatch_to_argument" ; len=21
            0x00011b49     .string "xzalloc" ; len=8
            0x00011b51     .string "wmemchr" ; len=8
            0x00011b59     .string "hash_get_n_entries" ; len=19
            0x00011b6c     .string "_obstack_begin" ; len=15
            0x00011b7b     .string "_environ" ; len=9
            0x00011b84     .string "strncmp" ; len=8
EOF
RUN

NAME=ELF: section-less dynsym ends at the gnu hash table
FILE=bins/elf/pltrel/aarch64-bti-lld-one-noshdr.so
CMDS=<<EOF
iiq
isq
EOF
EXPECT=<<EOF
0x000013b8 16 foo
0x000013c8 28 call_foo
EOF
RUN

NAME=ELF: section-less dynsym with no sysv hash table
FILE=bins/elf/pltrel/x86_64-retpoline-one-noshdr.so
CMDS=<<EOF
iiq
isq
EOF
EXPECT=<<EOF
0x00001340 4 add2
0x00001350 5 caller
EOF
RUN

NAME=ELF: section-less mips defined symbol is not an import
FILE=bins/elf/analysis/mipsbe-ubusd
CMDS=<<EOF
iiq~_ftext
isq~_ftext
EOF
EXPECT=<<EOF
0x00400ec0 0 _ftext
EOF
RUN

NAME=ELF32: empty dynsym has no imports
FILE=hex://7f454c4601010100000000000000000003000300010000000000000000000000340000000000000034000000000028000400030000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000b0000000000000000000000d4000000000000000200000001000000040000001000000009000000030000000000000000000000e4000000010000000000000000000000010000000000000011000000030000000000000000000000e50000001b000000000000000000000001000000000000000000000000000000000000000000000000002e64796e73796d002e64796e737472002e736873747274616200
CMDS=<<EOF
iij
iij
isj
EOF
EXPECT=<<EOF
[]
[]
[]
EOF
EXPECT_ERR=
RUN

NAME=ELF32: null symbol alone has no imports
FILE=hex://7f454c4601010100000000000000000003000300010000000000000000000000340000000000000034000000000028000400030000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000b0000000000000000000000d4000000100000000200000001000000040000001000000009000000030000000000000000000000e4000000010000000000000000000000010000000000000011000000030000000000000000000000e50000001b000000000000000000000001000000000000000000000000000000000000000000000000002e64796e73796d002e64796e737472002e736873747274616200
CMDS=<<EOF
iij
iij
isj
EOF
EXPECT=<<EOF
[]
[]
[]
EOF
EXPECT_ERR=
RUN

NAME=ELF64: empty dynsym has no imports
FILE=hex://7f454c4602010100000000000000000003003e00010000000000000000000000000000000000000040000000000000000000000040000000000040000400030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000b00000000000000000000000000000000000000400100000000000000000000000000000200000001000000080000000000000018000000000000000900000003000000000000000000000000000000000000005801000000000000010000000000000000000000000000000100000000000000000000000000000011000000030000000000000000000000000000000000000059010000000000001b0000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000002e64796e73796d002e64796e737472002e736873747274616200
CMDS=<<EOF
iij
iij
isj
EOF
EXPECT=<<EOF
[]
[]
[]
EOF
EXPECT_ERR=
RUN

NAME=ELF64: null symbol alone has no imports
FILE=hex://7f454c4602010100000000000000000003003e00010000000000000000000000000000000000000040000000000000000000000040000000000040000400030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000b00000000000000000000000000000000000000400100000000000018000000000000000200000001000000080000000000000018000000000000000900000003000000000000000000000000000000000000005801000000000000010000000000000000000000000000000100000000000000000000000000000011000000030000000000000000000000000000000000000059010000000000001b0000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000002e64796e73796d002e64796e737472002e736873747274616200
CMDS=<<EOF
iij
iij
isj
EOF
EXPECT=<<EOF
[]
[]
[]
EOF
EXPECT_ERR=
RUN

NAME=ELF32: failed symbol and import parsing is attempted once each
FILE=hex://7f454c4601010100000000000000000003000300010000000000000000000000340000000000000034000000000028000400030000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000b0000000000000000000000d4000000010000000200000001000000040000001000000009000000030000000000000000000000e4000000010000000000000000000000010000000000000011000000030000000000000000000000e50000001b000000000000000000000001000000000000000000000000000000000000000000000000002e64796e73796d002e64796e737472002e736873747274616200
CMDS=<<EOF
iij
iij
isj
EOF
EXPECT=<<EOF
[]
[]
[]
EOF
EXPECT_ERR=<<EOF
ERROR: nsym < 1
ERROR: failed parsing imports in section
ERROR: nsym < 1
ERROR: failed parsing imports in section
EOF
RUN

NAME=ELF64: failed symbol and import parsing is attempted once each
FILE=hex://7f454c4602010100000000000000000003003e00010000000000000000000000000000000000000040000000000000000000000040000000000040000400030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000b00000000000000000000000000000000000000400100000000000001000000000000000200000001000000080000000000000018000000000000000900000003000000000000000000000000000000000000005801000000000000010000000000000000000000000000000100000000000000000000000000000011000000030000000000000000000000000000000000000059010000000000001b0000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000002e64796e73796d002e64796e737472002e736873747274616200
CMDS=<<EOF
iij
iij
isj
EOF
EXPECT=<<EOF
[]
[]
[]
EOF
EXPECT_ERR=<<EOF
ERROR: nsym < 1
ERROR: failed parsing imports in section
ERROR: nsym < 1
ERROR: failed parsing imports in section
EOF
RUN

NAME=ELF: section-less aarch64_be bti plt reads code little-endian
FILE=bins/elf/aarch64_be-bti-noshdr.so
CMDS=ii~bar,baz
EXPECT=<<EOF
2   0x00010408 GLOBAL NOTYPE     bar
3   0x00010420 GLOBAL NOTYPE     baz
EOF
RUN

NAME=ELF: aarch64_be bti plt entry crossing its segment end is not probed
FILE=malloc://1320
CMDS=<<EOF
wff bins/elf/aarch64_be-bti-noshdr.so
# RX LOAD p_filesz 0x88 -> 0x5a: the last entry crosses the segment end
wx 5a @ 0xd7
# RX LOAD p_memsz to match
wx 5a @ 0xdf
oba 0
ii~bar,baz
EOF
EXPECT=<<EOF
2   0x00010400 GLOBAL NOTYPE     bar
3   0x00010410 GLOBAL NOTYPE     baz
EOF
RUN

NAME=ELF: aarch64_be bti plt entry truncated by the file end is not probed
FILE=malloc://1410
CMDS=<<EOF
wff bins/elf/aarch64_be-bti-noshdr.so
# RX LOAD p_offset 0x3b0 -> 0x528, past the original end
wx 0528 @ 0xbe
# first 90 bytes of the PLT text: the file ends inside an entry
wx 5f2403d50f0000941400009419000094c0035fd60000000000000000000000005f2403d5f07bbfa910010090118642f91022149120021fd61f2003d51f2003d510010090118a42f91042149120021fd61f2003d51f2003d51001 @ 0x528
oba 0
ii~bar,baz
EOF
EXPECT=<<EOF
2   0x00010400 GLOBAL NOTYPE     bar
3   0x00010410 GLOBAL NOTYPE     baz
EOF
RUN
