1 //===--- XCOFFObjectFile.cpp - XCOFF object file implementation -----------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the XCOFFObjectFile class.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Object/XCOFFObjectFile.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/MC/SubtargetFeature.h"
16 #include "llvm/Support/DataExtractor.h"
22 using namespace XCOFF
;
26 static const uint8_t FunctionSym
= 0x20;
27 static const uint16_t NoRelMask
= 0x0001;
28 static const size_t SymbolAuxTypeOffset
= 17;
30 // Checks that [Ptr, Ptr + Size) bytes fall inside the memory buffer
31 // 'M'. Returns a pointer to the underlying object on success.
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
))
38 return reinterpret_cast<const T
*>(Addr
);
41 static uintptr_t getWithOffset(uintptr_t Base
, ptrdiff_t Offset
) {
42 return reinterpret_cast<uintptr_t>(reinterpret_cast<const char *>(Base
) +
46 template <typename T
> static const T
*viewAs(uintptr_t in
) {
47 return reinterpret_cast<const T
*>(in
);
50 static StringRef
generateXCOFFFixedNameStringRef(const char *Name
) {
52 static_cast<const char *>(memchr(Name
, '\0', XCOFF::NameSize
));
53 return NulCharPtr
? StringRef(Name
, NulCharPtr
- Name
)
54 : StringRef(Name
, XCOFF::NameSize
);
57 template <typename T
> StringRef XCOFFSectionHeader
<T
>::getName() const {
58 const T
&DerivedXCOFFSectionHeader
= static_cast<const T
&>(*this);
59 return generateXCOFFFixedNameStringRef(DerivedXCOFFSectionHeader
.Name
);
62 template <typename T
> uint16_t XCOFFSectionHeader
<T
>::getSectionType() const {
63 const T
&DerivedXCOFFSectionHeader
= static_cast<const T
&>(*this);
64 return DerivedXCOFFSectionHeader
.Flags
& SectionFlagsTypeMask
;
68 bool XCOFFSectionHeader
<T
>::isReservedSectionType() const {
69 return getSectionType() & SectionFlagsReservedMask
;
72 template <typename AddressType
>
73 bool XCOFFRelocation
<AddressType
>::isRelocationSigned() const {
74 return Info
& XR_SIGN_INDICATOR_MASK
;
77 template <typename AddressType
>
78 bool XCOFFRelocation
<AddressType
>::isFixupIndicated() const {
79 return Info
& XR_FIXUP_INDICATOR_MASK
;
82 template <typename AddressType
>
83 uint8_t XCOFFRelocation
<AddressType
>::getRelocatedLength() const {
84 // The relocation encodes the bit length being relocated minus 1. Add back
85 // the 1 to get the actual length being relocated.
86 return (Info
& XR_BIASED_LENGTH_MASK
) + 1;
90 XCOFFObjectFile::getAdvancedSymbolEntryAddress(uintptr_t CurrentAddress
,
92 return getWithOffset(CurrentAddress
, Distance
* XCOFF::SymbolTableEntrySize
);
95 const XCOFF::SymbolAuxType
*
96 XCOFFObjectFile::getSymbolAuxType(uintptr_t AuxEntryAddress
) const {
97 assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
98 return viewAs
<XCOFF::SymbolAuxType
>(
99 getWithOffset(AuxEntryAddress
, SymbolAuxTypeOffset
));
102 void XCOFFObjectFile::checkSectionAddress(uintptr_t Addr
,
103 uintptr_t TableAddress
) const {
104 if (Addr
< TableAddress
)
105 report_fatal_error("Section header outside of section header table.");
107 uintptr_t Offset
= Addr
- TableAddress
;
108 if (Offset
>= getSectionHeaderSize() * getNumberOfSections())
109 report_fatal_error("Section header outside of section header table.");
111 if (Offset
% getSectionHeaderSize() != 0)
113 "Section header pointer does not point to a valid section header.");
116 const XCOFFSectionHeader32
*
117 XCOFFObjectFile::toSection32(DataRefImpl Ref
) const {
118 assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
120 checkSectionAddress(Ref
.p
, getSectionHeaderTableAddress());
122 return viewAs
<XCOFFSectionHeader32
>(Ref
.p
);
125 const XCOFFSectionHeader64
*
126 XCOFFObjectFile::toSection64(DataRefImpl Ref
) const {
127 assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
129 checkSectionAddress(Ref
.p
, getSectionHeaderTableAddress());
131 return viewAs
<XCOFFSectionHeader64
>(Ref
.p
);
134 XCOFFSymbolRef
XCOFFObjectFile::toSymbolRef(DataRefImpl Ref
) const {
135 assert(Ref
.p
!= 0 && "Symbol table pointer can not be nullptr!");
137 checkSymbolEntryPointer(Ref
.p
);
139 return XCOFFSymbolRef(Ref
, this);
142 const XCOFFFileHeader32
*XCOFFObjectFile::fileHeader32() const {
143 assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
144 return static_cast<const XCOFFFileHeader32
*>(FileHeader
);
147 const XCOFFFileHeader64
*XCOFFObjectFile::fileHeader64() const {
148 assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
149 return static_cast<const XCOFFFileHeader64
*>(FileHeader
);
152 template <typename T
> const T
*XCOFFObjectFile::sectionHeaderTable() const {
153 return static_cast<const T
*>(SectionHeaderTable
);
156 const XCOFFSectionHeader32
*
157 XCOFFObjectFile::sectionHeaderTable32() const {
158 assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
159 return static_cast<const XCOFFSectionHeader32
*>(SectionHeaderTable
);
162 const XCOFFSectionHeader64
*
163 XCOFFObjectFile::sectionHeaderTable64() const {
164 assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
165 return static_cast<const XCOFFSectionHeader64
*>(SectionHeaderTable
);
168 void XCOFFObjectFile::moveSymbolNext(DataRefImpl
&Symb
) const {
169 uintptr_t NextSymbolAddr
= getAdvancedSymbolEntryAddress(
170 Symb
.p
, toSymbolRef(Symb
).getNumberOfAuxEntries() + 1);
172 // This function is used by basic_symbol_iterator, which allows to
173 // point to the end-of-symbol-table address.
174 if (NextSymbolAddr
!= getEndOfSymbolTableAddress())
175 checkSymbolEntryPointer(NextSymbolAddr
);
177 Symb
.p
= NextSymbolAddr
;
181 XCOFFObjectFile::getStringTableEntry(uint32_t Offset
) const {
182 // The byte offset is relative to the start of the string table.
183 // A byte offset value of 0 is a null or zero-length symbol
184 // name. A byte offset in the range 1 to 3 (inclusive) points into the length
185 // field; as a soft-error recovery mechanism, we treat such cases as having an
188 return StringRef(nullptr, 0);
190 if (StringTable
.Data
!= nullptr && StringTable
.Size
> Offset
)
191 return (StringTable
.Data
+ Offset
);
193 return make_error
<GenericBinaryError
>("Bad offset for string table entry",
194 object_error::parse_failed
);
197 StringRef
XCOFFObjectFile::getStringTable() const {
198 // If the size is less than or equal to 4, then the string table contains no
200 return StringRef(StringTable
.Data
,
201 StringTable
.Size
<= 4 ? 0 : StringTable
.Size
);
205 XCOFFObjectFile::getCFileName(const XCOFFFileAuxEnt
*CFileEntPtr
) const {
206 if (CFileEntPtr
->NameInStrTbl
.Magic
!= XCOFFSymbolRef::NAME_IN_STR_TBL_MAGIC
)
207 return generateXCOFFFixedNameStringRef(CFileEntPtr
->Name
);
208 return getStringTableEntry(CFileEntPtr
->NameInStrTbl
.Offset
);
211 Expected
<StringRef
> XCOFFObjectFile::getSymbolName(DataRefImpl Symb
) const {
212 return toSymbolRef(Symb
).getName();
215 Expected
<uint64_t> XCOFFObjectFile::getSymbolAddress(DataRefImpl Symb
) const {
216 return toSymbolRef(Symb
).getValue();
219 uint64_t XCOFFObjectFile::getSymbolValueImpl(DataRefImpl Symb
) const {
220 return toSymbolRef(Symb
).getValue();
223 uint64_t XCOFFObjectFile::getCommonSymbolSizeImpl(DataRefImpl Symb
) const {
225 llvm_unreachable("Not yet implemented!");
229 Expected
<SymbolRef::Type
>
230 XCOFFObjectFile::getSymbolType(DataRefImpl Symb
) const {
231 // TODO: Return the correct symbol type.
232 return SymbolRef::ST_Other
;
235 Expected
<section_iterator
>
236 XCOFFObjectFile::getSymbolSection(DataRefImpl Symb
) const {
237 const int16_t SectNum
= toSymbolRef(Symb
).getSectionNumber();
239 if (isReservedSectionNumber(SectNum
))
240 return section_end();
242 Expected
<DataRefImpl
> ExpSec
= getSectionByNum(SectNum
);
244 return ExpSec
.takeError();
246 return section_iterator(SectionRef(ExpSec
.get(), this));
249 void XCOFFObjectFile::moveSectionNext(DataRefImpl
&Sec
) const {
250 const char *Ptr
= reinterpret_cast<const char *>(Sec
.p
);
251 Sec
.p
= reinterpret_cast<uintptr_t>(Ptr
+ getSectionHeaderSize());
254 Expected
<StringRef
> XCOFFObjectFile::getSectionName(DataRefImpl Sec
) const {
255 return generateXCOFFFixedNameStringRef(getSectionNameInternal(Sec
));
258 uint64_t XCOFFObjectFile::getSectionAddress(DataRefImpl Sec
) const {
259 // Avoid ternary due to failure to convert the ubig32_t value to a unit64_t
262 return toSection64(Sec
)->VirtualAddress
;
264 return toSection32(Sec
)->VirtualAddress
;
267 uint64_t XCOFFObjectFile::getSectionIndex(DataRefImpl Sec
) const {
268 // Section numbers in XCOFF are numbered beginning at 1. A section number of
269 // zero is used to indicate that a symbol is being imported or is undefined.
271 return toSection64(Sec
) - sectionHeaderTable64() + 1;
273 return toSection32(Sec
) - sectionHeaderTable32() + 1;
276 uint64_t XCOFFObjectFile::getSectionSize(DataRefImpl Sec
) const {
277 // Avoid ternary due to failure to convert the ubig32_t value to a unit64_t
280 return toSection64(Sec
)->SectionSize
;
282 return toSection32(Sec
)->SectionSize
;
285 Expected
<ArrayRef
<uint8_t>>
286 XCOFFObjectFile::getSectionContents(DataRefImpl Sec
) const {
287 if (isSectionVirtual(Sec
))
288 return ArrayRef
<uint8_t>();
290 uint64_t OffsetToRaw
;
292 OffsetToRaw
= toSection64(Sec
)->FileOffsetToRawData
;
294 OffsetToRaw
= toSection32(Sec
)->FileOffsetToRawData
;
296 const uint8_t * ContentStart
= base() + OffsetToRaw
;
297 uint64_t SectionSize
= getSectionSize(Sec
);
298 if (checkOffset(Data
, reinterpret_cast<uintptr_t>(ContentStart
), SectionSize
))
299 return make_error
<BinaryError
>();
301 return makeArrayRef(ContentStart
,SectionSize
);
304 uint64_t XCOFFObjectFile::getSectionAlignment(DataRefImpl Sec
) const {
306 llvm_unreachable("Not yet implemented!");
310 bool XCOFFObjectFile::isSectionCompressed(DataRefImpl Sec
) const {
314 bool XCOFFObjectFile::isSectionText(DataRefImpl Sec
) const {
315 return getSectionFlags(Sec
) & XCOFF::STYP_TEXT
;
318 bool XCOFFObjectFile::isSectionData(DataRefImpl Sec
) const {
319 uint32_t Flags
= getSectionFlags(Sec
);
320 return Flags
& (XCOFF::STYP_DATA
| XCOFF::STYP_TDATA
);
323 bool XCOFFObjectFile::isSectionBSS(DataRefImpl Sec
) const {
324 uint32_t Flags
= getSectionFlags(Sec
);
325 return Flags
& (XCOFF::STYP_BSS
| XCOFF::STYP_TBSS
);
328 bool XCOFFObjectFile::isDebugSection(DataRefImpl Sec
) const {
329 uint32_t Flags
= getSectionFlags(Sec
);
330 return Flags
& (XCOFF::STYP_DEBUG
| XCOFF::STYP_DWARF
);
333 bool XCOFFObjectFile::isSectionVirtual(DataRefImpl Sec
) const {
334 return is64Bit() ? toSection64(Sec
)->FileOffsetToRawData
== 0
335 : toSection32(Sec
)->FileOffsetToRawData
== 0;
338 relocation_iterator
XCOFFObjectFile::section_rel_begin(DataRefImpl Sec
) const {
341 const XCOFFSectionHeader64
*SectionEntPtr
= toSection64(Sec
);
342 auto RelocationsOrErr
=
343 relocations
<XCOFFSectionHeader64
, XCOFFRelocation64
>(*SectionEntPtr
);
344 if (Error E
= RelocationsOrErr
.takeError()) {
345 // TODO: report the error up the stack.
346 consumeError(std::move(E
));
347 return relocation_iterator(RelocationRef());
349 Ret
.p
= reinterpret_cast<uintptr_t>(&*RelocationsOrErr
.get().begin());
351 const XCOFFSectionHeader32
*SectionEntPtr
= toSection32(Sec
);
352 auto RelocationsOrErr
=
353 relocations
<XCOFFSectionHeader32
, XCOFFRelocation32
>(*SectionEntPtr
);
354 if (Error E
= RelocationsOrErr
.takeError()) {
355 // TODO: report the error up the stack.
356 consumeError(std::move(E
));
357 return relocation_iterator(RelocationRef());
359 Ret
.p
= reinterpret_cast<uintptr_t>(&*RelocationsOrErr
.get().begin());
361 return relocation_iterator(RelocationRef(Ret
, this));
364 relocation_iterator
XCOFFObjectFile::section_rel_end(DataRefImpl Sec
) const {
367 const XCOFFSectionHeader64
*SectionEntPtr
= toSection64(Sec
);
368 auto RelocationsOrErr
=
369 relocations
<XCOFFSectionHeader64
, XCOFFRelocation64
>(*SectionEntPtr
);
370 if (Error E
= RelocationsOrErr
.takeError()) {
371 // TODO: report the error up the stack.
372 consumeError(std::move(E
));
373 return relocation_iterator(RelocationRef());
375 Ret
.p
= reinterpret_cast<uintptr_t>(&*RelocationsOrErr
.get().end());
377 const XCOFFSectionHeader32
*SectionEntPtr
= toSection32(Sec
);
378 auto RelocationsOrErr
=
379 relocations
<XCOFFSectionHeader32
, XCOFFRelocation32
>(*SectionEntPtr
);
380 if (Error E
= RelocationsOrErr
.takeError()) {
381 // TODO: report the error up the stack.
382 consumeError(std::move(E
));
383 return relocation_iterator(RelocationRef());
385 Ret
.p
= reinterpret_cast<uintptr_t>(&*RelocationsOrErr
.get().end());
387 return relocation_iterator(RelocationRef(Ret
, this));
390 void XCOFFObjectFile::moveRelocationNext(DataRefImpl
&Rel
) const {
392 Rel
.p
= reinterpret_cast<uintptr_t>(viewAs
<XCOFFRelocation64
>(Rel
.p
) + 1);
394 Rel
.p
= reinterpret_cast<uintptr_t>(viewAs
<XCOFFRelocation32
>(Rel
.p
) + 1);
397 uint64_t XCOFFObjectFile::getRelocationOffset(DataRefImpl Rel
) const {
399 const XCOFFRelocation64
*Reloc
= viewAs
<XCOFFRelocation64
>(Rel
.p
);
400 const XCOFFSectionHeader64
*Sec64
= sectionHeaderTable64();
401 const uint64_t RelocAddress
= Reloc
->VirtualAddress
;
402 const uint16_t NumberOfSections
= getNumberOfSections();
403 for (uint16_t I
= 0; I
< NumberOfSections
; ++I
) {
404 // Find which section this relocation belongs to, and get the
405 // relocation offset relative to the start of the section.
406 if (Sec64
->VirtualAddress
<= RelocAddress
&&
407 RelocAddress
< Sec64
->VirtualAddress
+ Sec64
->SectionSize
) {
408 return RelocAddress
- Sec64
->VirtualAddress
;
413 const XCOFFRelocation32
*Reloc
= viewAs
<XCOFFRelocation32
>(Rel
.p
);
414 const XCOFFSectionHeader32
*Sec32
= sectionHeaderTable32();
415 const uint32_t RelocAddress
= Reloc
->VirtualAddress
;
416 const uint16_t NumberOfSections
= getNumberOfSections();
417 for (uint16_t I
= 0; I
< NumberOfSections
; ++I
) {
418 // Find which section this relocation belongs to, and get the
419 // relocation offset relative to the start of the section.
420 if (Sec32
->VirtualAddress
<= RelocAddress
&&
421 RelocAddress
< Sec32
->VirtualAddress
+ Sec32
->SectionSize
) {
422 return RelocAddress
- Sec32
->VirtualAddress
;
427 return InvalidRelocOffset
;
430 symbol_iterator
XCOFFObjectFile::getRelocationSymbol(DataRefImpl Rel
) const {
433 const XCOFFRelocation64
*Reloc
= viewAs
<XCOFFRelocation64
>(Rel
.p
);
434 Index
= Reloc
->SymbolIndex
;
436 if (Index
>= getNumberOfSymbolTableEntries64())
439 const XCOFFRelocation32
*Reloc
= viewAs
<XCOFFRelocation32
>(Rel
.p
);
440 Index
= Reloc
->SymbolIndex
;
442 if (Index
>= getLogicalNumberOfSymbolTableEntries32())
446 SymDRI
.p
= getSymbolEntryAddressByIndex(Index
);
447 return symbol_iterator(SymbolRef(SymDRI
, this));
450 uint64_t XCOFFObjectFile::getRelocationType(DataRefImpl Rel
) const {
452 return viewAs
<XCOFFRelocation64
>(Rel
.p
)->Type
;
453 return viewAs
<XCOFFRelocation32
>(Rel
.p
)->Type
;
456 void XCOFFObjectFile::getRelocationTypeName(
457 DataRefImpl Rel
, SmallVectorImpl
<char> &Result
) const {
460 const XCOFFRelocation64
*Reloc
= viewAs
<XCOFFRelocation64
>(Rel
.p
);
461 Res
= XCOFF::getRelocationTypeString(Reloc
->Type
);
463 const XCOFFRelocation32
*Reloc
= viewAs
<XCOFFRelocation32
>(Rel
.p
);
464 Res
= XCOFF::getRelocationTypeString(Reloc
->Type
);
466 Result
.append(Res
.begin(), Res
.end());
469 Expected
<uint32_t> XCOFFObjectFile::getSymbolFlags(DataRefImpl Symb
) const {
471 // TODO: Return correct symbol flags.
475 basic_symbol_iterator
XCOFFObjectFile::symbol_begin() const {
477 SymDRI
.p
= reinterpret_cast<uintptr_t>(SymbolTblPtr
);
478 return basic_symbol_iterator(SymbolRef(SymDRI
, this));
481 basic_symbol_iterator
XCOFFObjectFile::symbol_end() const {
483 const uint32_t NumberOfSymbolTableEntries
= getNumberOfSymbolTableEntries();
484 SymDRI
.p
= getSymbolEntryAddressByIndex(NumberOfSymbolTableEntries
);
485 return basic_symbol_iterator(SymbolRef(SymDRI
, this));
488 section_iterator
XCOFFObjectFile::section_begin() const {
490 DRI
.p
= getSectionHeaderTableAddress();
491 return section_iterator(SectionRef(DRI
, this));
494 section_iterator
XCOFFObjectFile::section_end() const {
496 DRI
.p
= getWithOffset(getSectionHeaderTableAddress(),
497 getNumberOfSections() * getSectionHeaderSize());
498 return section_iterator(SectionRef(DRI
, this));
501 uint8_t XCOFFObjectFile::getBytesInAddress() const { return is64Bit() ? 8 : 4; }
503 StringRef
XCOFFObjectFile::getFileFormatName() const {
504 return is64Bit() ? "aix5coff64-rs6000" : "aixcoff-rs6000";
507 Triple::ArchType
XCOFFObjectFile::getArch() const {
508 return is64Bit() ? Triple::ppc64
: Triple::ppc
;
511 SubtargetFeatures
XCOFFObjectFile::getFeatures() const {
512 return SubtargetFeatures();
515 bool XCOFFObjectFile::isRelocatableObject() const {
517 return !(fileHeader64()->Flags
& NoRelMask
);
518 return !(fileHeader32()->Flags
& NoRelMask
);
521 Expected
<uint64_t> XCOFFObjectFile::getStartAddress() const {
522 // TODO FIXME Should get from auxiliary_header->o_entry when support for the
523 // auxiliary_header is added.
527 StringRef
XCOFFObjectFile::mapDebugSectionName(StringRef Name
) const {
528 return StringSwitch
<StringRef
>(Name
)
529 .Case("dwinfo", "debug_info")
530 .Case("dwline", "debug_line")
531 .Case("dwpbnms", "debug_pubnames")
532 .Case("dwpbtyp", "debug_pubtypes")
533 .Case("dwarnge", "debug_aranges")
534 .Case("dwabrev", "debug_abbrev")
535 .Case("dwstr", "debug_str")
536 .Case("dwrnges", "debug_ranges")
537 .Case("dwloc", "debug_loc")
538 .Case("dwframe", "debug_frame")
539 .Case("dwmac", "debug_macinfo")
543 size_t XCOFFObjectFile::getFileHeaderSize() const {
544 return is64Bit() ? sizeof(XCOFFFileHeader64
) : sizeof(XCOFFFileHeader32
);
547 size_t XCOFFObjectFile::getSectionHeaderSize() const {
548 return is64Bit() ? sizeof(XCOFFSectionHeader64
) :
549 sizeof(XCOFFSectionHeader32
);
552 bool XCOFFObjectFile::is64Bit() const {
553 return Binary::ID_XCOFF64
== getType();
556 uint16_t XCOFFObjectFile::getMagic() const {
557 return is64Bit() ? fileHeader64()->Magic
: fileHeader32()->Magic
;
560 Expected
<DataRefImpl
> XCOFFObjectFile::getSectionByNum(int16_t Num
) const {
561 if (Num
<= 0 || Num
> getNumberOfSections())
562 return errorCodeToError(object_error::invalid_section_index
);
565 DRI
.p
= getWithOffset(getSectionHeaderTableAddress(),
566 getSectionHeaderSize() * (Num
- 1));
571 XCOFFObjectFile::getSymbolSectionName(XCOFFSymbolRef SymEntPtr
) const {
572 const int16_t SectionNum
= SymEntPtr
.getSectionNumber();
574 switch (SectionNum
) {
582 Expected
<DataRefImpl
> SecRef
= getSectionByNum(SectionNum
);
584 return generateXCOFFFixedNameStringRef(
585 getSectionNameInternal(SecRef
.get()));
586 return SecRef
.takeError();
590 unsigned XCOFFObjectFile::getSymbolSectionID(SymbolRef Sym
) const {
591 XCOFFSymbolRef
XCOFFSymRef(Sym
.getRawDataRefImpl(), this);
592 return XCOFFSymRef
.getSectionNumber();
595 bool XCOFFObjectFile::isReservedSectionNumber(int16_t SectionNumber
) {
596 return (SectionNumber
<= 0 && SectionNumber
>= -2);
599 uint16_t XCOFFObjectFile::getNumberOfSections() const {
600 return is64Bit() ? fileHeader64()->NumberOfSections
601 : fileHeader32()->NumberOfSections
;
604 int32_t XCOFFObjectFile::getTimeStamp() const {
605 return is64Bit() ? fileHeader64()->TimeStamp
: fileHeader32()->TimeStamp
;
608 uint16_t XCOFFObjectFile::getOptionalHeaderSize() const {
609 return is64Bit() ? fileHeader64()->AuxHeaderSize
610 : fileHeader32()->AuxHeaderSize
;
613 uint32_t XCOFFObjectFile::getSymbolTableOffset32() const {
614 return fileHeader32()->SymbolTableOffset
;
617 int32_t XCOFFObjectFile::getRawNumberOfSymbolTableEntries32() const {
618 // As far as symbol table size is concerned, if this field is negative it is
619 // to be treated as a 0. However since this field is also used for printing we
620 // don't want to truncate any negative values.
621 return fileHeader32()->NumberOfSymTableEntries
;
624 uint32_t XCOFFObjectFile::getLogicalNumberOfSymbolTableEntries32() const {
625 return (fileHeader32()->NumberOfSymTableEntries
>= 0
626 ? fileHeader32()->NumberOfSymTableEntries
630 uint64_t XCOFFObjectFile::getSymbolTableOffset64() const {
631 return fileHeader64()->SymbolTableOffset
;
634 uint32_t XCOFFObjectFile::getNumberOfSymbolTableEntries64() const {
635 return fileHeader64()->NumberOfSymTableEntries
;
638 uint32_t XCOFFObjectFile::getNumberOfSymbolTableEntries() const {
639 return is64Bit() ? getNumberOfSymbolTableEntries64()
640 : getLogicalNumberOfSymbolTableEntries32();
643 uintptr_t XCOFFObjectFile::getEndOfSymbolTableAddress() const {
644 const uint32_t NumberOfSymTableEntries
= getNumberOfSymbolTableEntries();
645 return getWithOffset(reinterpret_cast<uintptr_t>(SymbolTblPtr
),
646 XCOFF::SymbolTableEntrySize
* NumberOfSymTableEntries
);
649 void XCOFFObjectFile::checkSymbolEntryPointer(uintptr_t SymbolEntPtr
) const {
650 if (SymbolEntPtr
< reinterpret_cast<uintptr_t>(SymbolTblPtr
))
651 report_fatal_error("Symbol table entry is outside of symbol table.");
653 if (SymbolEntPtr
>= getEndOfSymbolTableAddress())
654 report_fatal_error("Symbol table entry is outside of symbol table.");
656 ptrdiff_t Offset
= reinterpret_cast<const char *>(SymbolEntPtr
) -
657 reinterpret_cast<const char *>(SymbolTblPtr
);
659 if (Offset
% XCOFF::SymbolTableEntrySize
!= 0)
661 "Symbol table entry position is not valid inside of symbol table.");
664 uint32_t XCOFFObjectFile::getSymbolIndex(uintptr_t SymbolEntPtr
) const {
665 return (reinterpret_cast<const char *>(SymbolEntPtr
) -
666 reinterpret_cast<const char *>(SymbolTblPtr
)) /
667 XCOFF::SymbolTableEntrySize
;
670 uintptr_t XCOFFObjectFile::getSymbolEntryAddressByIndex(uint32_t Index
) const {
671 return getAdvancedSymbolEntryAddress(
672 reinterpret_cast<uintptr_t>(getPointerToSymbolTable()), Index
);
676 XCOFFObjectFile::getSymbolNameByIndex(uint32_t Index
) const {
677 const uint32_t NumberOfSymTableEntries
= getNumberOfSymbolTableEntries();
679 if (Index
>= NumberOfSymTableEntries
)
680 return errorCodeToError(object_error::invalid_symbol_index
);
683 SymDRI
.p
= getSymbolEntryAddressByIndex(Index
);
684 return getSymbolName(SymDRI
);
687 uint16_t XCOFFObjectFile::getFlags() const {
688 return is64Bit() ? fileHeader64()->Flags
: fileHeader32()->Flags
;
691 const char *XCOFFObjectFile::getSectionNameInternal(DataRefImpl Sec
) const {
692 return is64Bit() ? toSection64(Sec
)->Name
: toSection32(Sec
)->Name
;
695 uintptr_t XCOFFObjectFile::getSectionHeaderTableAddress() const {
696 return reinterpret_cast<uintptr_t>(SectionHeaderTable
);
699 int32_t XCOFFObjectFile::getSectionFlags(DataRefImpl Sec
) const {
700 return is64Bit() ? toSection64(Sec
)->Flags
: toSection32(Sec
)->Flags
;
703 XCOFFObjectFile::XCOFFObjectFile(unsigned int Type
, MemoryBufferRef Object
)
704 : ObjectFile(Type
, Object
) {
705 assert(Type
== Binary::ID_XCOFF32
|| Type
== Binary::ID_XCOFF64
);
708 ArrayRef
<XCOFFSectionHeader64
> XCOFFObjectFile::sections64() const {
709 assert(is64Bit() && "64-bit interface called for non 64-bit file.");
710 const XCOFFSectionHeader64
*TablePtr
= sectionHeaderTable64();
711 return ArrayRef
<XCOFFSectionHeader64
>(TablePtr
,
712 TablePtr
+ getNumberOfSections());
715 ArrayRef
<XCOFFSectionHeader32
> XCOFFObjectFile::sections32() const {
716 assert(!is64Bit() && "32-bit interface called for non 32-bit file.");
717 const XCOFFSectionHeader32
*TablePtr
= sectionHeaderTable32();
718 return ArrayRef
<XCOFFSectionHeader32
>(TablePtr
,
719 TablePtr
+ getNumberOfSections());
722 // In an XCOFF32 file, when the field value is 65535, then an STYP_OVRFLO
723 // section header contains the actual count of relocation entries in the s_paddr
724 // field. STYP_OVRFLO headers contain the section index of their corresponding
725 // sections as their raw "NumberOfRelocations" field value.
726 template <typename T
>
727 Expected
<uint32_t> XCOFFObjectFile::getNumberOfRelocationEntries(
728 const XCOFFSectionHeader
<T
> &Sec
) const {
729 const T
&Section
= static_cast<const T
&>(Sec
);
731 return Section
.NumberOfRelocations
;
733 uint16_t SectionIndex
= &Section
- sectionHeaderTable
<T
>() + 1;
734 if (Section
.NumberOfRelocations
< XCOFF::RelocOverflow
)
735 return Section
.NumberOfRelocations
;
736 for (const auto &Sec
: sections32()) {
737 if (Sec
.Flags
== XCOFF::STYP_OVRFLO
&&
738 Sec
.NumberOfRelocations
== SectionIndex
)
739 return Sec
.PhysicalAddress
;
741 return errorCodeToError(object_error::parse_failed
);
744 template <typename Shdr
, typename Reloc
>
745 Expected
<ArrayRef
<Reloc
>> XCOFFObjectFile::relocations(const Shdr
&Sec
) const {
746 uintptr_t RelocAddr
= getWithOffset(reinterpret_cast<uintptr_t>(FileHeader
),
747 Sec
.FileOffsetToRelocationInfo
);
748 auto NumRelocEntriesOrErr
= getNumberOfRelocationEntries(Sec
);
749 if (Error E
= NumRelocEntriesOrErr
.takeError())
752 uint32_t NumRelocEntries
= NumRelocEntriesOrErr
.get();
753 static_assert((sizeof(Reloc
) == XCOFF::RelocationSerializationSize64
||
754 sizeof(Reloc
) == XCOFF::RelocationSerializationSize32
),
755 "Relocation structure is incorrect");
756 auto RelocationOrErr
=
757 getObject
<Reloc
>(Data
, reinterpret_cast<void *>(RelocAddr
),
758 NumRelocEntries
* sizeof(Reloc
));
759 if (Error E
= RelocationOrErr
.takeError())
762 const Reloc
*StartReloc
= RelocationOrErr
.get();
764 return ArrayRef
<Reloc
>(StartReloc
, StartReloc
+ NumRelocEntries
);
767 Expected
<XCOFFStringTable
>
768 XCOFFObjectFile::parseStringTable(const XCOFFObjectFile
*Obj
, uint64_t Offset
) {
769 // If there is a string table, then the buffer must contain at least 4 bytes
770 // for the string table's size. Not having a string table is not an error.
771 if (Error E
= Binary::checkOffset(
772 Obj
->Data
, reinterpret_cast<uintptr_t>(Obj
->base() + Offset
), 4)) {
773 consumeError(std::move(E
));
774 return XCOFFStringTable
{0, nullptr};
777 // Read the size out of the buffer.
778 uint32_t Size
= support::endian::read32be(Obj
->base() + Offset
);
780 // If the size is less then 4, then the string table is just a size and no
783 return XCOFFStringTable
{4, nullptr};
785 auto StringTableOrErr
=
786 getObject
<char>(Obj
->Data
, Obj
->base() + Offset
, Size
);
787 if (Error E
= StringTableOrErr
.takeError())
790 const char *StringTablePtr
= StringTableOrErr
.get();
791 if (StringTablePtr
[Size
- 1] != '\0')
792 return errorCodeToError(object_error::string_table_non_null_end
);
794 return XCOFFStringTable
{Size
, StringTablePtr
};
797 Expected
<std::unique_ptr
<XCOFFObjectFile
>>
798 XCOFFObjectFile::create(unsigned Type
, MemoryBufferRef MBR
) {
799 // Can't use std::make_unique because of the private constructor.
800 std::unique_ptr
<XCOFFObjectFile
> Obj
;
801 Obj
.reset(new XCOFFObjectFile(Type
, MBR
));
803 uint64_t CurOffset
= 0;
804 const auto *Base
= Obj
->base();
805 MemoryBufferRef Data
= Obj
->Data
;
807 // Parse file header.
808 auto FileHeaderOrErr
=
809 getObject
<void>(Data
, Base
+ CurOffset
, Obj
->getFileHeaderSize());
810 if (Error E
= FileHeaderOrErr
.takeError())
812 Obj
->FileHeader
= FileHeaderOrErr
.get();
814 CurOffset
+= Obj
->getFileHeaderSize();
815 // TODO FIXME we don't have support for an optional header yet, so just skip
817 CurOffset
+= Obj
->getOptionalHeaderSize();
819 // Parse the section header table if it is present.
820 if (Obj
->getNumberOfSections()) {
821 auto SecHeadersOrErr
= getObject
<void>(Data
, Base
+ CurOffset
,
822 Obj
->getNumberOfSections() *
823 Obj
->getSectionHeaderSize());
824 if (Error E
= SecHeadersOrErr
.takeError())
826 Obj
->SectionHeaderTable
= SecHeadersOrErr
.get();
829 const uint32_t NumberOfSymbolTableEntries
=
830 Obj
->getNumberOfSymbolTableEntries();
832 // If there is no symbol table we are done parsing the memory buffer.
833 if (NumberOfSymbolTableEntries
== 0)
834 return std::move(Obj
);
836 // Parse symbol table.
837 CurOffset
= Obj
->is64Bit() ? Obj
->getSymbolTableOffset64()
838 : Obj
->getSymbolTableOffset32();
839 const uint64_t SymbolTableSize
=
840 static_cast<uint64_t>(XCOFF::SymbolTableEntrySize
) *
841 NumberOfSymbolTableEntries
;
843 getObject
<void *>(Data
, Base
+ CurOffset
, SymbolTableSize
);
844 if (Error E
= SymTableOrErr
.takeError())
846 Obj
->SymbolTblPtr
= SymTableOrErr
.get();
847 CurOffset
+= SymbolTableSize
;
849 // Parse String table.
850 Expected
<XCOFFStringTable
> StringTableOrErr
=
851 parseStringTable(Obj
.get(), CurOffset
);
852 if (Error E
= StringTableOrErr
.takeError())
854 Obj
->StringTable
= StringTableOrErr
.get();
856 return std::move(Obj
);
859 Expected
<std::unique_ptr
<ObjectFile
>>
860 ObjectFile::createXCOFFObjectFile(MemoryBufferRef MemBufRef
,
862 return XCOFFObjectFile::create(FileType
, MemBufRef
);
865 bool XCOFFSymbolRef::isFunction() const {
866 if (!isCsectSymbol())
869 if (getSymbolType() & FunctionSym
)
872 Expected
<XCOFFCsectAuxRef
> ExpCsectAuxEnt
= getXCOFFCsectAuxRef();
876 const XCOFFCsectAuxRef CsectAuxRef
= ExpCsectAuxEnt
.get();
878 // A function definition should be a label definition.
879 // FIXME: This is not necessarily the case when -ffunction-sections is
881 if (!CsectAuxRef
.isLabel())
884 if (CsectAuxRef
.getStorageMappingClass() != XCOFF::XMC_PR
)
887 const int16_t SectNum
= getSectionNumber();
888 Expected
<DataRefImpl
> SI
= OwningObjectPtr
->getSectionByNum(SectNum
);
890 // If we could not get the section, then this symbol should not be
891 // a function. So consume the error and return `false` to move on.
892 consumeError(SI
.takeError());
896 return (OwningObjectPtr
->getSectionFlags(SI
.get()) & XCOFF::STYP_TEXT
);
899 bool XCOFFSymbolRef::isCsectSymbol() const {
900 XCOFF::StorageClass SC
= getStorageClass();
901 return (SC
== XCOFF::C_EXT
|| SC
== XCOFF::C_WEAKEXT
||
902 SC
== XCOFF::C_HIDEXT
);
905 Expected
<XCOFFCsectAuxRef
> XCOFFSymbolRef::getXCOFFCsectAuxRef() const {
906 assert(isCsectSymbol() &&
907 "Calling csect symbol interface with a non-csect symbol.");
909 uint8_t NumberOfAuxEntries
= getNumberOfAuxEntries();
911 Expected
<StringRef
> NameOrErr
= getName();
912 if (auto Err
= NameOrErr
.takeError())
913 return std::move(Err
);
915 if (!NumberOfAuxEntries
) {
916 return createStringError(object_error::parse_failed
,
917 "csect symbol \"" + *NameOrErr
+
918 "\" contains no auxiliary entry");
921 if (!OwningObjectPtr
->is64Bit()) {
922 // In XCOFF32, the csect auxilliary entry is always the last auxiliary
923 // entry for the symbol.
924 uintptr_t AuxAddr
= XCOFFObjectFile::getAdvancedSymbolEntryAddress(
925 getEntryAddress(), NumberOfAuxEntries
);
926 return XCOFFCsectAuxRef(viewAs
<XCOFFCsectAuxEnt32
>(AuxAddr
));
929 // XCOFF64 uses SymbolAuxType to identify the auxiliary entry type.
930 // We need to iterate through all the auxiliary entries to find it.
931 for (uint8_t Index
= NumberOfAuxEntries
; Index
> 0; --Index
) {
932 uintptr_t AuxAddr
= XCOFFObjectFile::getAdvancedSymbolEntryAddress(
933 getEntryAddress(), Index
);
934 if (*OwningObjectPtr
->getSymbolAuxType(AuxAddr
) ==
935 XCOFF::SymbolAuxType::AUX_CSECT
) {
937 OwningObjectPtr
->checkSymbolEntryPointer(AuxAddr
);
939 return XCOFFCsectAuxRef(viewAs
<XCOFFCsectAuxEnt64
>(AuxAddr
));
943 return createStringError(
944 object_error::parse_failed
,
945 "a csect auxiliary entry is not found for symbol \"" + *NameOrErr
+ "\"");
948 Expected
<StringRef
> XCOFFSymbolRef::getName() const {
949 // A storage class value with the high-order bit on indicates that the name is
950 // a symbolic debugger stabstring.
951 if (getStorageClass() & 0x80)
952 return StringRef("Unimplemented Debug Name");
955 if (Entry32
->NameInStrTbl
.Magic
!= XCOFFSymbolRef::NAME_IN_STR_TBL_MAGIC
)
956 return generateXCOFFFixedNameStringRef(Entry32
->SymbolName
);
958 return OwningObjectPtr
->getStringTableEntry(Entry32
->NameInStrTbl
.Offset
);
961 return OwningObjectPtr
->getStringTableEntry(Entry64
->Offset
);
964 // Explictly instantiate template classes.
965 template struct XCOFFSectionHeader
<XCOFFSectionHeader32
>;
966 template struct XCOFFSectionHeader
<XCOFFSectionHeader64
>;
968 template struct XCOFFRelocation
<llvm::support::ubig32_t
>;
969 template struct XCOFFRelocation
<llvm::support::ubig64_t
>;
971 template llvm::Expected
<llvm::ArrayRef
<llvm::object::XCOFFRelocation64
>>
972 llvm::object::XCOFFObjectFile::relocations
<llvm::object::XCOFFSectionHeader64
,
973 llvm::object::XCOFFRelocation64
>(
974 llvm::object::XCOFFSectionHeader64
const &) const;
975 template llvm::Expected
<llvm::ArrayRef
<llvm::object::XCOFFRelocation32
>>
976 llvm::object::XCOFFObjectFile::relocations
<llvm::object::XCOFFSectionHeader32
,
977 llvm::object::XCOFFRelocation32
>(
978 llvm::object::XCOFFSectionHeader32
const &) const;
980 bool doesXCOFFTracebackTableBegin(ArrayRef
<uint8_t> Bytes
) {
981 if (Bytes
.size() < 4)
984 return support::endian::read32be(Bytes
.data()) == 0;
987 #define GETVALUEWITHMASK(X) (Data & (TracebackTable::X))
988 #define GETVALUEWITHMASKSHIFT(X, S) \
989 ((Data & (TracebackTable::X)) >> (TracebackTable::S))
991 Expected
<TBVectorExt
> TBVectorExt::create(StringRef TBvectorStrRef
) {
992 Error Err
= Error::success();
993 TBVectorExt
TBTVecExt(TBvectorStrRef
, Err
);
995 return std::move(Err
);
999 TBVectorExt::TBVectorExt(StringRef TBvectorStrRef
, Error
&Err
) {
1000 const uint8_t *Ptr
= reinterpret_cast<const uint8_t *>(TBvectorStrRef
.data());
1001 Data
= support::endian::read16be(Ptr
);
1002 uint32_t VecParmsTypeValue
= support::endian::read32be(Ptr
+ 2);
1004 GETVALUEWITHMASKSHIFT(NumberOfVectorParmsMask
, NumberOfVectorParmsShift
);
1006 ErrorAsOutParameter
EAO(&Err
);
1007 Expected
<SmallString
<32>> VecParmsTypeOrError
=
1008 parseVectorParmsType(VecParmsTypeValue
, ParmsNum
);
1009 if (!VecParmsTypeOrError
)
1010 Err
= VecParmsTypeOrError
.takeError();
1012 VecParmsInfo
= VecParmsTypeOrError
.get();
1015 uint8_t TBVectorExt::getNumberOfVRSaved() const {
1016 return GETVALUEWITHMASKSHIFT(NumberOfVRSavedMask
, NumberOfVRSavedShift
);
1019 bool TBVectorExt::isVRSavedOnStack() const {
1020 return GETVALUEWITHMASK(IsVRSavedOnStackMask
);
1023 bool TBVectorExt::hasVarArgs() const {
1024 return GETVALUEWITHMASK(HasVarArgsMask
);
1027 uint8_t TBVectorExt::getNumberOfVectorParms() const {
1028 return GETVALUEWITHMASKSHIFT(NumberOfVectorParmsMask
,
1029 NumberOfVectorParmsShift
);
1032 bool TBVectorExt::hasVMXInstruction() const {
1033 return GETVALUEWITHMASK(HasVMXInstructionMask
);
1035 #undef GETVALUEWITHMASK
1036 #undef GETVALUEWITHMASKSHIFT
1038 Expected
<XCOFFTracebackTable
> XCOFFTracebackTable::create(const uint8_t *Ptr
,
1040 Error Err
= Error::success();
1041 XCOFFTracebackTable
TBT(Ptr
, Size
, Err
);
1043 return std::move(Err
);
1047 XCOFFTracebackTable::XCOFFTracebackTable(const uint8_t *Ptr
, uint64_t &Size
,
1050 ErrorAsOutParameter
EAO(&Err
);
1051 DataExtractor
DE(ArrayRef
<uint8_t>(Ptr
, Size
), /*IsLittleEndian=*/false,
1053 DataExtractor::Cursor
Cur(/*Offset=*/0);
1055 // Skip 8 bytes of mandatory fields.
1058 unsigned FixedParmsNum
= getNumberOfFixedParms();
1059 unsigned FloatingParmsNum
= getNumberOfFPParms();
1060 uint32_t ParamsTypeValue
= 0;
1062 // Begin to parse optional fields.
1063 if (Cur
&& (FixedParmsNum
+ FloatingParmsNum
) > 0)
1064 ParamsTypeValue
= DE
.getU32(Cur
);
1066 if (Cur
&& hasTraceBackTableOffset())
1067 TraceBackTableOffset
= DE
.getU32(Cur
);
1069 if (Cur
&& isInterruptHandler())
1070 HandlerMask
= DE
.getU32(Cur
);
1072 if (Cur
&& hasControlledStorage()) {
1073 NumOfCtlAnchors
= DE
.getU32(Cur
);
1074 if (Cur
&& NumOfCtlAnchors
) {
1075 SmallVector
<uint32_t, 8> Disp
;
1076 Disp
.reserve(NumOfCtlAnchors
.getValue());
1077 for (uint32_t I
= 0; I
< NumOfCtlAnchors
&& Cur
; ++I
)
1078 Disp
.push_back(DE
.getU32(Cur
));
1080 ControlledStorageInfoDisp
= std::move(Disp
);
1084 if (Cur
&& isFuncNamePresent()) {
1085 uint16_t FunctionNameLen
= DE
.getU16(Cur
);
1087 FunctionName
= DE
.getBytes(Cur
, FunctionNameLen
);
1090 if (Cur
&& isAllocaUsed())
1091 AllocaRegister
= DE
.getU8(Cur
);
1093 unsigned VectorParmsNum
= 0;
1094 if (Cur
&& hasVectorInfo()) {
1095 StringRef VectorExtRef
= DE
.getBytes(Cur
, 6);
1097 Expected
<TBVectorExt
> TBVecExtOrErr
= TBVectorExt::create(VectorExtRef
);
1098 if (!TBVecExtOrErr
) {
1099 Err
= TBVecExtOrErr
.takeError();
1102 VecExt
= TBVecExtOrErr
.get();
1103 VectorParmsNum
= VecExt
.getValue().getNumberOfVectorParms();
1107 // As long as there is no fixed-point or floating-point parameter, this
1108 // field remains not present even when hasVectorInfo gives true and
1109 // indicates the presence of vector parameters.
1110 if (Cur
&& (FixedParmsNum
+ FloatingParmsNum
) > 0) {
1111 Expected
<SmallString
<32>> ParmsTypeOrError
=
1113 ? parseParmsTypeWithVecInfo(ParamsTypeValue
, FixedParmsNum
,
1114 FloatingParmsNum
, VectorParmsNum
)
1115 : parseParmsType(ParamsTypeValue
, FixedParmsNum
, FloatingParmsNum
);
1117 if (!ParmsTypeOrError
) {
1118 Err
= ParmsTypeOrError
.takeError();
1121 ParmsType
= ParmsTypeOrError
.get();
1124 if (Cur
&& hasExtensionTable())
1125 ExtensionTable
= DE
.getU8(Cur
);
1128 Err
= Cur
.takeError();
1133 #define GETBITWITHMASK(P, X) \
1134 (support::endian::read32be(TBPtr + (P)) & (TracebackTable::X))
1135 #define GETBITWITHMASKSHIFT(P, X, S) \
1136 ((support::endian::read32be(TBPtr + (P)) & (TracebackTable::X)) >> \
1137 (TracebackTable::S))
1139 uint8_t XCOFFTracebackTable::getVersion() const {
1140 return GETBITWITHMASKSHIFT(0, VersionMask
, VersionShift
);
1143 uint8_t XCOFFTracebackTable::getLanguageID() const {
1144 return GETBITWITHMASKSHIFT(0, LanguageIdMask
, LanguageIdShift
);
1147 bool XCOFFTracebackTable::isGlobalLinkage() const {
1148 return GETBITWITHMASK(0, IsGlobaLinkageMask
);
1151 bool XCOFFTracebackTable::isOutOfLineEpilogOrPrologue() const {
1152 return GETBITWITHMASK(0, IsOutOfLineEpilogOrPrologueMask
);
1155 bool XCOFFTracebackTable::hasTraceBackTableOffset() const {
1156 return GETBITWITHMASK(0, HasTraceBackTableOffsetMask
);
1159 bool XCOFFTracebackTable::isInternalProcedure() const {
1160 return GETBITWITHMASK(0, IsInternalProcedureMask
);
1163 bool XCOFFTracebackTable::hasControlledStorage() const {
1164 return GETBITWITHMASK(0, HasControlledStorageMask
);
1167 bool XCOFFTracebackTable::isTOCless() const {
1168 return GETBITWITHMASK(0, IsTOClessMask
);
1171 bool XCOFFTracebackTable::isFloatingPointPresent() const {
1172 return GETBITWITHMASK(0, IsFloatingPointPresentMask
);
1175 bool XCOFFTracebackTable::isFloatingPointOperationLogOrAbortEnabled() const {
1176 return GETBITWITHMASK(0, IsFloatingPointOperationLogOrAbortEnabledMask
);
1179 bool XCOFFTracebackTable::isInterruptHandler() const {
1180 return GETBITWITHMASK(0, IsInterruptHandlerMask
);
1183 bool XCOFFTracebackTable::isFuncNamePresent() const {
1184 return GETBITWITHMASK(0, IsFunctionNamePresentMask
);
1187 bool XCOFFTracebackTable::isAllocaUsed() const {
1188 return GETBITWITHMASK(0, IsAllocaUsedMask
);
1191 uint8_t XCOFFTracebackTable::getOnConditionDirective() const {
1192 return GETBITWITHMASKSHIFT(0, OnConditionDirectiveMask
,
1193 OnConditionDirectiveShift
);
1196 bool XCOFFTracebackTable::isCRSaved() const {
1197 return GETBITWITHMASK(0, IsCRSavedMask
);
1200 bool XCOFFTracebackTable::isLRSaved() const {
1201 return GETBITWITHMASK(0, IsLRSavedMask
);
1204 bool XCOFFTracebackTable::isBackChainStored() const {
1205 return GETBITWITHMASK(4, IsBackChainStoredMask
);
1208 bool XCOFFTracebackTable::isFixup() const {
1209 return GETBITWITHMASK(4, IsFixupMask
);
1212 uint8_t XCOFFTracebackTable::getNumOfFPRsSaved() const {
1213 return GETBITWITHMASKSHIFT(4, FPRSavedMask
, FPRSavedShift
);
1216 bool XCOFFTracebackTable::hasExtensionTable() const {
1217 return GETBITWITHMASK(4, HasExtensionTableMask
);
1220 bool XCOFFTracebackTable::hasVectorInfo() const {
1221 return GETBITWITHMASK(4, HasVectorInfoMask
);
1224 uint8_t XCOFFTracebackTable::getNumOfGPRsSaved() const {
1225 return GETBITWITHMASKSHIFT(4, GPRSavedMask
, GPRSavedShift
);
1228 uint8_t XCOFFTracebackTable::getNumberOfFixedParms() const {
1229 return GETBITWITHMASKSHIFT(4, NumberOfFixedParmsMask
,
1230 NumberOfFixedParmsShift
);
1233 uint8_t XCOFFTracebackTable::getNumberOfFPParms() const {
1234 return GETBITWITHMASKSHIFT(4, NumberOfFloatingPointParmsMask
,
1235 NumberOfFloatingPointParmsShift
);
1238 bool XCOFFTracebackTable::hasParmsOnStack() const {
1239 return GETBITWITHMASK(4, HasParmsOnStackMask
);
1242 #undef GETBITWITHMASK
1243 #undef GETBITWITHMASKSHIFT
1244 } // namespace object