Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp =================================================================== --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -260,7 +260,11 @@ if (GV.hasLocalLinkage() && shouldPromoteLocalToGlobal(&GV, VI)) { // Save the original name string before we rename GV below. auto Name = GV.getName().str(); - GV.setName(getPromotedName(&GV)); + // With -funique-internal-linkage-names, local functions already get unique + // names. To avoid duplication, check if this suffix does not exist before + // uniqueifying the name. This will directly reduce .strtab size. + if (Name.find(".__uniq.") == std::string::npos) + GV.setName(getPromotedName(&GV)); GV.setLinkage(getLinkage(&GV, /* DoPromote */ true)); assert(!GV.hasLocalLinkage()); GV.setVisibility(GlobalValue::HiddenVisibility); Index: llvm/test/ThinLTO/X86/export.ll =================================================================== --- llvm/test/ThinLTO/X86/export.ll +++ llvm/test/ThinLTO/X86/export.ll @@ -7,6 +7,8 @@ ; RUN: llvm-lto -thinlto-action=promote %t1.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s ; CHECK-DAG: @staticvar.llvm.0 = hidden global ; CHECK-DAG: define hidden void @staticfunc.llvm.0 +; CHECK-DAG: define hidden void @uniqstaticfunc.__uniq.12345 +; CHECK-NOT: define hidden void @uniqstaticfunc.__uniq.12345.llvm. target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.11.0" @@ -16,6 +18,7 @@ define void @callstaticfunc() #0 { entry: call void @staticfunc() + call void @uniqstaticfunc.__uniq.12345() ret void } @@ -24,3 +27,9 @@ %0 = load i32, i32* @staticvar, align 4 ret void } + +define internal void @uniqstaticfunc.__uniq.12345() #0 { +entry: + %0 = load i32, i32* @staticvar, align 4 + ret void +}