[PATCH] D30588: [LTO] Add module asm uses to the llvm.compiler.used before merging

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 09:50:07 PST 2017


tejohnson added a comment.

In https://reviews.llvm.org/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 https://reviews.llvm.org/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 at 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



================
Comment at: test/LTO/X86/symver-asm.ll:2
 ; RUN: llvm-as < %s >%t1
-; RUN: llvm-lto -o %t2 %t1
+; RUN: llvm-lto -exported-symbol=io_cancel_0_4 -exported-symbol=io_cancel_weak_0_4 -o %t2 %t1
 ; RUN: llvm-nm %t2 | FileCheck %s
----------------
mehdi_amini wrote:
> The comment in the test below says " Even without -exported-symbol, io_cancel_0_4 should be noticed by LTOModule's" ?
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)


https://reviews.llvm.org/D30588





More information about the llvm-commits mailing list