ELF: Fix base address computation code for files generated by yaml2obj
authorPavel Labath <pavel@labath.sk>
Fri, 11 Jan 2019 10:18:40 +0000 (10:18 +0000)
committerPavel Labath <pavel@labath.sk>
Fri, 11 Jan 2019 10:18:40 +0000 (10:18 +0000)
commit43ddbc0b6c089185eafa3ebd92de2b1120577ac4
tree29d064dab31878a11519b08ee0c0c19e1f1026a6
parent98ef5337c9dfab72ad8f93a83b6429dfd0da168e
ELF: Fix base address computation code for files generated by yaml2obj

The code was assuming that the elf file will have a PT_LOAD segment
starting from the first byte of the file. While this is true for files
generated by most linkers (it's a way of saving space), it is not a
requirement. And files not satisfying this constraint can still be
perfectly executable. yaml2obj is one of the tools which produces files
like this.

This patch relaxes the check in ObjectFileELF to take the address of the
first PT_LOAD segment as the base address of the object (instead of the
one with the offset 0). Since the PT_LOAD segments are supposed to be
sorted according to the VM address, this entry will also be the one with
the lowest VM address.

If we ever run into files which don't have the PT_LOAD segments sorted,
we can easily change this code to return the lowest VM address as the
base address (if that is the correct thing to do for these files).

llvm-svn: 350923
lldb/lit/Modules/ELF/base-address.yaml [new file with mode: 0644]
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp