2021-09-08 13:02:38 +03:00
|
|
|
#include "elf/mold.h"
|
|
|
|
#include "macho/mold.h"
|
|
|
|
|
2021-09-13 12:15:34 +03:00
|
|
|
#include <cstring>
|
2021-09-15 09:25:14 +03:00
|
|
|
#include <signal.h>
|
2021-09-13 12:15:34 +03:00
|
|
|
|
|
|
|
namespace mold {
|
|
|
|
|
2021-09-28 10:10:33 +03:00
|
|
|
std::string_view errno_string() {
|
|
|
|
static thread_local char buf[200];
|
2021-09-13 12:15:34 +03:00
|
|
|
strerror_r(errno, buf, sizeof(buf));
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2021-09-28 10:40:05 +03:00
|
|
|
const std::string mold_version =
|
|
|
|
#ifdef GIT_HASH
|
|
|
|
"mold " MOLD_VERSION " (" GIT_HASH "; compatible with GNU ld and GNU gold)";
|
|
|
|
#else
|
|
|
|
"mold " MOLD_VERSION " (compatible with GNU ld and GNU gold)";
|
|
|
|
#endif
|
2021-09-13 12:15:34 +03:00
|
|
|
|
2021-09-15 09:25:14 +03:00
|
|
|
void cleanup() {
|
|
|
|
if (output_tmpfile)
|
|
|
|
unlink(output_tmpfile);
|
|
|
|
if (socket_tmpfile)
|
|
|
|
unlink(socket_tmpfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void signal_handler(int) {
|
|
|
|
cleanup();
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void install_signal_handler() {
|
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
}
|
|
|
|
|
2021-09-13 12:15:34 +03:00
|
|
|
} // namespace mold
|
|
|
|
|
2021-09-08 13:02:38 +03:00
|
|
|
int main(int argc, char **argv) {
|
2021-09-08 13:49:51 +03:00
|
|
|
std::string_view cmd = mold::path_filename(argv[0]);
|
2021-09-08 13:02:38 +03:00
|
|
|
|
|
|
|
if (cmd == "ld" || cmd == "mold" || cmd == "ld.mold")
|
2021-09-08 14:15:03 +03:00
|
|
|
return mold::elf::main(argc, argv);
|
|
|
|
|
2021-09-08 13:02:38 +03:00
|
|
|
if (cmd == "ld64" || cmd == "ld64.mold")
|
2021-09-08 14:15:03 +03:00
|
|
|
return mold::macho::main(argc, argv);
|
2021-09-08 13:02:38 +03:00
|
|
|
|
|
|
|
std::cerr << "mold: unknown command: " << argv[0] << "\n";
|
|
|
|
exit(1);
|
|
|
|
}
|