This is an archive of the discontinued LLVM Phabricator instance.

[cfi] Fix weak functions handling.
ClosedPublic

Authored by eugenis on Oct 27 2016, 3:31 PM.

Details

Reviewers
pcc
Summary

When a function pointer is replaced with a jumptable pointer, special
case is needed to preserve the semantics of extern_weak functions.
Since a jumptable entry can not be extern_weak, we emulate that
behaviour by replacing all references to F (the extern_weak function)
with the following expression: F != nullptr ? JumpTablePtr : nullptr.

Extra special care is needed for global initializers, since most (or
probably all) backends can not lower an initializer that includes
this kind of constant expression. Initializers like that are replaced
with a global constructor (i.e. a runtime initializer).

Diff Detail

Repository
rL LLVM

Event Timeline

eugenis updated this revision to Diff 76116.Oct 27 2016, 3:31 PM
eugenis retitled this revision from to [cfi] Fix weak functions handling..
eugenis updated this object.
eugenis added a reviewer: pcc.
eugenis set the repository for this revision to rL LLVM.
eugenis added a subscriber: llvm-commits.
eugenis added inline comments.Oct 27 2016, 3:39 PM
lib/Transforms/IPO/LowerTypeTests.cpp
757

I wonder if the priority should be lower. Regular constructors have priority of 65535, we definitely want higher than that, but maybe lower than ASan, etc constructors which use 1 and 2 currently.

pcc added inline comments.Oct 27 2016, 3:43 PM
lib/Transforms/IPO/LowerTypeTests.cpp
757

I think this constructor is equivalent to relocation application so it should run as close to that as possible, i.e. it should have the highest priority.

Please document the reasons for our choice of priority.

774

What if the use is an element of an aggregate that initializes a GlobalVariable?

eugenis added inline comments.Oct 27 2016, 3:53 PM
lib/Transforms/IPO/LowerTypeTests.cpp
774

Good point. There are also other expressions that are sometimes (always?) allowed in a global initializers, like (char*)f + 42.

eugenis updated this revision to Diff 76125.Oct 27 2016, 4:17 PM
eugenis marked 4 inline comments as done.

PTAL

pcc added inline comments.Oct 27 2016, 4:21 PM
lib/Transforms/IPO/LowerTypeTests.cpp
773

Is this correctly handling the case where an initializer contains multiple references to a weak undef?

eugenis updated this revision to Diff 76126.Oct 27 2016, 4:30 PM
eugenis added inline comments.
lib/Transforms/IPO/LowerTypeTests.cpp
773

another good point!

pcc accepted this revision.Oct 27 2016, 5:03 PM
pcc edited edge metadata.

LGTM with nits

lib/Transforms/IPO/LowerTypeTests.cpp
766

Nit: could be GV->getValueType().

1085

Nit: this could be an in-class initializer.

This revision is now accepted and ready to land.Oct 27 2016, 5:03 PM
eugenis updated this revision to Diff 76140.Oct 27 2016, 5:14 PM
eugenis edited edge metadata.
eugenis marked 2 inline comments as done.
pcc added inline comments.Oct 27 2016, 5:16 PM
lib/Transforms/IPO/LowerTypeTests.cpp
1085

I meant that you could write Function *WeakInitializerFn = nullptr; in the class definition

eugenis updated this revision to Diff 76142.Oct 27 2016, 5:18 PM
eugenis marked an inline comment as done.Nov 11 2016, 1:42 PM
pcc added a comment.Nov 11 2016, 1:44 PM

still LGTM

eugenis closed this revision.Nov 28 2016, 1:32 PM

r286636
thanks for the review!