Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading