llvm.org GIT mirror llvm / b36941f
Merging r228842: ------------------------------------------------------------------------ r228842 | jvoung | 2015-02-11 08:12:50 -0800 (Wed, 11 Feb 2015) | 17 lines Gold-plugin: Broaden scope of get/release_input_file to scope of Module. Summary: Move calls to get_input_file and release_input_file out of getModuleForFile(). Otherwise release_input_file may end up unmapping a view of the file while the view is still being used by the Module (on 32-bit hosts). Fix for PR22482. Test Plan: Add test using --no-map-whole-files. Reviewers: rafael, nlewycky Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D7539 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@228942 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 4 years ago
2 changed file(s) with 19 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
0 ; RUN: llvm-as -o %t.bc %s
1 ; RUN: ld -plugin %llvmshlibdir/LLVMgold.so -plugin-opt=emit-llvm \
2 ; RUN: --no-map-whole-files -r -o %t2.bc %t.bc
3 ; RUN: llvm-dis < %t2.bc -o - | FileCheck %s
4
5 ; CHECK: main
6 define i32 @main() {
7 ret i32 0
8 }
558558 }
559559
560560 static std::unique_ptr
561 getModuleForFile(LLVMContext &Context, claimed_file &F, raw_fd_ostream *ApiFile,
561 getModuleForFile(LLVMContext &Context, claimed_file &F,
562 off_t Filesize, raw_fd_ostream *ApiFile,
562563 StringSet<> &Internalize, StringSet<> &Maybe) {
563 ld_plugin_input_file File;
564 if (get_input_file(F.handle, &File) != LDPS_OK)
565 message(LDPL_FATAL, "Failed to get file information");
566564
567565 if (get_symbols(F.handle, F.syms.size(), &F.syms[0]) != LDPS_OK)
568566 message(LDPL_FATAL, "Failed to get symbol information");
571569 if (get_view(F.handle, &View) != LDPS_OK)
572570 message(LDPL_FATAL, "Failed to get a view of file");
573571
574 MemoryBufferRef BufferRef(StringRef((const char *)View, File.filesize), "");
572 MemoryBufferRef BufferRef(StringRef((const char *)View, Filesize), "");
575573 ErrorOr> ObjOrErr =
576574 object::IRObjectFile::create(BufferRef, Context);
577575
578576 if (std::error_code EC = ObjOrErr.getError())
579577 message(LDPL_FATAL, "Could not read bitcode from file : %s",
580578 EC.message().c_str());
581
582 if (release_input_file(F.handle) != LDPS_OK)
583 message(LDPL_FATAL, "Failed to release file information");
584579
585580 object::IRObjectFile &Obj = **ObjOrErr;
586581
797792 StringSet<> Internalize;
798793 StringSet<> Maybe;
799794 for (claimed_file &F : Modules) {
795 ld_plugin_input_file File;
796 if (get_input_file(F.handle, &File) != LDPS_OK)
797 message(LDPL_FATAL, "Failed to get file information");
800798 std::unique_ptr M =
801 getModuleForFile(Context, F, ApiFile, Internalize, Maybe);
799 getModuleForFile(Context, F, File.filesize, ApiFile,
800 Internalize, Maybe);
802801 if (!options::triple.empty())
803802 M->setTargetTriple(options::triple.c_str());
804803 else if (M->getTargetTriple().empty()) {
807806
808807 if (L.linkInModule(M.get()))
809808 message(LDPL_FATAL, "Failed to link module");
809 if (release_input_file(F.handle) != LDPS_OK)
810 message(LDPL_FATAL, "Failed to release file information");
810811 }
811812
812813 for (const auto &Name : Internalize) {