Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -896,7 +896,6 @@ } static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, - std::unique_ptr OS, std::string SampleProfile) { StringMap> ModuleToDefinedGVSummaries; @@ -944,13 +943,11 @@ OwnedImports.push_back(std::move(*MBOrErr)); } - auto AddStream = [&](size_t Task) { - return llvm::make_unique(std::move(OS)); - }; lto::Config Conf; Conf.SampleProfile = SampleProfile; + Conf.SkipCodeGen = true; if (Error E = thinBackend( - Conf, 0, AddStream, *M, *CombinedIndex, ImportList, + Conf, 0, nullptr, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { errs() << "Error running ThinLTO backend: " << EIB.message() << '\n'; @@ -983,11 +980,8 @@ // (LLVM will optionally ignore empty index files, returning null instead // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; - if (DoThinLTOBackend) { - runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), - CGOpts.SampleProfileFile); - return; - } + if (DoThinLTOBackend) + runThinLTOBackend(CombinedIndex.get(), M, CGOpts.SampleProfileFile); } EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M); Index: test/CodeGen/function-sections.c =================================================================== --- test/CodeGen/function-sections.c +++ test/CodeGen/function-sections.c @@ -9,6 +9,12 @@ // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fdata-sections -o - < %s | FileCheck %s --check-prefix=DATA_SECT // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fno-data-sections -fdata-sections -o - < %s | FileCheck %s --check-prefix=DATA_SECT +// Try again through a clang invocation of the ThinLTO backend. +// RUN: %clang -O2 %s -flto=thin -c -o %t.o +// RUN: llvm-lto -thinlto -o %t %t.o +// RUN: %clang -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -S -ffunction-sections -o - | FileCheck %s --check-prefix=FUNC_SECT +// RUN: %clang -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -S -fdata-sections -o - | FileCheck %s --check-prefix=DATA_SECT + const int hello = 123; void world() {} @@ -22,7 +28,7 @@ // FUNC_SECT: section .rodata, // FUNC_SECT: hello: -// DATA_SECT-NOT: section +// DATA_SECT-NOT: .section // DATA_SECT: world: // DATA_SECT: .section .rodata.hello, // DATA_SECT: hello: