Page MenuHomePhabricator

[CodeGen][ObjC] Emit the retainRV marker as a module flag instead of named metadata.
ClosedPublic

Authored by ahatanak on Apr 4 2019, 7:02 PM.

Details

Summary

This fixes a bug which causes the ARC contract pass to not insert the assembly marker that is needed for the runtime to do the objc_autoreleaseReturnValue/ objc_retainAutoreleasedReturnValue optimization when compiling on ARM64/ARM with LTO enabled. This happens because IRLinker::linkNamedMDNodes() adds all the operands from the source modules to the metadata's operand list in the merged module (see the example below) and ARC contract fails to extract the marker string if the metadata has more than one operand.

clang.arc.retainAutoreleasedReturnValueMarker = !{!0, !0}
!0 = !{!"mov\09fp, fp\09\09# marker for objc_retainAutoreleaseReturnValue"}

To fix the bug, this patch emits the marker as a module flag.

rdar://problem/49464214

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak created this revision.Apr 4 2019, 7:02 PM

Corresponding llvm patch is here: https://reviews.llvm.org/D60303.

I talked with Akira offline and we think this is probably the best approach to fix this LTO issue. I will leave others to comment if they think otherwise.

Will the ARC-contract pass recognize both, or are you adding a BC upgrader that rewrites the global metadata into a module flag?

The upgrader rewrites the named metadata into a module flag (see https://reviews.llvm.org/D60303).

rjmccall accepted this revision.Apr 9 2019, 12:59 PM

Okay. In that case, I have no objections to this.

This revision is now accepted and ready to land.Apr 9 2019, 12:59 PM

Thanks. Does this require changes to swift too?

Thanks. Does this require changes to swift too?

Yes, it will, to getObjCRetainAutoreleasedReturnValueMarker in GenObjC.cpp.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2019, 11:18 PM