[clang] [Driver] Implement ToolChain on Haiku (PR #66038)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 23 21:58:14 PDT 2024
================
@@ -9,20 +9,141 @@
#include "Haiku.h"
#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/Compilation.h"
#include "llvm/Support/Path.h"
using namespace clang::driver;
+using namespace clang::driver::tools;
using namespace clang::driver::toolchains;
using namespace clang;
using namespace llvm::opt;
+void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+ const InputInfo &Output,
+ const InputInfoList &Inputs,
+ const ArgList &Args,
+ const char *LinkingOutput) const {
+ const toolchains::Haiku &ToolChain =
+ static_cast<const toolchains::Haiku &>(getToolChain());
+ const Driver &D = ToolChain.getDriver();
+ const llvm::Triple::ArchType Arch = ToolChain.getArch();
+ const bool Static = Args.hasArg(options::OPT_static);
+ const bool Shared = Args.hasArg(options::OPT_shared);
+ ArgStringList CmdArgs;
+
+ // Silence warning for "clang -g foo.o -o foo"
+ Args.ClaimAllArgs(options::OPT_g_Group);
+ // and "clang -emit-llvm foo.o -o foo"
+ Args.ClaimAllArgs(options::OPT_emit_llvm);
+ // and for "clang -w foo.o -o foo". Other warning options are already
+ // handled somewhere else.
+ Args.ClaimAllArgs(options::OPT_w);
+
+ // Silence warning for "clang -pie foo.o -o foo"
+ Args.ClaimAllArgs(options::OPT_pie);
+
+ if (!D.SysRoot.empty())
+ CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
+ CmdArgs.push_back("--eh-frame-hdr");
+ if (Static) {
+ CmdArgs.push_back("-Bstatic");
+ } else {
+ if (Args.hasArg(options::OPT_rdynamic))
+ CmdArgs.push_back("-export-dynamic");
+ if (Shared)
+ CmdArgs.push_back("-shared");
----------------
X547 wrote:
`-shared` flag is already added below.
Haiku applications must be always linked with `-shared` flag, both runnable executables and shared libraries. PIE executables and executable TLS modes are not supported and may trigger wield crashes.
Haiku executable loading and startup sequence significantly differs from Linux. First Haiku kernel loads `runtime_loader` (program interpreter in Linux terminology) into newely created process and pass argv/environ arguments to it. Kernel itself do not load or even touch target executable to be executed, it only pass path to in in `haiku_loader` entry point.
Then `haiku_loader` loads target executable with something like `dlopen()`, get entry point from ELF header and run it (`exit(entryPoint(argc, argv, environ));`).
https://github.com/llvm/llvm-project/pull/66038
More information about the cfe-commits
mailing list