Fix a previously introduced bug in ElfTests related to PIE and addresses.
Summary: This failed on mode/opt, because the `- sh_addr + sh_offset` was actually using the address and offset of the *symbol table section*, not the *data section* (where the kStringValue variable actually is). It still worked, because for mapped sections, the `offset - address` just happens to be the same for all sections, so it didn't matter what section we used; in debug mode, we use dynamic linking, so the symbol section is called .dynsym and is loaded in memory, but in opt mode, the symbol section is called .symtab and is *not* loaded, so sh_addr is zero, and that formula no longer works. The goal there was really just to subtract the binary base address encoded in the ELF file. ElfFile already provides this via getBaseAddress(), and that's also how we can identify whether the loaded ELF (in this case, the same as the current executable) is PIE; so switched both the calculation and the if condition to use this result. Reviewed By: yfeldblum Differential Revision: D23020998 fbshipit-source-id: f7e66bb554c62aa13d7d2fc1017cb31542507be9
Showing
Please register or sign in to comment