diff options
author | Jan Wen Voung <jvoung@google.com> | 2015-02-11 16:12:50 +0000 |
---|---|---|
committer | Jan Wen Voung <jvoung@google.com> | 2015-02-11 16:12:50 +0000 |
commit | c11b45a2ea0dc7cfb91f4e5565a2ebc6719c43bf (patch) | |
tree | 8d0308d16609a0904524b2e25fce8c4e90569125 /llvm/tools/gold/gold-plugin.cpp | |
parent | bf8d0cc699b171c72a8fe48c67431d0a2e0a3a5d (diff) | |
download | bcm5719-llvm-c11b45a2ea0dc7cfb91f4e5565a2ebc6719c43bf.tar.gz bcm5719-llvm-c11b45a2ea0dc7cfb91f4e5565a2ebc6719c43bf.zip |
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
llvm-svn: 228842
Diffstat (limited to 'llvm/tools/gold/gold-plugin.cpp')
-rw-r--r-- | llvm/tools/gold/gold-plugin.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp index 5d5db5a33a2..dd6d47f5d70 100644 --- a/llvm/tools/gold/gold-plugin.cpp +++ b/llvm/tools/gold/gold-plugin.cpp @@ -560,11 +560,9 @@ static void freeSymName(ld_plugin_symbol &Sym) { } static std::unique_ptr<Module> -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 @@ getModuleForFile(LLVMContext &Context, claimed_file &F, raw_fd_ostream *ApiFile, 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<std::unique_ptr<object::IRObjectFile>> ObjOrErr = object::IRObjectFile::create(BufferRef, Context); @@ -581,9 +579,6 @@ getModuleForFile(LLVMContext &Context, claimed_file &F, raw_fd_ostream *ApiFile, 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 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) { 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<Module> 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 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) { 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) { |