This is an archive of the discontinued LLVM Phabricator instance.

Prevent GlobalOpts from dropping ASANitized global variables
Needs RevisionPublic

Authored by aprantl on Mar 11 2016, 4:18 PM.

Details

Summary

ASAN transforms global variables into an array with extra storage at the end and RAUWs the global value with a GEP into the array. GlobalOpts will think that the GEP constexpr is dead because its only use is a Metadata node and eliminate it, thus dropping the storage from the debug info.
This patch fixes this by adding a flag to Constant::removeDeadConstantUsers() to optionally ignore metadata users.

Diff Detail

Event Timeline

aprantl updated this revision to Diff 50480.Mar 11 2016, 4:18 PM
aprantl retitled this revision from to Prevent GlobalOpts from dropping ASANitized global variables.
aprantl updated this object.
aprantl set the repository for this revision to rL LLVM.
aprantl added a subscriber: llvm-commits.
dexonsmith edited edge metadata.Mar 11 2016, 4:52 PM
dexonsmith added a subscriber: dexonsmith.

Ugh, this is ugly. We should really start using a !dbg attachment on
global variables, much like we changed functions. Then ASan can update
the attachment (if necessary), and we don't rely on RAUW to get things
right. (I'm not sure that needs to happen before we fix this bug.)

Comments inline.

aprantl updated this revision to Diff 50762.Mar 15 2016, 1:01 PM
aprantl edited edge metadata.
aprantl removed rL LLVM as the repository for this revision.

Prevent the new behavior from affecting code generation.

I added a check to catch the case where the GV is only kept alive by a constant that is only kept alive by metadata.

I'm concerned that fixing up GlobalOpt::deleteIfDead isn't enough
to avoid affecting CodeGen. There are other places in the
pipeline that will check Value::use_empty and/or have logic like
(or use directly) Function::isDefTriviallyDead. I think it's
important that the call to GV.removeDeadConstantUsers() has the
same effect on use-lists whether or not there's any debug info.
Moreover, GlobalOpt::deleteIfDead should have the same effect on
the entire module (including use-lists) regardless of debug info.

(But in case you can convince me, more comments below.)

aprantl abandoned this revision.Mar 15 2016, 2:02 PM

Alright, I'm not sure if I want to invest any more time in this patch. I will investigate how much work it is to reverse the pointers between CU and global variables next.

aprantl updated this revision to Diff 56453.May 6 2016, 1:28 PM

Attaching a WIP patch for reversing the ownership between DIGlobalVariable and GlobalVariable.

dexonsmith requested changes to this revision.Oct 19 2020, 11:05 AM

Attaching a WIP patch for reversing the ownership between DIGlobalVariable and GlobalVariable.

"Requesting changes" as I assume this at least needs to be rebased, but I still think it's a good direction. Is the a reason this wasn't pursued further?

This revision now requires changes to proceed.Oct 19 2020, 11:05 AM