[PATCH] D54946: [yaml2obj] [COFF] Subtract the image base for section virtual addresses

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 27 11:00:26 PST 2018


mstorsjo added a comment.

In D54946#1310078 <https://reviews.llvm.org/D54946#1310078>, @zturner wrote:

> Maybe I'm misunderstanding something.  In `COFFYAML.cpp` we have this code:
>
>   IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
>   
>
> So, we write out the virtual address exactly as it is in the binary header file.  So why, when going the other direction, do we subtract the image base?  I don't have a strong preference on whether we store the VA or the RVA (I have a mild preference for storing the value exactly as it is in the object file), but whatever we do, yaml2obj and obj2yaml at least need to agree with other, right?


Yes, obviously. And right now, obj2yaml/coff2yaml.cpp does `NewYAMLSection.Header.VirtualAddress = ObjSection.getAddress();`, where `ObjSection.getAddress()` calls down to this:

  uint64_t COFFObjectFile::getSectionAddress(DataRefImpl Ref) const {
    const coff_section *Sec = toSec(Ref);
    uint64_t Result = Sec->VirtualAddress;
   
    // The section VirtualAddress does not include ImageBase, and we want to
    // return virtual addresses.
    Result += getImageBase();
    return Result;
  }

So just writing `NewYAMLSection.Header.VirtualAddress = COFFSection->VirtualAddress;` would fix this. That's why I'd like to know @majnemer's original intent.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54946/new/

https://reviews.llvm.org/D54946





More information about the llvm-commits mailing list