This is an archive of the discontinued LLVM Phabricator instance.

[asan] Print VAs instead of RVAs for module offsets on Windows
ClosedPublic

Authored by rnk on Jul 31 2015, 10:33 AM.

Details

Summary

This is consistent with binutils and ASan behavior on other platforms,
and makes it easier to use llvm-symbolizer with WinASan.

An RVA is a "relative virtual address", meaning it is the address of
something inside the image minus the base of the mapping at runtime.

A VA in this context is an RVA plus the "preferred base" of the module,
and not a real runtime address. The real runtime address of a symbol
will equal the VA iff the module is loaded at its preferred base at
runtime.

On Windows, the preferred base is stored in the ImageBase field of one
of the PE file header, and this change adds the necessary code to
extract it. On Linux, this offset is typically included in program and
section headers of executables.

ELF shared objects typically use a preferred base of zero, meaning the
smallest p_vaddr field in the program headers is zero. This makes it so
that PIC and PIE module offsets come out looking like RVAs, but they're
actually VAs. The difference between them simply happens to be zero.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk updated this revision to Diff 31133.Jul 31 2015, 10:33 AM
rnk retitled this revision from to [asan] Print VAs instead of RVAs for module offsets on Windows.
rnk updated this object.
rnk added reviewers: samsonov, majnemer.
rnk added a subscriber: llvm-commits.
samsonov edited edge metadata.Jul 31 2015, 1:40 PM

LGTM. I'm slightly worried about existing clients who might depend on ASan stack traces containing RVAs. Does it mean that they should just drop "--relative-address" flag from their llvm-symbolizer.exe invocation? If yes, please specify this in the commit message.

lib/sanitizer_common/sanitizer_win.cc
328 ↗(On Diff #31133)

You can probably move this to sanitizer_common.h

340 ↗(On Diff #31133)

const char *modname

372 ↗(On Diff #31133)

internal_memcmp

421 ↗(On Diff #31133)

I'd vote for kMaxPathLength, but I see that MAX_PATH is already used in several places for Windows.

503 ↗(On Diff #31133)

Keep error_p to be consistent with function decl?

samsonov accepted this revision.Jul 31 2015, 1:40 PM
samsonov edited edge metadata.
This revision is now accepted and ready to land.Jul 31 2015, 1:40 PM
rnk marked 5 inline comments as done.Aug 3 2015, 11:24 AM

LGTM. I'm slightly worried about existing clients who might depend on ASan stack traces containing RVAs. Does it mean that they should just drop "--relative-address" flag from their llvm-symbolizer.exe invocation? If yes, please specify this in the commit message.

Sure. I think Chromium clusterfuzz is the only client of this flag, and I'll talk to them when I look at rolling clang.

rnk added a comment.Aug 3 2015, 12:52 PM

LGTM. I'm slightly worried about existing clients who might depend on ASan stack traces containing RVAs. Does it mean that they should just drop "--relative-address" flag from their llvm-symbolizer.exe invocation? If yes, please specify this in the commit message.

Sure. I think Chromium clusterfuzz is the only client of this flag, and I'll talk to them when I look at rolling clang.

This revision was automatically updated to reflect the committed changes.