[clang] [Clang][Hexagon] Use flat library directory layout for Picolibc (PR #201326)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 30 01:53:30 PDT 2026


================
@@ -582,14 +582,29 @@ void HexagonToolChain::getLibraryDir(const ArgList &Args,
     llvm::sys::path::append(Dir, "lib");
   }
   std::string CpuVer = GetTargetCPUVersion(Args).str();
-  llvm::sys::path::append(Dir, CpuVer);
-  if (auto G = toolchains::HexagonToolChain::getSmallDataThreshold(Args))
-    if (*G == 0)
-      llvm::sys::path::append(Dir, "G0");
-  bool IsStatic = Args.hasArg(options::OPT_static);
+  bool IsPicolibc = GetCStdlibType(Args) == ToolChain::CST_Picolibc;
+  bool IsG0 =
+      toolchains::HexagonToolChain::getSmallDataThreshold(Args).value_or(1) ==
+      0;
   bool IsShared = Args.hasArg(options::OPT_shared);
-  if (IsShared && !IsStatic)
-    llvm::sys::path::append(Dir, "pic");
+  // shared object must be -fPIC
+  bool IsPic = IsShared || Args.hasArg(options::OPT_fpic, options::OPT_fPIC);
+  if (IsPicolibc) {
+    // Flat layout: lib/v68-G0-pic, lib/v68-G0, lib/v68
+    std::string Variant = CpuVer;
+    if (IsG0)
+      Variant += "-G0";
+    if (IsPic)
+      Variant += "-pic";
+    llvm::sys::path::append(Dir, Variant);
+  } else {
+    // Nested layout (non-Picolibc): lib/v68/G0/pic
+    llvm::sys::path::append(Dir, CpuVer);
+    if (IsG0)
+      llvm::sys::path::append(Dir, "G0");
+    if (IsPic)
+      llvm::sys::path::append(Dir, "pic");
+  }
----------------
quic-k wrote:

right, I will restore the original behavior for non-Picolibc

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


More information about the cfe-commits mailing list