Index: llvm/trunk/test/tools/gold/no-map-whole-file.ll =================================================================== --- llvm/trunk/test/tools/gold/no-map-whole-file.ll +++ llvm/trunk/test/tools/gold/no-map-whole-file.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as -o %t.bc %s +; RUN: ld -plugin %llvmshlibdir/LLVMgold.so -plugin-opt=emit-llvm \ +; RUN: --no-map-whole-files -r -o %t2.bc %t.bc +; RUN: llvm-dis < %t2.bc -o - | FileCheck %s + +; CHECK: main +define i32 @main() { + ret i32 0 +} Index: llvm/trunk/tools/gold/gold-plugin.cpp =================================================================== --- llvm/trunk/tools/gold/gold-plugin.cpp +++ llvm/trunk/tools/gold/gold-plugin.cpp @@ -560,11 +560,9 @@ } static std::unique_ptr -getModuleForFile(LLVMContext &Context, claimed_file &F, raw_fd_ostream *ApiFile, +getModuleForFile(LLVMContext &Context, claimed_file &F, + off_t Filesize, raw_fd_ostream *ApiFile, StringSet<> &Internalize, StringSet<> &Maybe) { - ld_plugin_input_file File; - if (get_input_file(F.handle, &File) != LDPS_OK) - message(LDPL_FATAL, "Failed to get file information"); if (get_symbols(F.handle, F.syms.size(), &F.syms[0]) != LDPS_OK) message(LDPL_FATAL, "Failed to get symbol information"); @@ -573,7 +571,7 @@ if (get_view(F.handle, &View) != LDPS_OK) message(LDPL_FATAL, "Failed to get a view of file"); - MemoryBufferRef BufferRef(StringRef((const char *)View, File.filesize), ""); + MemoryBufferRef BufferRef(StringRef((const char *)View, Filesize), ""); ErrorOr> ObjOrErr = object::IRObjectFile::create(BufferRef, Context); @@ -581,9 +579,6 @@ message(LDPL_FATAL, "Could not read bitcode from file : %s", EC.message().c_str()); - if (release_input_file(F.handle) != LDPS_OK) - message(LDPL_FATAL, "Failed to release file information"); - object::IRObjectFile &Obj = **ObjOrErr; Module &M = Obj.getModule(); @@ -802,8 +797,12 @@ StringSet<> Internalize; StringSet<> Maybe; for (claimed_file &F : Modules) { + ld_plugin_input_file File; + if (get_input_file(F.handle, &File) != LDPS_OK) + message(LDPL_FATAL, "Failed to get file information"); std::unique_ptr M = - getModuleForFile(Context, F, ApiFile, Internalize, Maybe); + getModuleForFile(Context, F, File.filesize, ApiFile, + Internalize, Maybe); if (!options::triple.empty()) M->setTargetTriple(options::triple.c_str()); else if (M->getTargetTriple().empty()) { @@ -812,6 +811,8 @@ if (L.linkInModule(M.get())) message(LDPL_FATAL, "Failed to link module"); + if (release_input_file(F.handle) != LDPS_OK) + message(LDPL_FATAL, "Failed to release file information"); } for (const auto &Name : Internalize) {