22.16.5.4 Mapped bounds in bounded arrays

When an array map is bounded, be it by number of elements or by size, the bounding value can be mapped itself. To illustrate how this works, let’s go back to our ELF file and the section containing relocations. First, we map an Elf64_Shdr to get the section header:

(poke) var shdr = Elf64_Shdr @ offset
(poke) shdr.sh_offset
120#B
(poke) shdr.sh_size
24#B

Now we map an array with the relocations themselves, using a map bounded by size, as we learned in the last section:

(poke) var relocs = ELF64_Rela[shdr.sh_size] @ shdr.sh_offset
(poke) relocs'length
3

Now, observe that shdr.sh_size is mapped itself! This means that, should the section size be modified (to accommodate an extra relocation, for example) the mapping of relocs will reflect that automatically:

(poke) shdr.sh_size = shdr.sh_size + 1#Elf64_Rela
(poke) relocs'length
4

This is certainly an useful idiom, that is often used while poking around. However, sometimes this is not what we want. If we don’t want the mapping bounds of relocs to be tied to shdr, we can just use a temporary for the size:

(poke) var s = shdr.sh_size
(poke) var relocs = Elf64_Rela[s] @ shdr.sh_offset

Since simple values (such as the size above) are not mapped, this trick works as intended.