[PATCH] Fix LTO handling of symbols in the .symver directive

Tom Roeder tmroeder at google.com
Thu Mar 27 15:41:45 PDT 2014

This patch fixes LTO's RecordStreamer so that it records symbols in the
MCExpr part of an asm .symver directive as being used. This prevents
referenced functions from being internalized and deleted.  This happens,
e.g., in libaio (http://lse.sourceforge.net/io/aio.html).

Without this patch, the attached test case will cause LLVM to produce the

LLVM ERROR: A @@ version cannot be undefined.

Please let me know what you think.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140327/4ddc5bf1/attachment.html>
-------------- next part --------------
diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp
index 7387416..998f4f9 100644
--- a/lib/LTO/LTOModule.cpp
+++ b/lib/LTO/LTOModule.cpp
@@ -658,6 +658,7 @@ namespace {
     void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override {
       // FIXME: should we handle aliases?
+      AddValueSymbols(Value);
     bool EmitSymbolAttribute(MCSymbol *Symbol,
                              MCSymbolAttr Attribute) override {
diff --git a/test/LTO/symver-asm.ll b/test/LTO/symver-asm.ll
new file mode 100644
index 0000000..03dda2b
--- /dev/null
+++ b/test/LTO/symver-asm.ll
@@ -0,0 +1,16 @@
+; RUN: llvm-as < %s >%t1
+; RUN: llvm-lto -o %t2 %t1
+; RUN: llvm-nm %t2 | FileCheck %s
+target triple = "x86_64-unknown-linux-gnu"
+module asm ".symver io_cancel_0_4,io_cancel@@LIBAIO_0.4"
+; Even without -exported-symbol, io_cancel_0_4 should be noticed by LTOModule's
+; RecordStreamer, so it shouldn't get eliminated. However, the object file will
+; contain the aliased symver as well as the original.
+define i32 @io_cancel_0_4() {
+; CHECK: io_cancel@@LIBAIO_0.4
+; CHECK: io_cancel_0_4
+  ret i32 0

More information about the llvm-commits mailing list