[PATCH] D17971: [lto] Don't add variables with private linkage to the symbol table.

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 8 15:06:39 PST 2016


silvas created this revision.
silvas added a reviewer: rafael.
silvas added subscribers: llvm-commits, Bigcheese.
Herald added a subscriber: joker.eph.

Do we need any other special handling for these?

This causes the issue in PR26872 to go away now that we aren't creating
symbols for the string literals, but that may just be concealing a
deeper problem, so best to keep that PR open.

In my testing, it seems that InternalLinkage also needs to be added to
this `if` condition (to avoid duplicate symbol errors for C/C++
"static") and also AppendingLinkage (to avoid duplicate symbols for
llvm.global_ctors).
Those will be in separate patches though.

http://reviews.llvm.org/D17971

Files:
  ELF/InputFiles.cpp
  test/ELF/lto/Inputs/linkage.ll
  test/ELF/lto/linkage.ll

Index: test/ELF/lto/linkage.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/linkage.ll
@@ -0,0 +1,11 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %t1.o
+; RUN: llvm-as %p/Inputs/linkage.ll -o %t2.o
+; RUN: ld.lld -m elf_x86_64 %t1.o %t2.o -o %t.so -shared
+
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Should not encounter a duplicate symbol error for @.str
+ at .str = private unnamed_addr constant [4 x i8] c"Hey\00", align 1
Index: test/ELF/lto/Inputs/linkage.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/Inputs/linkage.ll
@@ -0,0 +1,4 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at .str = private unnamed_addr constant [4 x i8] c"Hey\00", align 1
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -444,6 +444,8 @@
       if (const Comdat *C = GV->getComdat())
         if (!KeptComdats.count(C))
           continue;
+      if (GV->getLinkage() == GlobalValue::PrivateLinkage)
+        continue;
       Visibility = getGvVisibility(GV);
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17971.50076.patch
Type: text/x-patch
Size: 1281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160308/3f12fc0e/attachment.bin>


More information about the llvm-commits mailing list