[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:02:41 PST 2018


mstorsjo added a comment.

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

> 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?
>
>
> Also, in `coff2yaml.cpp` we have this code which initializes the above field:
>
>   const object::coff_section *COFFSection = Obj.getCOFFSection(ObjSection);
>   COFFYAML::Section NewYAMLSection;
>   ...
>   NewYAMLSection.Header.VirtualAddress = ObjSection.getAddress();
>   
>
> So, the value we print in the yaml is indeed the exact value from the object file.  If we change one but not the other, then it will regress the ability of object files to round-trip through yaml.


Roundtripping executables is broken right now, which this patch fixes. Object files are unaffected by this patch. Just try it out for yourself.


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