This is an archive of the discontinued LLVM Phabricator instance.

Rename ObjectFile::GetHeaderAddress to GetBaseAddress
ClosedPublic

Authored by labath on Dec 7 2018, 3:13 AM.

Details

Summary

This function was named such because in the case of MachO files, the
mach header is located at this address. However all (most?) usages of
this function were not interested in that fact, but the fact that this
address is used as the base address for expressing various relative
addresses in the object file.

For other object file formats, this name is not appropriate (and it's
probably the reason why this function was not implemented in these
classes). In the ELF case the ELF header will usually end up at this
address, but this is a result of the linker optimizing the file layout
and not a requirement of the spec. For COFF files, I believe the is no
header located at this address either.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Dec 7 2018, 3:13 AM
labath marked an inline comment as done.Dec 7 2018, 3:22 AM

Adding a bunch of people to make sure this makes sense for all object formats (I am particularly oblivious to how COFF works). If this makes sense, I'll implement this function in ObjectFilePECOFF and ELF to return the "image base" and "base address" respectively.

source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
1676–1677 ↗(On Diff #177165)

This is the most dodgy usage I believe. It looks like this piece of code is expecting to use the base ObjectFile implementation of this function, which returns the m_memory_addr member. However, this will in reality call the MachO implementation which does something completely different (and independent of being in memory). It might be better to change this to GetObjectFile()->IsInMemory(), but I have no idea how to verify that.

clayborg accepted this revision.Dec 7 2018, 8:22 AM

Looks fine. Just one clarification in the header documentation and this is good to go.

include/lldb/Symbol/ObjectFile.h
561 ↗(On Diff #177165)
/// offset member filled in indicating the resulting Address object represents a file address.
source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
1677 ↗(On Diff #177165)

Switching to IsInMemory will work. This code probably predates the existence of IsInMemory().

This revision is now accepted and ready to land.Dec 7 2018, 8:22 AM
labath marked 2 inline comments as done.Dec 11 2018, 7:21 AM
labath added inline comments.
source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
1677 ↗(On Diff #177165)

Ok, I'll check this in separately, as this is the only functional change in this commit.

This revision was automatically updated to reflect the committed changes.