From bfdad33b82b9ac535b33b2783870dffe3bd401f3 Mon Sep 17 00:00:00 2001 From: Xin Tong Date: Mon, 8 Oct 2018 15:12:48 +0000 Subject: [PATCH] [ThinLTO] Keep non-prevailing (linkonce|weak)_odr symbols live Summary: If we have a symbol with (linkonce|weak)_odr linkage, we do not want to dead strip it even it is not prevailing. IR level (linkonce|weak)_odr symbol can become non-prevailing when we mix ELF objects and IR objects where the (linkonce|weak)_odr symbol in the ELF object is prevailing and the ones in the IR objects are not. Stripping them will prevent us from doing optimizations with them. By not dead stripping them, We will convert these symbols to available_externally linkage as a result of non-prevailing and eventually dropping them after inlining. I modified cache-prevailing.ll to use linkonce linkage as it is testing whether cache prevailing bit is effective or not, not we should treat linkonce_odr alive or not Reviewers: tejohnson, pcc Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D52893 llvm-svn: 343970 --- llvm/lib/Transforms/IPO/FunctionImport.cpp | 20 ++++++++++++-------- llvm/test/LTO/Resolution/X86/cache-prevailing.ll | 2 +- llvm/test/ThinLTO/X86/deadstrip.ll | 19 +++++++++++++++++++ .../test/Transforms/FunctionImport/not-prevailing.ll | 2 +- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index bc1bbcb..8f8c85e 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -741,24 +741,28 @@ void llvm::computeDeadSymbols( return; // We only keep live symbols that are known to be non-prevailing if any are - // available_externally. Those symbols are discarded later in the - // EliminateAvailableExternally pass and setting them to not-live breaks - // downstreams users of liveness information (PR36483). + // available_externally, linkonceodr, weakodr. Those symbols are discarded + // later in the EliminateAvailableExternally pass and setting them to + // not-live could break downstreams users of liveness information (PR36483) + // or limit optimization opportunities. if (isPrevailing(VI.getGUID()) == PrevailingType::No) { - bool AvailableExternally = false; + bool KeepAliveLinkage = false; bool Interposable = false; for (auto &S : VI.getSummaryList()) { - if (S->linkage() == GlobalValue::AvailableExternallyLinkage) - AvailableExternally = true; + if (S->linkage() == GlobalValue::AvailableExternallyLinkage || + S->linkage() == GlobalValue::WeakODRLinkage || + S->linkage() == GlobalValue::LinkOnceODRLinkage) + KeepAliveLinkage = true; else if (GlobalValue::isInterposableLinkage(S->linkage())) Interposable = true; } - if (!AvailableExternally) + if (!KeepAliveLinkage) return; if (Interposable) - report_fatal_error("Interposable and available_externally symbol"); + report_fatal_error( + "Interposable and available_externally/linkonce_odr/weak_odr symbol"); } for (auto &S : VI.getSummaryList()) diff --git a/llvm/test/LTO/Resolution/X86/cache-prevailing.ll b/llvm/test/LTO/Resolution/X86/cache-prevailing.ll index 390e366..5768749 100644 --- a/llvm/test/LTO/Resolution/X86/cache-prevailing.ll +++ b/llvm/test/LTO/Resolution/X86/cache-prevailing.ll @@ -10,7 +10,7 @@ target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-pc-windows-msvc19.11.0" -@foo = linkonce_odr constant i32 1, comdat +@foo = linkonce constant i32 1, comdat $foo = comdat any define i32* @bar() { diff --git a/llvm/test/ThinLTO/X86/deadstrip.ll b/llvm/test/ThinLTO/X86/deadstrip.ll index d96d45d..3da7213 100644 --- a/llvm/test/ThinLTO/X86/deadstrip.ll +++ b/llvm/test/ThinLTO/X86/deadstrip.ll @@ -18,6 +18,8 @@ ; RUN: -r %t1.bc,_baz,l \ ; RUN: -r %t1.bc,_boo,l \ ; RUN: -r %t1.bc,_live_available_externally_func,l \ +; RUN: -r %t1.bc,_live_linkonce_odr_func,l \ +; RUN: -r %t1.bc,_live_weak_odr_func,l \ ; RUN: -r %t2.bc,_baz,pl \ ; RUN: -r %t2.bc,_boo,pl \ ; RUN: -r %t2.bc,_dead_func,l \ @@ -33,12 +35,16 @@ ; COMBINED-DAG: &1 | FileCheck %s -; CHECK: Interposable and available_externally symbol +; CHECK: Interposable and available_externally/linkonce_odr/weak_odr symbol target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" -- 2.7.4