From 3e5b9229e0083081fa96422ab279f62012ca24a5 Mon Sep 17 00:00:00 2001 From: Aditya Vidyadhar Kamath Date: Mon, 30 Sep 2024 10:02:46 -0500 Subject: [PATCH] AIX: Fix XCOFF editor to avoid duplicating standard libpath entries The `/usr/lib` and `/lib` entries need to be present, but do not need to be at the end. Avoid appending extra copies of the entries if they already exist. Closes: #26275 --- Source/cmXCOFF.cxx | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Source/cmXCOFF.cxx b/Source/cmXCOFF.cxx index 6fd6fbf4cf..e459103f66 100644 --- a/Source/cmXCOFF.cxx +++ b/Source/cmXCOFF.cxx @@ -6,6 +6,7 @@ #include #include +#include #include "cmsys/FStream.hxx" @@ -283,19 +284,22 @@ cm::optional Impl::GetLibPath() template bool Impl::SetLibPath(cm::string_view libPath) { - // The new LIBPATH must end in the standard AIX LIBPATH. -#define CM_AIX_LIBPATH "/usr/lib:/lib" + // The new LIBPATH must contain standard AIX LIBPATH entries. std::string libPathBuf; - if (libPath != CM_AIX_LIBPATH && - !cmHasLiteralSuffix(libPath, ":" CM_AIX_LIBPATH)) { - libPathBuf = std::string(libPath); - if (!libPathBuf.empty() && libPathBuf.back() != ':') { - libPathBuf.push_back(':'); - } - libPathBuf += CM_AIX_LIBPATH; - libPath = libPathBuf; +#define ENSURE_ENTRY(x) \ + if (libPath != x && !cmHasLiteralPrefix(libPath, x ":") && \ + !cmHasLiteralSuffix(libPath, ":" x) && \ + libPath.find(":" x ":") == std::string::npos) { \ + libPathBuf = std::string(libPath); \ + if (!libPathBuf.empty() && libPathBuf.back() != ':') { \ + libPathBuf.push_back(':'); \ + } \ + libPathBuf += x; \ + libPath = libPathBuf; \ } -#undef CM_AIX_LIBPATH + ENSURE_ENTRY("/usr/lib") + ENSURE_ENTRY("/lib") +#undef ENSURE_ENTRY auto oldEnd = std::find(this->LoaderImportFileTable.begin(), this->LoaderImportFileTable.end(), '\0');