Skip to content

Commit e056d88

Browse files
committed
increase file limit when hit the ulimit
1 parent 0841ffc commit e056d88

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/mapped-file-unix.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
#include "common.h"
22

3+
// for getrlimit, setrlimit
4+
#include <sys/resource.h>
5+
36
namespace mold {
47

58
MappedFile *open_file_impl(const std::string &path, std::string &error) {
69
i64 fd = ::open(path.c_str(), O_RDONLY);
10+
// increase rlimit when EMFILE. This is required for llvm lto, since llvm
11+
// plugin requires keeping input files open
12+
if (fd == -1 && errno == EMFILE) {
13+
if (struct rlimit rlim{}; getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
14+
rlim.rlim_cur = rlim.rlim_max;
15+
setrlimit(RLIMIT_NOFILE, &rlim);
16+
fd = ::open(path.c_str(), O_RDONLY);
17+
}
18+
}
719
if (fd == -1) {
820
if (errno != ENOENT)
921
error = "opening " + path + " failed: " + errno_string();

0 commit comments

Comments
 (0)