[llvm] Cpu features cross platform (PR #205447)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 26 19:16:20 PDT 2026


================
@@ -0,0 +1,99 @@
+//===- TargetTriple.cpp - Darwin target triple detection ------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Target triple detection on Darwin.
+//
+//===----------------------------------------------------------------------===//
+
+#include "orc-rt/TargetTriple.h"
+#include "orc-rt/TargetDetails.h"
+
+#include <TargetConditionals.h>
+#include <cstdlib>
+#include <cstring>
+#include <sys/sysctl.h>
+#include <sys/types.h>
+
+namespace orc_rt {
+
+namespace {
+
+std::string sysctlString(const char *Name) noexcept {
+  // This should be large enough for everything we need it for
+  // this upfront oversized allocation avoids a second syscall.
+  char Buf[64] = {};
+  size_t S = sizeof(Buf);
+  if (sysctlbyname(Name, Buf, &S, nullptr, 0) != 0)
+    return {};
+  return std::string(Buf, strnlen(Buf, S));
----------------
lhames wrote:

Could you add a fixme to dynamically size the buffer and check errors? (Eventually we want this watertight, but it's not a priority for landing this patch).

https://github.com/llvm/llvm-project/pull/205447


More information about the llvm-commits mailing list