| 283 | |
| 284 | template <typename XCOFF> |
| 285 | bool Impl<XCOFF>::SetLibPath(cm::string_view libPath) |
| 286 | { |
| 287 | // The new LIBPATH must contain standard AIX LIBPATH entries. |
| 288 | std::string libPathBuf; |
| 289 | #define ENSURE_ENTRY(x) \ |
| 290 | if (libPath != x && !cmHasLiteralPrefix(libPath, x ":") && \ |
| 291 | !cmHasLiteralSuffix(libPath, ":" x) && \ |
| 292 | libPath.find(":" x ":") == std::string::npos) { \ |
| 293 | libPathBuf = std::string(libPath); \ |
| 294 | if (!libPathBuf.empty() && libPathBuf.back() != ':') { \ |
| 295 | libPathBuf.push_back(':'); \ |
| 296 | } \ |
| 297 | libPathBuf += x; \ |
| 298 | libPath = libPathBuf; \ |
| 299 | } |
| 300 | ENSURE_ENTRY("/usr/lib") |
| 301 | ENSURE_ENTRY("/lib") |
| 302 | #undef ENSURE_ENTRY |
| 303 | |
| 304 | auto oldEnd = std::find(this->LoaderImportFileTable.begin(), |
| 305 | this->LoaderImportFileTable.end(), '\0'); |
| 306 | if (oldEnd == this->LoaderImportFileTable.end()) { |
| 307 | this->SetErrorMessage("XCOFF loader import file id table is invalid."); |
| 308 | return false; |
| 309 | } |
| 310 | if ((this->LoaderImportFileTable.begin() + libPath.size()) > oldEnd) { |
| 311 | this->SetErrorMessage("XCOFF loader import file id table is too small."); |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | { |
| 316 | std::vector<char> ift; |
| 317 | ift.reserve(this->LoaderImportFileTable.size()); |
| 318 | // Start with the new LIBPATH. |
| 319 | ift.insert(ift.end(), libPath.begin(), libPath.end()); |
| 320 | // Add the rest of the original table. |
| 321 | ift.insert(ift.end(), oldEnd, this->LoaderImportFileTable.end()); |
| 322 | // If the new table is shorter, zero out the leftover space. |
| 323 | ift.resize(this->LoaderImportFileTable.size(), 0); |
| 324 | this->LoaderHeader.l_istlen = |
| 325 | static_cast<decltype(XCOFF::ldhdr::l_istlen)>(ift.size()); |
| 326 | this->LoaderImportFileTable = std::move(ift); |
| 327 | } |
| 328 | |
| 329 | size_t scnptr; |
| 330 | if (this->is_big_archive == IsArchive::Yes) { |
| 331 | size_t header_len = sizeof(fl_hdr) + sizeof(ar_hdr) + this->nextEvenByte; |
| 332 | scnptr = this->LoaderSectionHeader.s_scnptr + |
| 333 | offsetof(typename XCOFF::ldhdr, l_istlen) + |
| 334 | align(header_len, this->bytes_to_align); |
| 335 | } else { |
| 336 | scnptr = this->LoaderSectionHeader.s_scnptr + |
| 337 | offsetof(typename XCOFF::ldhdr, l_istlen); |
| 338 | } |
| 339 | |
| 340 | if (!this->Stream->seekp(scnptr, std::ios::beg)) { |
| 341 | this->SetErrorMessage( |
| 342 | "Failed to seek to XCOFF loader header import file id table length."); |
no test coverage detected