1 //===--- XCOFFObjectFile.cpp - XCOFF object file implementation -----------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines the XCOFFObjectFile class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/Object/XCOFFObjectFile.h" 14 #include "llvm/ADT/StringSwitch.h" 15 #include "llvm/MC/SubtargetFeature.h" 16 #include "llvm/Support/DataExtractor.h" 17 #include <cstddef> 18 #include <cstring> 19 20 namespace llvm { 21 22 using namespace XCOFF; 23 24 namespace object { 25 26 static const uint8_t FunctionSym = 0x20; 27 static const uint16_t NoRelMask = 0x0001; 28 static const size_t SymbolAuxTypeOffset = 17; 29 30 // Checks that [Ptr, Ptr + Size) bytes fall inside the memory buffer 31 // 'M'. Returns a pointer to the underlying object on success. 32 template <typename T> 33 static Expected<const T *> getObject(MemoryBufferRef M, const void *Ptr, 34 const uint64_t Size = sizeof(T)) { 35 uintptr_t Addr = reinterpret_cast<uintptr_t>(Ptr); 36 if (Error E = Binary::checkOffset(M, Addr, Size)) 37 return std::move(E); 38 return reinterpret_cast<const T *>(Addr); 39 } 40 41 static uintptr_t getWithOffset(uintptr_t Base, ptrdiff_t Offset) { 42 return reinterpret_cast<uintptr_t>(reinterpret_cast<const char *>(Base) + 43 Offset); 44 } 45 46 template <typename T> static const T *viewAs(uintptr_t in) { 47 return reinterpret_cast<const T *>(in); 48 } 49 50 static StringRef generateXCOFFFixedNameStringRef(const char *Name) { 51 auto NulCharPtr = 52 static_cast<const char *>(memchr(Name, '\0', XCOFF::NameSize)); 53 return NulCharPtr ? StringRef(Name, NulCharPtr - Name) 54 : StringRef(Name, XCOFF::NameSize); 55 } 56 57 template <typename T> StringRef XCOFFSectionHeader<T>::getName() const { 58 const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this); 59 return generateXCOFFFixedNameStringRef(DerivedXCOFFSectionHeader.Name); 60 } 61 62 template <typename T> uint16_t XCOFFSectionHeader<T>::getSectionType() const { 63 const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this); 64 return DerivedXCOFFSectionHeader.Flags & SectionFlagsTypeMask; 65 } 66 67 template <typename T> 68 bool XCOFFSectionHeader<T>::isReservedSectionType() const { 69 return getSectionType() & SectionFlagsReservedMask; 70 } 71 72 bool XCOFFRelocation32::isRelocationSigned() const { 73 return Info & XR_SIGN_INDICATOR_MASK; 74 } 75 76 bool XCOFFRelocation32::isFixupIndicated() const { 77 return Info & XR_FIXUP_INDICATOR_MASK; 78 } 79 80 uint8_t XCOFFRelocation32::getRelocatedLength() const { 81 // The relocation encodes the bit length being relocated minus 1. Add back 82 // the 1 to get the actual length being relocated. 83 return (Info & XR_BIASED_LENGTH_MASK) + 1; 84 } 85 86 uintptr_t 87 XCOFFObjectFile::getAdvancedSymbolEntryAddress(uintptr_t CurrentAddress, 88 uint32_t Distance) { 89 return getWithOffset(CurrentAddress, Distance * XCOFF::SymbolTableEntrySize); 90 } 91 92 const XCOFF::SymbolAuxType * 93 XCOFFObjectFile::getSymbolAuxType(uintptr_t AuxEntryAddress) const { 94 assert(is64Bit() && "64-bit interface called on a 32-bit object file."); 95 return viewAs<XCOFF::SymbolAuxType>( 96 getWithOffset(AuxEntryAddress, SymbolAuxTypeOffset)); 97 } 98 99 void XCOFFObjectFile::checkSectionAddress(uintptr_t Addr, 100 uintptr_t TableAddress) const { 101 if (Addr < TableAddress) 102 report_fatal_error("Section header outside of section header table."); 103 104 uintptr_t Offset = Addr - TableAddress; 105 if (Offset >= getSectionHeaderSize() * getNumberOfSections()) 106 report_fatal_error("Section header outside of section header table."); 107 108 if (Offset % getSectionHeaderSize() != 0) 109 report_fatal_error( 110 "Section header pointer does not point to a valid section header."); 111 } 112 113 const XCOFFSectionHeader32 * 114 XCOFFObjectFile::toSection32(DataRefImpl Ref) const { 115 assert(!is64Bit() && "32-bit interface called on 64-bit object file."); 116 #ifndef NDEBUG 117 checkSectionAddress(Ref.p, getSectionHeaderTableAddress()); 118 #endif 119 return viewAs<XCOFFSectionHeader32>(Ref.p); 120 } 121 122 const XCOFFSectionHeader64 * 123 XCOFFObjectFile::toSection64(DataRefImpl Ref) const { 124 assert(is64Bit() && "64-bit interface called on a 32-bit object file."); 125 #ifndef NDEBUG 126 checkSectionAddress(Ref.p, getSectionHeaderTableAddress()); 127 #endif 128 return viewAs<XCOFFSectionHeader64>(Ref.p); 129 } 130 131 XCOFFSymbolRef XCOFFObjectFile::toSymbolRef(DataRefImpl Ref) const { 132 assert(Ref.p != 0 && "Symbol table pointer can not be nullptr!"); 133 #ifndef NDEBUG 134 checkSymbolEntryPointer(Ref.p); 135 #endif 136 return XCOFFSymbolRef(Ref, this); 137 } 138 139 const XCOFFFileHeader32 *XCOFFObjectFile::fileHeader32() const { 140 assert(!is64Bit() && "32-bit interface called on 64-bit object file."); 141 return static_cast<const XCOFFFileHeader32 *>(FileHeader); 142 } 143 144 const XCOFFFileHeader64 *XCOFFObjectFile::fileHeader64() const { 145 assert(is64Bit() && "64-bit interface called on a 32-bit object file."); 146 return static_cast<const XCOFFFileHeader64 *>(FileHeader); 147 } 148 149 const XCOFFSectionHeader32 * 150 XCOFFObjectFile::sectionHeaderTable32() const { 151 assert(!is64Bit() && "32-bit interface called on 64-bit object file."); 152 return static_cast<const XCOFFSectionHeader32 *>(SectionHeaderTable); 153 } 154 155 const XCOFFSectionHeader64 * 156 XCOFFObjectFile::sectionHeaderTable64() const { 157 assert(is64Bit() && "64-bit interface called on a 32-bit object file."); 158 return static_cast<const XCOFFSectionHeader64 *>(SectionHeaderTable); 159 } 160 161 void XCOFFObjectFile::moveSymbolNext(DataRefImpl &Symb) const { 162 uintptr_t NextSymbolAddr = getAdvancedSymbolEntryAddress( 163 Symb.p, toSymbolRef(Symb).getNumberOfAuxEntries() + 1); 164 #ifndef NDEBUG 165 // This function is used by basic_symbol_iterator, which allows to 166 // point to the end-of-symbol-table address. 167 if (NextSymbolAddr != getEndOfSymbolTableAddress()) 168 checkSymbolEntryPointer(NextSymbolAddr); 169 #endif 170 Symb.p = NextSymbolAddr; 171 } 172 173 Expected<StringRef> 174 XCOFFObjectFile::getStringTableEntry(uint32_t Offset) const { 175 // The byte offset is relative to the start of the string table. 176 // A byte offset value of 0 is a null or zero-length symbol 177 // name. A byte offset in the range 1 to 3 (inclusive) points into the length 178 // field; as a soft-error recovery mechanism, we treat such cases as having an 179 // offset of 0. 180 if (Offset < 4) 181 return StringRef(nullptr, 0); 182 183 if (StringTable.Data != nullptr && StringTable.Size > Offset) 184 return (StringTable.Data + Offset); 185 186 return make_error<GenericBinaryError>("Bad offset for string table entry", 187 object_error::parse_failed); 188 } 189 190 Expected<StringRef> 191 XCOFFObjectFile::getCFileName(const XCOFFFileAuxEnt *CFileEntPtr) const { 192 if (CFileEntPtr->NameInStrTbl.Magic != XCOFFSymbolRef::NAME_IN_STR_TBL_MAGIC) 193 return generateXCOFFFixedNameStringRef(CFileEntPtr->Name); 194 return getStringTableEntry(CFileEntPtr->NameInStrTbl.Offset); 195 } 196 197 Expected<StringRef> XCOFFObjectFile::getSymbolName(DataRefImpl Symb) const { 198 return toSymbolRef(Symb).getName(); 199 } 200 201 Expected<uint64_t> XCOFFObjectFile::getSymbolAddress(DataRefImpl Symb) const { 202 return toSymbolRef(Symb).getValue(); 203 } 204 205 uint64_t XCOFFObjectFile::getSymbolValueImpl(DataRefImpl Symb) const { 206 return toSymbolRef(Symb).getValue(); 207 } 208 209 uint64_t XCOFFObjectFile::getCommonSymbolSizeImpl(DataRefImpl Symb) const { 210 uint64_t Result = 0; 211 llvm_unreachable("Not yet implemented!"); 212 return Result; 213 } 214 215 Expected<SymbolRef::Type> 216 XCOFFObjectFile::getSymbolType(DataRefImpl Symb) const { 217 // TODO: Return the correct symbol type. 218 return SymbolRef::ST_Other; 219 } 220 221 Expected<section_iterator> 222 XCOFFObjectFile::getSymbolSection(DataRefImpl Symb) const { 223 const int16_t SectNum = toSymbolRef(Symb).getSectionNumber(); 224 225 if (isReservedSectionNumber(SectNum)) 226 return section_end(); 227 228 Expected<DataRefImpl> ExpSec = getSectionByNum(SectNum); 229 if (!ExpSec) 230 return ExpSec.takeError(); 231 232 return section_iterator(SectionRef(ExpSec.get(), this)); 233 } 234 235 void XCOFFObjectFile::moveSectionNext(DataRefImpl &Sec) const { 236 const char *Ptr = reinterpret_cast<const char *>(Sec.p); 237 Sec.p = reinterpret_cast<uintptr_t>(Ptr + getSectionHeaderSize()); 238 } 239 240 Expected<StringRef> XCOFFObjectFile::getSectionName(DataRefImpl Sec) const { 241 return generateXCOFFFixedNameStringRef(getSectionNameInternal(Sec)); 242 } 243 244 uint64_t XCOFFObjectFile::getSectionAddress(DataRefImpl Sec) const { 245 // Avoid ternary due to failure to convert the ubig32_t value to a unit64_t 246 // with MSVC. 247 if (is64Bit()) 248 return toSection64(Sec)->VirtualAddress; 249 250 return toSection32(Sec)->VirtualAddress; 251 } 252 253 uint64_t XCOFFObjectFile::getSectionIndex(DataRefImpl Sec) const { 254 // Section numbers in XCOFF are numbered beginning at 1. A section number of 255 // zero is used to indicate that a symbol is being imported or is undefined. 256 if (is64Bit()) 257 return toSection64(Sec) - sectionHeaderTable64() + 1; 258 else 259 return toSection32(Sec) - sectionHeaderTable32() + 1; 260 } 261 262 uint64_t XCOFFObjectFile::getSectionSize(DataRefImpl Sec) const { 263 // Avoid ternary due to failure to convert the ubig32_t value to a unit64_t 264 // with MSVC. 265 if (is64Bit()) 266 return toSection64(Sec)->SectionSize; 267 268 return toSection32(Sec)->SectionSize; 269 } 270 271 Expected<ArrayRef<uint8_t>> 272 XCOFFObjectFile::getSectionContents(DataRefImpl Sec) const { 273 if (isSectionVirtual(Sec)) 274 return ArrayRef<uint8_t>(); 275 276 uint64_t OffsetToRaw; 277 if (is64Bit()) 278 OffsetToRaw = toSection64(Sec)->FileOffsetToRawData; 279 else 280 OffsetToRaw = toSection32(Sec)->FileOffsetToRawData; 281 282 const uint8_t * ContentStart = base() + OffsetToRaw; 283 uint64_t SectionSize = getSectionSize(Sec); 284 if (checkOffset(Data, reinterpret_cast<uintptr_t>(ContentStart), SectionSize)) 285 return make_error<BinaryError>(); 286 287 return makeArrayRef(ContentStart,SectionSize); 288 } 289 290 uint64_t XCOFFObjectFile::getSectionAlignment(DataRefImpl Sec) const { 291 uint64_t Result = 0; 292 llvm_unreachable("Not yet implemented!"); 293 return Result; 294 } 295 296 bool XCOFFObjectFile::isSectionCompressed(DataRefImpl Sec) const { 297 return false; 298 } 299 300 bool XCOFFObjectFile::isSectionText(DataRefImpl Sec) const { 301 return getSectionFlags(Sec) & XCOFF::STYP_TEXT; 302 } 303 304 bool XCOFFObjectFile::isSectionData(DataRefImpl Sec) const { 305 uint32_t Flags = getSectionFlags(Sec); 306 return Flags & (XCOFF::STYP_DATA | XCOFF::STYP_TDATA); 307 } 308 309 bool XCOFFObjectFile::isSectionBSS(DataRefImpl Sec) const { 310 uint32_t Flags = getSectionFlags(Sec); 311 return Flags & (XCOFF::STYP_BSS | XCOFF::STYP_TBSS); 312 } 313 314 bool XCOFFObjectFile::isDebugSection(DataRefImpl Sec) const { 315 uint32_t Flags = getSectionFlags(Sec); 316 return Flags & (XCOFF::STYP_DEBUG | XCOFF::STYP_DWARF); 317 } 318 319 bool XCOFFObjectFile::isSectionVirtual(DataRefImpl Sec) const { 320 return is64Bit() ? toSection64(Sec)->FileOffsetToRawData == 0 321 : toSection32(Sec)->FileOffsetToRawData == 0; 322 } 323 324 relocation_iterator XCOFFObjectFile::section_rel_begin(DataRefImpl Sec) const { 325 if (is64Bit()) 326 report_fatal_error("64-bit support not implemented yet"); 327 const XCOFFSectionHeader32 *SectionEntPtr = toSection32(Sec); 328 auto RelocationsOrErr = relocations(*SectionEntPtr); 329 if (Error E = RelocationsOrErr.takeError()) 330 return relocation_iterator(RelocationRef()); 331 DataRefImpl Ret; 332 Ret.p = reinterpret_cast<uintptr_t>(&*RelocationsOrErr.get().begin()); 333 return relocation_iterator(RelocationRef(Ret, this)); 334 } 335 336 relocation_iterator XCOFFObjectFile::section_rel_end(DataRefImpl Sec) const { 337 if (is64Bit()) 338 report_fatal_error("64-bit support not implemented yet"); 339 const XCOFFSectionHeader32 *SectionEntPtr = toSection32(Sec); 340 auto RelocationsOrErr = relocations(*SectionEntPtr); 341 if (Error E = RelocationsOrErr.takeError()) 342 return relocation_iterator(RelocationRef()); 343 DataRefImpl Ret; 344 Ret.p = reinterpret_cast<uintptr_t>(&*RelocationsOrErr.get().end()); 345 return relocation_iterator(RelocationRef(Ret, this)); 346 } 347 348 void XCOFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { 349 Rel.p = reinterpret_cast<uintptr_t>(viewAs<XCOFFRelocation32>(Rel.p) + 1); 350 } 351 352 uint64_t XCOFFObjectFile::getRelocationOffset(DataRefImpl Rel) const { 353 if (is64Bit()) 354 report_fatal_error("64-bit support not implemented yet"); 355 const XCOFFRelocation32 *Reloc = viewAs<XCOFFRelocation32>(Rel.p); 356 const XCOFFSectionHeader32 *Sec32 = sectionHeaderTable32(); 357 const uint32_t RelocAddress = Reloc->VirtualAddress; 358 const uint16_t NumberOfSections = getNumberOfSections(); 359 for (uint16_t i = 0; i < NumberOfSections; ++i) { 360 // Find which section this relocation is belonging to, and get the 361 // relocation offset relative to the start of the section. 362 if (Sec32->VirtualAddress <= RelocAddress && 363 RelocAddress < Sec32->VirtualAddress + Sec32->SectionSize) { 364 return RelocAddress - Sec32->VirtualAddress; 365 } 366 ++Sec32; 367 } 368 return InvalidRelocOffset; 369 } 370 371 symbol_iterator XCOFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const { 372 if (is64Bit()) 373 report_fatal_error("64-bit support not implemented yet"); 374 const XCOFFRelocation32 *Reloc = viewAs<XCOFFRelocation32>(Rel.p); 375 const uint32_t Index = Reloc->SymbolIndex; 376 377 if (Index >= getLogicalNumberOfSymbolTableEntries32()) 378 return symbol_end(); 379 380 DataRefImpl SymDRI; 381 SymDRI.p = getSymbolEntryAddressByIndex(Index); 382 return symbol_iterator(SymbolRef(SymDRI, this)); 383 } 384 385 uint64_t XCOFFObjectFile::getRelocationType(DataRefImpl Rel) const { 386 if (is64Bit()) 387 report_fatal_error("64-bit support not implemented yet"); 388 return viewAs<XCOFFRelocation32>(Rel.p)->Type; 389 } 390 391 void XCOFFObjectFile::getRelocationTypeName( 392 DataRefImpl Rel, SmallVectorImpl<char> &Result) const { 393 if (is64Bit()) 394 report_fatal_error("64-bit support not implemented yet"); 395 const XCOFFRelocation32 *Reloc = viewAs<XCOFFRelocation32>(Rel.p); 396 StringRef Res = XCOFF::getRelocationTypeString(Reloc->Type); 397 Result.append(Res.begin(), Res.end()); 398 } 399 400 Expected<uint32_t> XCOFFObjectFile::getSymbolFlags(DataRefImpl Symb) const { 401 uint32_t Result = 0; 402 // TODO: Return correct symbol flags. 403 return Result; 404 } 405 406 basic_symbol_iterator XCOFFObjectFile::symbol_begin() const { 407 DataRefImpl SymDRI; 408 SymDRI.p = reinterpret_cast<uintptr_t>(SymbolTblPtr); 409 return basic_symbol_iterator(SymbolRef(SymDRI, this)); 410 } 411 412 basic_symbol_iterator XCOFFObjectFile::symbol_end() const { 413 DataRefImpl SymDRI; 414 const uint32_t NumberOfSymbolTableEntries = getNumberOfSymbolTableEntries(); 415 SymDRI.p = getSymbolEntryAddressByIndex(NumberOfSymbolTableEntries); 416 return basic_symbol_iterator(SymbolRef(SymDRI, this)); 417 } 418 419 section_iterator XCOFFObjectFile::section_begin() const { 420 DataRefImpl DRI; 421 DRI.p = getSectionHeaderTableAddress(); 422 return section_iterator(SectionRef(DRI, this)); 423 } 424 425 section_iterator XCOFFObjectFile::section_end() const { 426 DataRefImpl DRI; 427 DRI.p = getWithOffset(getSectionHeaderTableAddress(), 428 getNumberOfSections() * getSectionHeaderSize()); 429 return section_iterator(SectionRef(DRI, this)); 430 } 431 432 uint8_t XCOFFObjectFile::getBytesInAddress() const { return is64Bit() ? 8 : 4; } 433 434 StringRef XCOFFObjectFile::getFileFormatName() const { 435 return is64Bit() ? "aix5coff64-rs6000" : "aixcoff-rs6000"; 436 } 437 438 Triple::ArchType XCOFFObjectFile::getArch() const { 439 return is64Bit() ? Triple::ppc64 : Triple::ppc; 440 } 441 442 SubtargetFeatures XCOFFObjectFile::getFeatures() const { 443 return SubtargetFeatures(); 444 } 445 446 bool XCOFFObjectFile::isRelocatableObject() const { 447 if (is64Bit()) 448 return !(fileHeader64()->Flags & NoRelMask); 449 return !(fileHeader32()->Flags & NoRelMask); 450 } 451 452 Expected<uint64_t> XCOFFObjectFile::getStartAddress() const { 453 // TODO FIXME Should get from auxiliary_header->o_entry when support for the 454 // auxiliary_header is added. 455 return 0; 456 } 457 458 StringRef XCOFFObjectFile::mapDebugSectionName(StringRef Name) const { 459 return StringSwitch<StringRef>(Name) 460 .Case("dwinfo", "debug_info") 461 .Case("dwline", "debug_line") 462 .Case("dwpbnms", "debug_pubnames") 463 .Case("dwpbtyp", "debug_pubtypes") 464 .Case("dwarnge", "debug_aranges") 465 .Case("dwabrev", "debug_abbrev") 466 .Case("dwstr", "debug_str") 467 .Case("dwrnges", "debug_ranges") 468 .Case("dwloc", "debug_loc") 469 .Case("dwframe", "debug_frame") 470 .Case("dwmac", "debug_macinfo") 471 .Default(Name); 472 } 473 474 size_t XCOFFObjectFile::getFileHeaderSize() const { 475 return is64Bit() ? sizeof(XCOFFFileHeader64) : sizeof(XCOFFFileHeader32); 476 } 477 478 size_t XCOFFObjectFile::getSectionHeaderSize() const { 479 return is64Bit() ? sizeof(XCOFFSectionHeader64) : 480 sizeof(XCOFFSectionHeader32); 481 } 482 483 bool XCOFFObjectFile::is64Bit() const { 484 return Binary::ID_XCOFF64 == getType(); 485 } 486 487 uint16_t XCOFFObjectFile::getMagic() const { 488 return is64Bit() ? fileHeader64()->Magic : fileHeader32()->Magic; 489 } 490 491 Expected<DataRefImpl> XCOFFObjectFile::getSectionByNum(int16_t Num) const { 492 if (Num <= 0 || Num > getNumberOfSections()) 493 return errorCodeToError(object_error::invalid_section_index); 494 495 DataRefImpl DRI; 496 DRI.p = getWithOffset(getSectionHeaderTableAddress(), 497 getSectionHeaderSize() * (Num - 1)); 498 return DRI; 499 } 500 501 Expected<StringRef> 502 XCOFFObjectFile::getSymbolSectionName(XCOFFSymbolRef SymEntPtr) const { 503 const int16_t SectionNum = SymEntPtr.getSectionNumber(); 504 505 switch (SectionNum) { 506 case XCOFF::N_DEBUG: 507 return "N_DEBUG"; 508 case XCOFF::N_ABS: 509 return "N_ABS"; 510 case XCOFF::N_UNDEF: 511 return "N_UNDEF"; 512 default: 513 Expected<DataRefImpl> SecRef = getSectionByNum(SectionNum); 514 if (SecRef) 515 return generateXCOFFFixedNameStringRef( 516 getSectionNameInternal(SecRef.get())); 517 return SecRef.takeError(); 518 } 519 } 520 521 unsigned XCOFFObjectFile::getSymbolSectionID(SymbolRef Sym) const { 522 XCOFFSymbolRef XCOFFSymRef(Sym.getRawDataRefImpl(), this); 523 return XCOFFSymRef.getSectionNumber(); 524 } 525 526 bool XCOFFObjectFile::isReservedSectionNumber(int16_t SectionNumber) { 527 return (SectionNumber <= 0 && SectionNumber >= -2); 528 } 529 530 uint16_t XCOFFObjectFile::getNumberOfSections() const { 531 return is64Bit() ? fileHeader64()->NumberOfSections 532 : fileHeader32()->NumberOfSections; 533 } 534 535 int32_t XCOFFObjectFile::getTimeStamp() const { 536 return is64Bit() ? fileHeader64()->TimeStamp : fileHeader32()->TimeStamp; 537 } 538 539 uint16_t XCOFFObjectFile::getOptionalHeaderSize() const { 540 return is64Bit() ? fileHeader64()->AuxHeaderSize 541 : fileHeader32()->AuxHeaderSize; 542 } 543 544 uint32_t XCOFFObjectFile::getSymbolTableOffset32() const { 545 return fileHeader32()->SymbolTableOffset; 546 } 547 548 int32_t XCOFFObjectFile::getRawNumberOfSymbolTableEntries32() const { 549 // As far as symbol table size is concerned, if this field is negative it is 550 // to be treated as a 0. However since this field is also used for printing we 551 // don't want to truncate any negative values. 552 return fileHeader32()->NumberOfSymTableEntries; 553 } 554 555 uint32_t XCOFFObjectFile::getLogicalNumberOfSymbolTableEntries32() const { 556 return (fileHeader32()->NumberOfSymTableEntries >= 0 557 ? fileHeader32()->NumberOfSymTableEntries 558 : 0); 559 } 560 561 uint64_t XCOFFObjectFile::getSymbolTableOffset64() const { 562 return fileHeader64()->SymbolTableOffset; 563 } 564 565 uint32_t XCOFFObjectFile::getNumberOfSymbolTableEntries64() const { 566 return fileHeader64()->NumberOfSymTableEntries; 567 } 568 569 uint32_t XCOFFObjectFile::getNumberOfSymbolTableEntries() const { 570 return is64Bit() ? getNumberOfSymbolTableEntries64() 571 : getLogicalNumberOfSymbolTableEntries32(); 572 } 573 574 uintptr_t XCOFFObjectFile::getEndOfSymbolTableAddress() const { 575 const uint32_t NumberOfSymTableEntries = getNumberOfSymbolTableEntries(); 576 return getWithOffset(reinterpret_cast<uintptr_t>(SymbolTblPtr), 577 XCOFF::SymbolTableEntrySize * NumberOfSymTableEntries); 578 } 579 580 void XCOFFObjectFile::checkSymbolEntryPointer(uintptr_t SymbolEntPtr) const { 581 if (SymbolEntPtr < reinterpret_cast<uintptr_t>(SymbolTblPtr)) 582 report_fatal_error("Symbol table entry is outside of symbol table."); 583 584 if (SymbolEntPtr >= getEndOfSymbolTableAddress()) 585 report_fatal_error("Symbol table entry is outside of symbol table."); 586 587 ptrdiff_t Offset = reinterpret_cast<const char *>(SymbolEntPtr) - 588 reinterpret_cast<const char *>(SymbolTblPtr); 589 590 if (Offset % XCOFF::SymbolTableEntrySize != 0) 591 report_fatal_error( 592 "Symbol table entry position is not valid inside of symbol table."); 593 } 594 595 uint32_t XCOFFObjectFile::getSymbolIndex(uintptr_t SymbolEntPtr) const { 596 return (reinterpret_cast<const char *>(SymbolEntPtr) - 597 reinterpret_cast<const char *>(SymbolTblPtr)) / 598 XCOFF::SymbolTableEntrySize; 599 } 600 601 uintptr_t XCOFFObjectFile::getSymbolEntryAddressByIndex(uint32_t Index) const { 602 return getAdvancedSymbolEntryAddress( 603 reinterpret_cast<uintptr_t>(getPointerToSymbolTable()), Index); 604 } 605 606 Expected<StringRef> 607 XCOFFObjectFile::getSymbolNameByIndex(uint32_t Index) const { 608 const uint32_t NumberOfSymTableEntries = getNumberOfSymbolTableEntries(); 609 610 if (Index >= NumberOfSymTableEntries) 611 return errorCodeToError(object_error::invalid_symbol_index); 612 613 DataRefImpl SymDRI; 614 SymDRI.p = getSymbolEntryAddressByIndex(Index); 615 return getSymbolName(SymDRI); 616 } 617 618 uint16_t XCOFFObjectFile::getFlags() const { 619 return is64Bit() ? fileHeader64()->Flags : fileHeader32()->Flags; 620 } 621 622 const char *XCOFFObjectFile::getSectionNameInternal(DataRefImpl Sec) const { 623 return is64Bit() ? toSection64(Sec)->Name : toSection32(Sec)->Name; 624 } 625 626 uintptr_t XCOFFObjectFile::getSectionHeaderTableAddress() const { 627 return reinterpret_cast<uintptr_t>(SectionHeaderTable); 628 } 629 630 int32_t XCOFFObjectFile::getSectionFlags(DataRefImpl Sec) const { 631 return is64Bit() ? toSection64(Sec)->Flags : toSection32(Sec)->Flags; 632 } 633 634 XCOFFObjectFile::XCOFFObjectFile(unsigned int Type, MemoryBufferRef Object) 635 : ObjectFile(Type, Object) { 636 assert(Type == Binary::ID_XCOFF32 || Type == Binary::ID_XCOFF64); 637 } 638 639 ArrayRef<XCOFFSectionHeader64> XCOFFObjectFile::sections64() const { 640 assert(is64Bit() && "64-bit interface called for non 64-bit file."); 641 const XCOFFSectionHeader64 *TablePtr = sectionHeaderTable64(); 642 return ArrayRef<XCOFFSectionHeader64>(TablePtr, 643 TablePtr + getNumberOfSections()); 644 } 645 646 ArrayRef<XCOFFSectionHeader32> XCOFFObjectFile::sections32() const { 647 assert(!is64Bit() && "32-bit interface called for non 32-bit file."); 648 const XCOFFSectionHeader32 *TablePtr = sectionHeaderTable32(); 649 return ArrayRef<XCOFFSectionHeader32>(TablePtr, 650 TablePtr + getNumberOfSections()); 651 } 652 653 // In an XCOFF32 file, when the field value is 65535, then an STYP_OVRFLO 654 // section header contains the actual count of relocation entries in the s_paddr 655 // field. STYP_OVRFLO headers contain the section index of their corresponding 656 // sections as their raw "NumberOfRelocations" field value. 657 Expected<uint32_t> XCOFFObjectFile::getLogicalNumberOfRelocationEntries( 658 const XCOFFSectionHeader32 &Sec) const { 659 660 uint16_t SectionIndex = &Sec - sectionHeaderTable32() + 1; 661 662 if (Sec.NumberOfRelocations < XCOFF::RelocOverflow) 663 return Sec.NumberOfRelocations; 664 for (const auto &Sec : sections32()) { 665 if (Sec.Flags == XCOFF::STYP_OVRFLO && 666 Sec.NumberOfRelocations == SectionIndex) 667 return Sec.PhysicalAddress; 668 } 669 return errorCodeToError(object_error::parse_failed); 670 } 671 672 Expected<ArrayRef<XCOFFRelocation32>> 673 XCOFFObjectFile::relocations(const XCOFFSectionHeader32 &Sec) const { 674 uintptr_t RelocAddr = getWithOffset(reinterpret_cast<uintptr_t>(FileHeader), 675 Sec.FileOffsetToRelocationInfo); 676 auto NumRelocEntriesOrErr = getLogicalNumberOfRelocationEntries(Sec); 677 if (Error E = NumRelocEntriesOrErr.takeError()) 678 return std::move(E); 679 680 uint32_t NumRelocEntries = NumRelocEntriesOrErr.get(); 681 682 static_assert( 683 sizeof(XCOFFRelocation32) == XCOFF::RelocationSerializationSize32, ""); 684 auto RelocationOrErr = 685 getObject<XCOFFRelocation32>(Data, reinterpret_cast<void *>(RelocAddr), 686 NumRelocEntries * sizeof(XCOFFRelocation32)); 687 if (Error E = RelocationOrErr.takeError()) 688 return std::move(E); 689 690 const XCOFFRelocation32 *StartReloc = RelocationOrErr.get(); 691 692 return ArrayRef<XCOFFRelocation32>(StartReloc, StartReloc + NumRelocEntries); 693 } 694 695 Expected<XCOFFStringTable> 696 XCOFFObjectFile::parseStringTable(const XCOFFObjectFile *Obj, uint64_t Offset) { 697 // If there is a string table, then the buffer must contain at least 4 bytes 698 // for the string table's size. Not having a string table is not an error. 699 if (Error E = Binary::checkOffset( 700 Obj->Data, reinterpret_cast<uintptr_t>(Obj->base() + Offset), 4)) { 701 consumeError(std::move(E)); 702 return XCOFFStringTable{0, nullptr}; 703 } 704 705 // Read the size out of the buffer. 706 uint32_t Size = support::endian::read32be(Obj->base() + Offset); 707 708 // If the size is less then 4, then the string table is just a size and no 709 // string data. 710 if (Size <= 4) 711 return XCOFFStringTable{4, nullptr}; 712 713 auto StringTableOrErr = 714 getObject<char>(Obj->Data, Obj->base() + Offset, Size); 715 if (Error E = StringTableOrErr.takeError()) 716 return std::move(E); 717 718 const char *StringTablePtr = StringTableOrErr.get(); 719 if (StringTablePtr[Size - 1] != '\0') 720 return errorCodeToError(object_error::string_table_non_null_end); 721 722 return XCOFFStringTable{Size, StringTablePtr}; 723 } 724 725 Expected<std::unique_ptr<XCOFFObjectFile>> 726 XCOFFObjectFile::create(unsigned Type, MemoryBufferRef MBR) { 727 // Can't use std::make_unique because of the private constructor. 728 std::unique_ptr<XCOFFObjectFile> Obj; 729 Obj.reset(new XCOFFObjectFile(Type, MBR)); 730 731 uint64_t CurOffset = 0; 732 const auto *Base = Obj->base(); 733 MemoryBufferRef Data = Obj->Data; 734 735 // Parse file header. 736 auto FileHeaderOrErr = 737 getObject<void>(Data, Base + CurOffset, Obj->getFileHeaderSize()); 738 if (Error E = FileHeaderOrErr.takeError()) 739 return std::move(E); 740 Obj->FileHeader = FileHeaderOrErr.get(); 741 742 CurOffset += Obj->getFileHeaderSize(); 743 // TODO FIXME we don't have support for an optional header yet, so just skip 744 // past it. 745 CurOffset += Obj->getOptionalHeaderSize(); 746 747 // Parse the section header table if it is present. 748 if (Obj->getNumberOfSections()) { 749 auto SecHeadersOrErr = getObject<void>(Data, Base + CurOffset, 750 Obj->getNumberOfSections() * 751 Obj->getSectionHeaderSize()); 752 if (Error E = SecHeadersOrErr.takeError()) 753 return std::move(E); 754 Obj->SectionHeaderTable = SecHeadersOrErr.get(); 755 } 756 757 const uint32_t NumberOfSymbolTableEntries = 758 Obj->getNumberOfSymbolTableEntries(); 759 760 // If there is no symbol table we are done parsing the memory buffer. 761 if (NumberOfSymbolTableEntries == 0) 762 return std::move(Obj); 763 764 // Parse symbol table. 765 CurOffset = Obj->is64Bit() ? Obj->getSymbolTableOffset64() 766 : Obj->getSymbolTableOffset32(); 767 const uint64_t SymbolTableSize = 768 static_cast<uint64_t>(XCOFF::SymbolTableEntrySize) * 769 NumberOfSymbolTableEntries; 770 auto SymTableOrErr = 771 getObject<void *>(Data, Base + CurOffset, SymbolTableSize); 772 if (Error E = SymTableOrErr.takeError()) 773 return std::move(E); 774 Obj->SymbolTblPtr = SymTableOrErr.get(); 775 CurOffset += SymbolTableSize; 776 777 // Parse String table. 778 Expected<XCOFFStringTable> StringTableOrErr = 779 parseStringTable(Obj.get(), CurOffset); 780 if (Error E = StringTableOrErr.takeError()) 781 return std::move(E); 782 Obj->StringTable = StringTableOrErr.get(); 783 784 return std::move(Obj); 785 } 786 787 Expected<std::unique_ptr<ObjectFile>> 788 ObjectFile::createXCOFFObjectFile(MemoryBufferRef MemBufRef, 789 unsigned FileType) { 790 return XCOFFObjectFile::create(FileType, MemBufRef); 791 } 792 793 bool XCOFFSymbolRef::isFunction() const { 794 if (!isCsectSymbol()) 795 return false; 796 797 if (getSymbolType() & FunctionSym) 798 return true; 799 800 Expected<XCOFFCsectAuxRef> ExpCsectAuxEnt = getXCOFFCsectAuxRef(); 801 if (!ExpCsectAuxEnt) 802 return false; 803 804 const XCOFFCsectAuxRef CsectAuxRef = ExpCsectAuxEnt.get(); 805 806 // A function definition should be a label definition. 807 // FIXME: This is not necessarily the case when -ffunction-sections is 808 // enabled. 809 if (!CsectAuxRef.isLabel()) 810 return false; 811 812 if (CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_PR) 813 return false; 814 815 const int16_t SectNum = getSectionNumber(); 816 Expected<DataRefImpl> SI = OwningObjectPtr->getSectionByNum(SectNum); 817 if (!SI) { 818 // If we could not get the section, then this symbol should not be 819 // a function. So consume the error and return `false` to move on. 820 consumeError(SI.takeError()); 821 return false; 822 } 823 824 return (OwningObjectPtr->getSectionFlags(SI.get()) & XCOFF::STYP_TEXT); 825 } 826 827 bool XCOFFSymbolRef::isCsectSymbol() const { 828 XCOFF::StorageClass SC = getStorageClass(); 829 return (SC == XCOFF::C_EXT || SC == XCOFF::C_WEAKEXT || 830 SC == XCOFF::C_HIDEXT); 831 } 832 833 Expected<XCOFFCsectAuxRef> XCOFFSymbolRef::getXCOFFCsectAuxRef() const { 834 assert(isCsectSymbol() && 835 "Calling csect symbol interface with a non-csect symbol."); 836 837 uint8_t NumberOfAuxEntries = getNumberOfAuxEntries(); 838 839 Expected<StringRef> NameOrErr = getName(); 840 if (auto Err = NameOrErr.takeError()) 841 return std::move(Err); 842 843 if (!NumberOfAuxEntries) { 844 return createStringError(object_error::parse_failed, 845 "csect symbol \"" + *NameOrErr + 846 "\" contains no auxiliary entry"); 847 } 848 849 if (!OwningObjectPtr->is64Bit()) { 850 // In XCOFF32, the csect auxilliary entry is always the last auxiliary 851 // entry for the symbol. 852 uintptr_t AuxAddr = XCOFFObjectFile::getAdvancedSymbolEntryAddress( 853 getEntryAddress(), NumberOfAuxEntries); 854 return XCOFFCsectAuxRef(viewAs<XCOFFCsectAuxEnt32>(AuxAddr)); 855 } 856 857 // XCOFF64 uses SymbolAuxType to identify the auxiliary entry type. 858 // We need to iterate through all the auxiliary entries to find it. 859 for (uint8_t Index = NumberOfAuxEntries; Index > 0; --Index) { 860 uintptr_t AuxAddr = XCOFFObjectFile::getAdvancedSymbolEntryAddress( 861 getEntryAddress(), Index); 862 if (*OwningObjectPtr->getSymbolAuxType(AuxAddr) == 863 XCOFF::SymbolAuxType::AUX_CSECT) { 864 #ifndef NDEBUG 865 OwningObjectPtr->checkSymbolEntryPointer(AuxAddr); 866 #endif 867 return XCOFFCsectAuxRef(viewAs<XCOFFCsectAuxEnt64>(AuxAddr)); 868 } 869 } 870 871 return createStringError( 872 object_error::parse_failed, 873 "a csect auxiliary entry is not found for symbol \"" + *NameOrErr + "\""); 874 } 875 876 Expected<StringRef> XCOFFSymbolRef::getName() const { 877 // A storage class value with the high-order bit on indicates that the name is 878 // a symbolic debugger stabstring. 879 if (getStorageClass() & 0x80) 880 return StringRef("Unimplemented Debug Name"); 881 882 if (Entry32) { 883 if (Entry32->NameInStrTbl.Magic != XCOFFSymbolRef::NAME_IN_STR_TBL_MAGIC) 884 return generateXCOFFFixedNameStringRef(Entry32->SymbolName); 885 886 return OwningObjectPtr->getStringTableEntry(Entry32->NameInStrTbl.Offset); 887 } 888 889 return OwningObjectPtr->getStringTableEntry(Entry64->Offset); 890 } 891 892 // Explictly instantiate template classes. 893 template struct XCOFFSectionHeader<XCOFFSectionHeader32>; 894 template struct XCOFFSectionHeader<XCOFFSectionHeader64>; 895 896 bool doesXCOFFTracebackTableBegin(ArrayRef<uint8_t> Bytes) { 897 if (Bytes.size() < 4) 898 return false; 899 900 return support::endian::read32be(Bytes.data()) == 0; 901 } 902 903 #define GETVALUEWITHMASK(X) (Data & (TracebackTable::X)) 904 #define GETVALUEWITHMASKSHIFT(X, S) \ 905 ((Data & (TracebackTable::X)) >> (TracebackTable::S)) 906 907 Expected<TBVectorExt> TBVectorExt::create(StringRef TBvectorStrRef) { 908 Error Err = Error::success(); 909 TBVectorExt TBTVecExt(TBvectorStrRef, Err); 910 if (Err) 911 return std::move(Err); 912 return TBTVecExt; 913 } 914 915 TBVectorExt::TBVectorExt(StringRef TBvectorStrRef, Error &Err) { 916 const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(TBvectorStrRef.data()); 917 Data = support::endian::read16be(Ptr); 918 uint32_t VecParmsTypeValue = support::endian::read32be(Ptr + 2); 919 unsigned ParmsNum = 920 GETVALUEWITHMASKSHIFT(NumberOfVectorParmsMask, NumberOfVectorParmsShift); 921 922 ErrorAsOutParameter EAO(&Err); 923 Expected<SmallString<32>> VecParmsTypeOrError = 924 parseVectorParmsType(VecParmsTypeValue, ParmsNum); 925 if (!VecParmsTypeOrError) 926 Err = VecParmsTypeOrError.takeError(); 927 else 928 VecParmsInfo = VecParmsTypeOrError.get(); 929 } 930 931 uint8_t TBVectorExt::getNumberOfVRSaved() const { 932 return GETVALUEWITHMASKSHIFT(NumberOfVRSavedMask, NumberOfVRSavedShift); 933 } 934 935 bool TBVectorExt::isVRSavedOnStack() const { 936 return GETVALUEWITHMASK(IsVRSavedOnStackMask); 937 } 938 939 bool TBVectorExt::hasVarArgs() const { 940 return GETVALUEWITHMASK(HasVarArgsMask); 941 } 942 943 uint8_t TBVectorExt::getNumberOfVectorParms() const { 944 return GETVALUEWITHMASKSHIFT(NumberOfVectorParmsMask, 945 NumberOfVectorParmsShift); 946 } 947 948 bool TBVectorExt::hasVMXInstruction() const { 949 return GETVALUEWITHMASK(HasVMXInstructionMask); 950 } 951 #undef GETVALUEWITHMASK 952 #undef GETVALUEWITHMASKSHIFT 953 954 Expected<XCOFFTracebackTable> XCOFFTracebackTable::create(const uint8_t *Ptr, 955 uint64_t &Size) { 956 Error Err = Error::success(); 957 XCOFFTracebackTable TBT(Ptr, Size, Err); 958 if (Err) 959 return std::move(Err); 960 return TBT; 961 } 962 963 XCOFFTracebackTable::XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size, 964 Error &Err) 965 : TBPtr(Ptr) { 966 ErrorAsOutParameter EAO(&Err); 967 DataExtractor DE(ArrayRef<uint8_t>(Ptr, Size), /*IsLittleEndian=*/false, 968 /*AddressSize=*/0); 969 DataExtractor::Cursor Cur(/*Offset=*/0); 970 971 // Skip 8 bytes of mandatory fields. 972 DE.getU64(Cur); 973 974 unsigned FixedParmsNum = getNumberOfFixedParms(); 975 unsigned FloatingParmsNum = getNumberOfFPParms(); 976 uint32_t ParamsTypeValue = 0; 977 978 // Begin to parse optional fields. 979 if (Cur && (FixedParmsNum + FloatingParmsNum) > 0) 980 ParamsTypeValue = DE.getU32(Cur); 981 982 if (Cur && hasTraceBackTableOffset()) 983 TraceBackTableOffset = DE.getU32(Cur); 984 985 if (Cur && isInterruptHandler()) 986 HandlerMask = DE.getU32(Cur); 987 988 if (Cur && hasControlledStorage()) { 989 NumOfCtlAnchors = DE.getU32(Cur); 990 if (Cur && NumOfCtlAnchors) { 991 SmallVector<uint32_t, 8> Disp; 992 Disp.reserve(NumOfCtlAnchors.getValue()); 993 for (uint32_t I = 0; I < NumOfCtlAnchors && Cur; ++I) 994 Disp.push_back(DE.getU32(Cur)); 995 if (Cur) 996 ControlledStorageInfoDisp = std::move(Disp); 997 } 998 } 999 1000 if (Cur && isFuncNamePresent()) { 1001 uint16_t FunctionNameLen = DE.getU16(Cur); 1002 if (Cur) 1003 FunctionName = DE.getBytes(Cur, FunctionNameLen); 1004 } 1005 1006 if (Cur && isAllocaUsed()) 1007 AllocaRegister = DE.getU8(Cur); 1008 1009 unsigned VectorParmsNum = 0; 1010 if (Cur && hasVectorInfo()) { 1011 StringRef VectorExtRef = DE.getBytes(Cur, 6); 1012 if (Cur) { 1013 Expected<TBVectorExt> TBVecExtOrErr = TBVectorExt::create(VectorExtRef); 1014 if (!TBVecExtOrErr) { 1015 Err = TBVecExtOrErr.takeError(); 1016 return; 1017 } 1018 VecExt = TBVecExtOrErr.get(); 1019 VectorParmsNum = VecExt.getValue().getNumberOfVectorParms(); 1020 } 1021 } 1022 1023 // As long as there is no fixed-point or floating-point parameter, this 1024 // field remains not present even when hasVectorInfo gives true and 1025 // indicates the presence of vector parameters. 1026 if (Cur && (FixedParmsNum + FloatingParmsNum) > 0) { 1027 Expected<SmallString<32>> ParmsTypeOrError = 1028 hasVectorInfo() 1029 ? parseParmsTypeWithVecInfo(ParamsTypeValue, FixedParmsNum, 1030 FloatingParmsNum, VectorParmsNum) 1031 : parseParmsType(ParamsTypeValue, FixedParmsNum, FloatingParmsNum); 1032 1033 if (!ParmsTypeOrError) { 1034 Err = ParmsTypeOrError.takeError(); 1035 return; 1036 } 1037 ParmsType = ParmsTypeOrError.get(); 1038 } 1039 1040 if (Cur && hasExtensionTable()) 1041 ExtensionTable = DE.getU8(Cur); 1042 1043 if (!Cur) 1044 Err = Cur.takeError(); 1045 1046 Size = Cur.tell(); 1047 } 1048 1049 #define GETBITWITHMASK(P, X) \ 1050 (support::endian::read32be(TBPtr + (P)) & (TracebackTable::X)) 1051 #define GETBITWITHMASKSHIFT(P, X, S) \ 1052 ((support::endian::read32be(TBPtr + (P)) & (TracebackTable::X)) >> \ 1053 (TracebackTable::S)) 1054 1055 uint8_t XCOFFTracebackTable::getVersion() const { 1056 return GETBITWITHMASKSHIFT(0, VersionMask, VersionShift); 1057 } 1058 1059 uint8_t XCOFFTracebackTable::getLanguageID() const { 1060 return GETBITWITHMASKSHIFT(0, LanguageIdMask, LanguageIdShift); 1061 } 1062 1063 bool XCOFFTracebackTable::isGlobalLinkage() const { 1064 return GETBITWITHMASK(0, IsGlobaLinkageMask); 1065 } 1066 1067 bool XCOFFTracebackTable::isOutOfLineEpilogOrPrologue() const { 1068 return GETBITWITHMASK(0, IsOutOfLineEpilogOrPrologueMask); 1069 } 1070 1071 bool XCOFFTracebackTable::hasTraceBackTableOffset() const { 1072 return GETBITWITHMASK(0, HasTraceBackTableOffsetMask); 1073 } 1074 1075 bool XCOFFTracebackTable::isInternalProcedure() const { 1076 return GETBITWITHMASK(0, IsInternalProcedureMask); 1077 } 1078 1079 bool XCOFFTracebackTable::hasControlledStorage() const { 1080 return GETBITWITHMASK(0, HasControlledStorageMask); 1081 } 1082 1083 bool XCOFFTracebackTable::isTOCless() const { 1084 return GETBITWITHMASK(0, IsTOClessMask); 1085 } 1086 1087 bool XCOFFTracebackTable::isFloatingPointPresent() const { 1088 return GETBITWITHMASK(0, IsFloatingPointPresentMask); 1089 } 1090 1091 bool XCOFFTracebackTable::isFloatingPointOperationLogOrAbortEnabled() const { 1092 return GETBITWITHMASK(0, IsFloatingPointOperationLogOrAbortEnabledMask); 1093 } 1094 1095 bool XCOFFTracebackTable::isInterruptHandler() const { 1096 return GETBITWITHMASK(0, IsInterruptHandlerMask); 1097 } 1098 1099 bool XCOFFTracebackTable::isFuncNamePresent() const { 1100 return GETBITWITHMASK(0, IsFunctionNamePresentMask); 1101 } 1102 1103 bool XCOFFTracebackTable::isAllocaUsed() const { 1104 return GETBITWITHMASK(0, IsAllocaUsedMask); 1105 } 1106 1107 uint8_t XCOFFTracebackTable::getOnConditionDirective() const { 1108 return GETBITWITHMASKSHIFT(0, OnConditionDirectiveMask, 1109 OnConditionDirectiveShift); 1110 } 1111 1112 bool XCOFFTracebackTable::isCRSaved() const { 1113 return GETBITWITHMASK(0, IsCRSavedMask); 1114 } 1115 1116 bool XCOFFTracebackTable::isLRSaved() const { 1117 return GETBITWITHMASK(0, IsLRSavedMask); 1118 } 1119 1120 bool XCOFFTracebackTable::isBackChainStored() const { 1121 return GETBITWITHMASK(4, IsBackChainStoredMask); 1122 } 1123 1124 bool XCOFFTracebackTable::isFixup() const { 1125 return GETBITWITHMASK(4, IsFixupMask); 1126 } 1127 1128 uint8_t XCOFFTracebackTable::getNumOfFPRsSaved() const { 1129 return GETBITWITHMASKSHIFT(4, FPRSavedMask, FPRSavedShift); 1130 } 1131 1132 bool XCOFFTracebackTable::hasExtensionTable() const { 1133 return GETBITWITHMASK(4, HasExtensionTableMask); 1134 } 1135 1136 bool XCOFFTracebackTable::hasVectorInfo() const { 1137 return GETBITWITHMASK(4, HasVectorInfoMask); 1138 } 1139 1140 uint8_t XCOFFTracebackTable::getNumOfGPRsSaved() const { 1141 return GETBITWITHMASKSHIFT(4, GPRSavedMask, GPRSavedShift); 1142 } 1143 1144 uint8_t XCOFFTracebackTable::getNumberOfFixedParms() const { 1145 return GETBITWITHMASKSHIFT(4, NumberOfFixedParmsMask, 1146 NumberOfFixedParmsShift); 1147 } 1148 1149 uint8_t XCOFFTracebackTable::getNumberOfFPParms() const { 1150 return GETBITWITHMASKSHIFT(4, NumberOfFloatingPointParmsMask, 1151 NumberOfFloatingPointParmsShift); 1152 } 1153 1154 bool XCOFFTracebackTable::hasParmsOnStack() const { 1155 return GETBITWITHMASK(4, HasParmsOnStackMask); 1156 } 1157 1158 #undef GETBITWITHMASK 1159 #undef GETBITWITHMASKSHIFT 1160 } // namespace object 1161 } // namespace llvm 1162