diff --git a/icf.cc b/icf.cc index e9e6e7ef..60909bc8 100644 --- a/icf.cc +++ b/icf.cc @@ -55,7 +55,6 @@ #include "mold.h" #include -#include #include #include #include @@ -63,6 +62,13 @@ #include #include +#ifdef __APPLE__ +# define COMMON_DIGEST_FOR_OPENSSL +# include +#else +# include +#endif + static constexpr i64 HASH_SIZE = 16; typedef std::array Digest; diff --git a/memory-mapped-file.cc b/memory-mapped-file.cc index 92b407c2..44b1cbb1 100644 --- a/memory-mapped-file.cc +++ b/memory-mapped-file.cc @@ -14,7 +14,13 @@ MemoryMappedFile::open(Context &ctx, std::string path) { struct stat st; if (stat(path.c_str(), &st) == -1) return nullptr; - u64 mtime = (u64)st.st_mtim.tv_sec * 1000000000 + st.st_mtim.tv_nsec; + + u64 mtime; +#ifdef __APPLE__ + mtime = (u64)st.st_mtimespec.tv_sec * 1000000000 + st.st_mtimespec.tv_nsec; +#else + mtime = (u64)st.st_mtim.tv_sec * 1000000000 + st.st_mtim.tv_nsec; +#endif u8 *data = nullptr; if (st.st_size == 0) { diff --git a/mold-wrapper.c b/mold-wrapper.c index 058c5457..7bd1394e 100644 --- a/mold-wrapper.c +++ b/mold-wrapper.c @@ -49,6 +49,21 @@ static bool is_ld(const char *path) { !strcmp(ptr, "ld.gold"); } +int execvpe(const char *file, char *const *argv, char *const *envp) { + debug_print("execvpe %s\n", file); + + if (!strcmp(file, "ld") || is_ld(file)) { + file = get_mold_path(); + ((const char **)argv)[0] = file; + } + + for (int i = 0; envp[i]; i++) + putenv(envp[i]); + + typeof(execvpe) *real = dlsym(RTLD_NEXT, "execvp"); + return real(file, argv, environ); +} + int execve(const char *path, char *const *argv, char *const *envp) { debug_print("execve %s\n", path); @@ -94,18 +109,6 @@ int execvp(const char *file, char *const *argv) { return execvpe(file, argv, environ); } -int execvpe(const char *file, char *const *argv, char *const *envp) { - debug_print("execvpe %s\n", file); - - if (!strcmp(file, "ld") || is_ld(file)) { - file = get_mold_path(); - ((const char **)argv)[0] = file; - } - - typeof(execvpe) *real = dlsym(RTLD_NEXT, "execvpe"); - return real(file, argv, environ); -} - int posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, diff --git a/output-chunks.cc b/output-chunks.cc index e0424a3c..c285e15c 100644 --- a/output-chunks.cc +++ b/output-chunks.cc @@ -1,11 +1,18 @@ #include "mold.h" -#include #include #include #include #include +#ifdef __APPLE__ +# define COMMON_DIGEST_FOR_OPENSSL +# include +# define SHA256(data, len, md) CC_SHA256(data, len, md) +#else +# include +#endif + template void OutputChunk::write_to(Context &ctx, u8 *buf) { Fatal(ctx) << name << ": write_to is called on an invalid section"; diff --git a/subprocess.cc b/subprocess.cc index 56caec79..c15c369f 100644 --- a/subprocess.cc +++ b/subprocess.cc @@ -1,6 +1,5 @@ #include "mold.h" -#include #include #include #include @@ -9,6 +8,13 @@ #include #include +#ifdef __APPLE__ +# define COMMON_DIGEST_FOR_OPENSSL +# include +#else +# include +#endif + #define DAEMON_TIMEOUT 30 // Exiting from a program with large memory usage is slow --