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