This is an archive of the discontinued LLVM Phabricator instance.

[LTO] Add module asm uses to the llvm.compiler.used before merging
AbandonedPublic

Authored by tejohnson on Mar 3 2017, 1:06 PM.

Details

Reviewers
pcc
rafael
Summary

In LTO mode we were adding undefined module asm uses to the
llvm.compiler.used eventually, but not early enough. The referenced
internal symbol was simply not being linked into the combined module
since it didn't appear referenced.

Fixes PR25679.

Depends on D30585

Event Timeline

tejohnson created this revision.Mar 3 2017, 1:06 PM
pcc edited edge metadata.Mar 6 2017, 2:38 PM

Will your test case work without LTO? I'd expect the user to have to use __attribute((used)) to prevent the io_cancel_local_0_4 symbol from being DCE'd.

mehdi_amini added inline comments.Mar 6 2017, 3:39 PM
test/LTO/X86/symver-asm.ll
2

The comment in the test below says " Even without -exported-symbol, io_cancel_0_4 should be noticed by LTOModule's" ?

In D30588#693713, @pcc wrote:

Will your test case work without LTO? I'd expect the user to have to use __attribute((used)) to prevent the io_cancel_local_0_4 symbol from being DCE'd.

I tried it with "opt -O2" and indeed the local symbol is removed. However, there is existing handling in the LTO path for this case of having uses in the module asm that are not (yet) on the llvm.compiler.used. As noted we are already adding these referenced symbols to the llvm.compiler.used in both the old and new LTO APIs, just later on. I looked back at the history of this. The handling in the new LTO API was added with D24617. This would have made the new LTO API consistent with the old LTO API. Chasing through the history of where this was added in libLTO, I found this old commit that added it. Note the comment "The second improvement..." which refers to this. So at least on the LTO path, there doesn't seem to be an expectation that these were already added to the llvm.compiler.used.

commit 38c4e535493363b96eac47af9e7c056530137bea
Author: Rafael Espindola <rafael.espindola@gmail.com>
Date: Wed Mar 2 04:14:42 2011 +0000

Add a special streamer to libLTO that just records symbols definitions and
uses.

The result produced by the streamer is used to give the linker more accurate
information and to add to llvm.compiler.used. The second improvement removes
the need for the user to add __attribute__((used)) to functions only used in
inline asm. The first one lets us build firefox with LTO on Darwin :-)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126830 91177308-0d34-0410-b5e6-96231b3b80d8
test/LTO/X86/symver-asm.ll
2

It is noticed and kept, but internalized. I wanted to ensure that we get the desired global binding for the versioned alias, so I had to make it exported here. Notice that before we were only checking for the presence of the io_cancel* symbols in the nm output, not looking at their symbol binding. I will remove the comment below which is now stale. (Also the second -exported-symbol above crept in from another version of the test, I will remove it)

tejohnson updated this revision to Diff 90871.Mar 7 2017, 9:55 AM

Update test per review.

*internal* functions referenced from ASM need to be in llvm.compiler.used, regular global functions don't.

*internal* functions referenced from ASM need to be in llvm.compiler.used, regular global functions don't.

Confirmed - I had forgotten that distinction. This change is no longer required then. I will update the follow-on fixes to include the llvm.compiler.used for the local.

tejohnson abandoned this revision.Mar 7 2017, 10:19 AM