[PATCH] D55237: LTO: Don't internalize available_externally globals.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 3 15:28:46 PST 2018


pcc created this revision.
pcc added a reviewer: tejohnson.
Herald added subscribers: dang, dexonsmith, steven_wu, hiraditya, inglorion, mehdi_amini.

This breaks C and C++ semantics because it can cause the address
of the global inside the module to differ from the address outside
of the module.


Repository:
  rL LLVM

https://reviews.llvm.org/D55237

Files:
  llvm/lib/LTO/LTO.cpp
  llvm/test/LTO/Resolution/X86/available-externally.ll


Index: llvm/test/LTO/Resolution/X86/available-externally.ll
===================================================================
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/available-externally.ll
@@ -0,0 +1,16 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar, -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+
+; CHECK: U bar
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void ()* @foo() {
+  ret void ()* @bar
+}
+
+define available_externally void @bar() {
+  ret void
+}
Index: llvm/lib/LTO/LTO.cpp
===================================================================
--- llvm/lib/LTO/LTO.cpp
+++ llvm/lib/LTO/LTO.cpp
@@ -359,7 +359,8 @@
                // Ignore local and appending linkage values since the linker
                // doesn't resolve them.
                !GlobalValue::isLocalLinkage(S->linkage()) &&
-               !GlobalValue::isAppendingLinkage(S->linkage()))
+               !GlobalValue::isAppendingLinkage(S->linkage()) &&
+               S->linkage() != GlobalValue::AvailableExternallyLinkage)
       S->setLinkage(GlobalValue::InternalLinkage);
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55237.176495.patch
Type: text/x-patch
Size: 1205 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181203/e1455c17/attachment.bin>


More information about the llvm-commits mailing list