mirror of
https://github.com/Relintai/osxcross.git
synced 2025-02-03 22:45:56 +01:00
Implement workarounds for vanilla llvm-dsymutil compatibility
This commit is contained in:
parent
4ea0c29d0c
commit
118d72e594
@ -239,10 +239,10 @@ constexpr struct Opt {
|
|||||||
const size_t valseparatorlen;
|
const size_t valseparatorlen;
|
||||||
constexpr Opt(const char *name, optFun fun, const bool valrequired = false,
|
constexpr Opt(const char *name, optFun fun, const bool valrequired = false,
|
||||||
const bool pusharg = false, const char *valseparator = nullptr)
|
const bool pusharg = false, const char *valseparator = nullptr)
|
||||||
: name(name), namelen(slen(name)), fun(fun),
|
: name(name), namelen(constexprStrLen(name)), fun(fun),
|
||||||
valrequired(valrequired), pusharg(pusharg),
|
valrequired(valrequired), pusharg(pusharg),
|
||||||
valseparator(valseparator),
|
valseparator(valseparator),
|
||||||
valseparatorlen(valseparator ? slen(valseparator) : 0) {}
|
valseparatorlen(valseparator ? constexprStrLen(valseparator) : 0) {}
|
||||||
} opts[] = {
|
} opts[] = {
|
||||||
{"-mmacosx-version-min", versionmin, true, false, "="},
|
{"-mmacosx-version-min", versionmin, true, false, "="},
|
||||||
{"-stdlib", stdlib, true, false, "="},
|
{"-stdlib", stdlib, true, false, "="},
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <signal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace tools;
|
using namespace tools;
|
||||||
@ -32,6 +35,19 @@ namespace program {
|
|||||||
int dsymutil(int argc, char **argv, Target &target) {
|
int dsymutil(int argc, char **argv, Target &target) {
|
||||||
(void)argc;
|
(void)argc;
|
||||||
|
|
||||||
|
//
|
||||||
|
// LLVM 3.6 and LLVM 3.7 come with too early in-development versions of
|
||||||
|
// llvm-dsymutil, which we *must* ignore here.
|
||||||
|
//
|
||||||
|
// 1. Lookup the [osxcross-]llvm-dsymutil binary.
|
||||||
|
// If no binary is found, then silently return 0/EXIT_SUCCESS.
|
||||||
|
// 2. Run <llvm-dsymutil -version>.
|
||||||
|
// 3. Check whether we are using llvm-dsymutil 3.8 (or later),
|
||||||
|
// otherwise silently return 0/EXIT_SUCCESS.
|
||||||
|
// 4. Apply compatibility workarounds.
|
||||||
|
// 5. Run [osxcross-]llvm-dsymutil.
|
||||||
|
//
|
||||||
|
|
||||||
std::string dsymutil;
|
std::string dsymutil;
|
||||||
char LLVMDsymutilVersionOutput[1024];
|
char LLVMDsymutilVersionOutput[1024];
|
||||||
const char *LLVMDsymutilVersionStr;
|
const char *LLVMDsymutilVersionStr;
|
||||||
@ -75,7 +91,7 @@ int dsymutil(int argc, char **argv, Target &target) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMDsymutilVersionStr += 13; // strlen("LLVM version ");
|
LLVMDsymutilVersionStr += constexprStrLen("LLVM version ");
|
||||||
|
|
||||||
LLVMDsymutilVersion = parseLLVMVersion(LLVMDsymutilVersionStr);
|
LLVMDsymutilVersion = parseLLVMVersion(LLVMDsymutilVersionStr);
|
||||||
|
|
||||||
@ -97,7 +113,104 @@ int dsymutil(int argc, char **argv, Target &target) {
|
|||||||
lipo << target.execpath << PATHDIV
|
lipo << target.execpath << PATHDIV
|
||||||
<< target.getDefaultTriple(triple) << "-lipo";
|
<< target.getDefaultTriple(triple) << "-lipo";
|
||||||
|
|
||||||
setenv("LIPO", lipo.str().c_str(), 1);
|
if (endsWith(dsymutil, "osxcross-llvm-dsymutil")) {
|
||||||
|
// This is a patched llvm-dsymutil, just need to set LIPO here.
|
||||||
|
setenv("LIPO", lipo.str().c_str(), 1);
|
||||||
|
} else {
|
||||||
|
// This is an unpatched llvm-dsymutil, need to use stupid workarounds here.
|
||||||
|
|
||||||
|
// There is a bug in the vanilla llvm-dsymutil sources which would cause it
|
||||||
|
// to crash when operating on gcc object files.
|
||||||
|
// Fix: https://github.com/tpoechtrager/llvm-dsymutil/commit/5e0fea25.patch
|
||||||
|
|
||||||
|
auto fixHint = []() {
|
||||||
|
info << "you can build a patched llvm-dsymutil via "
|
||||||
|
<< "./build_llvm_dsymutil.sh"
|
||||||
|
<< info.endl();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (ParentProcessName == "collect2" &&
|
||||||
|
!getenv("OSXCROSS_FORCE_GCC_DSYMUTIL_INVOCATION")) {
|
||||||
|
if (!getenv("OSXCROSS_NO_GCC_DSYMUTIL_WARNING")) {
|
||||||
|
warn << "dsymutil is a no-op when being invoked via gcc; "
|
||||||
|
<< "you would get a crash otherwise"
|
||||||
|
<< warn.endl();
|
||||||
|
fixHint();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
//
|
||||||
|
// A glorious workaround to make the vanilla llvm-dsymutil find lipo.
|
||||||
|
//
|
||||||
|
// 1. Create a temporary directory.
|
||||||
|
// 2. Store a lipo symlink there.
|
||||||
|
// 3. Append <tmpdir> to PATH.
|
||||||
|
// 4. Fork the process and wait until the child process exited.
|
||||||
|
// 5. Remove the temporary directory and return the llvm-dsymutil.
|
||||||
|
// exit code.
|
||||||
|
//
|
||||||
|
|
||||||
|
char tmpdir[] = "/tmp/XXXXXX";
|
||||||
|
std::string lipolink;
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
if (mkdtemp(tmpdir)) {
|
||||||
|
lipolink = tmpdir;
|
||||||
|
lipolink += "/lipo";
|
||||||
|
|
||||||
|
auto removeTemporaryDirectory = [&]() {
|
||||||
|
if ((!lipolink.empty() && unlink(lipolink.c_str())) || rmdir(tmpdir)) {
|
||||||
|
warn << "dsymutil: cannot remove temporary directory '"
|
||||||
|
<< tmpdir << "'" << warn.endl();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!symlink(lipo.str().c_str(), lipolink.c_str())) {
|
||||||
|
concatEnvVariable("PATH", tmpdir);
|
||||||
|
|
||||||
|
if ((pid = fork()) == -1) {
|
||||||
|
err << "dsymutil: fork() failed" << err.endl();
|
||||||
|
removeTemporaryDirectory();
|
||||||
|
return 2;
|
||||||
|
} else if (pid > 0) {
|
||||||
|
int status;
|
||||||
|
|
||||||
|
if (waitpid(pid, &status, 0) == -1) {
|
||||||
|
err << "dsymutil: waitpid() failed" << err.endl();
|
||||||
|
removeTemporaryDirectory();
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeTemporaryDirectory();
|
||||||
|
|
||||||
|
if (WIFSIGNALED(status)) {
|
||||||
|
int signal = WTERMSIG(status);
|
||||||
|
|
||||||
|
err << "dsymutil: signal: " << strsignal(signal) << err.endl();
|
||||||
|
|
||||||
|
if (signal == SIGSEGV) {
|
||||||
|
info << "the vanilla llvm-dsymutil is known to crash "
|
||||||
|
<< "when operating on gcc object files" << info.endl();
|
||||||
|
fixHint();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WIFEXITED(status))
|
||||||
|
return WEXITSTATUS(status);
|
||||||
|
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lipolink.clear();
|
||||||
|
removeTemporaryDirectory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (execvp(dsymutil.c_str(), argv))
|
if (execvp(dsymutil.c_str(), argv))
|
||||||
err << "cannot execute '" << dsymutil << "'" << err.endl();
|
err << "cannot execute '" << dsymutil << "'" << err.endl();
|
||||||
|
@ -40,8 +40,8 @@ static inline bool endsWith(std::string const &str, std::string const &end) {
|
|||||||
return std::equal(end.rbegin(), end.rend(), str.rbegin());
|
return std::equal(end.rbegin(), end.rend(), str.rbegin());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t constexpr slen(const char *str) {
|
size_t constexpr constexprStrLen(const char *str) {
|
||||||
return *str ? 1 + slen(str + 1) : 0;
|
return *str ? 1 + constexprStrLen(str + 1) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user