Skip to content

Commit

Permalink
increase file limit when hit the ulimit
Browse files Browse the repository at this point in the history
  • Loading branch information
karuboniru committed Oct 21, 2024
1 parent 0841ffc commit e056d88
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/mapped-file-unix.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#include "common.h"

// for getrlimit, setrlimit
#include <sys/resource.h>

namespace mold {

MappedFile *open_file_impl(const std::string &path, std::string &error) {
i64 fd = ::open(path.c_str(), O_RDONLY);
// increase rlimit when EMFILE. This is required for llvm lto, since llvm
// plugin requires keeping input files open
if (fd == -1 && errno == EMFILE) {
if (struct rlimit rlim{}; getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
rlim.rlim_cur = rlim.rlim_max;
setrlimit(RLIMIT_NOFILE, &rlim);
fd = ::open(path.c_str(), O_RDONLY);
}
}
if (fd == -1) {
if (errno != ENOENT)
error = "opening " + path + " failed: " + errno_string();
Expand Down

0 comments on commit e056d88

Please sign in to comment.