This is an archive of the discontinued LLVM Phabricator instance.

Fix mapping of unmaterialized global values during metadata linking
ClosedPublic

Authored by tejohnson on Nov 14 2015, 11:59 AM.

Details

Summary

The patch to move metadata linking after global value linking didn't
correctly map unmaterialized global values to null as desired. They
were in fact mapped to the source copy. It largely worked by accident
since most module linker clients destroyed the source module which
caused the source GVs to be replaced by null, but caused a failure with
LTO linking on Windows:
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/312869.html

The problem is that a null return value from materializeValueFor is
handled by mapping the value to self. This is the desired behavior when
materializeValueFor is passed a non-GlobalValue. The problem is how to
distinguish that case from the case where we really do want to map to
null.

This patch addresses this by passing in a new flag to the value mapper
indicating that unmapped global values should be mapped to null. Other
Value types are handled as before.

Note that the documented behavior of asserting on unmapped values when
the flag RF_IgnoreMissingValues isn't set is currently disabled with
FIXME notes due to bootstrap failures. I modified these disabled asserts
so when they are eventually enabled again it won't assert for the
unmapped values when the new RF_NullMapMissingGlobalValues flag is set.

I also considered using a callback into the value materializer, but a
flag seemed cleaner given that there are already existing flags.
I also considered modifying materializeValueFor to return the input
value when we want to map to source and then treat a null return
to mean map to null. However, there are other value materializer
subclasses that implement materializeValueFor, and they would all need
to be audited and the return values possibly changed, which seemed
error-prone.

Diff Detail

Repository
rL LLVM

Event Timeline

tejohnson updated this revision to Diff 40215.Nov 14 2015, 11:59 AM
tejohnson retitled this revision from to Fix mapping of unmaterialized global values during metadata linking.
tejohnson updated this object.
tejohnson added reviewers: dexonsmith, mehdi_amini.
tejohnson added subscribers: llvm-commits, pcc.
mehdi_amini accepted this revision.Nov 14 2015, 5:21 PM
mehdi_amini edited edge metadata.
mehdi_amini added inline comments.
include/llvm/Transforms/Utils/ValueMapper.h
73 ↗(On Diff #40215)

No need to repeat RF_NullMapMissingGlobalValues in the doxygen.

lib/Transforms/Utils/ValueMapper.cpp
47 ↗(On Diff #40215)

A string with the assert is usually more user friendly.

This revision is now accepted and ready to land.Nov 14 2015, 5:21 PM
tejohnson marked 2 inline comments as done.Nov 15 2015, 6:50 AM

Thanks, comments addressed.

This revision was automatically updated to reflect the committed changes.