-error_code COFFObjectFile::getSymbolNMTypeChar(DataRefImpl Symb,
- char &Result) const {
- const coff_symbol *symb = toSymb(Symb);
- StringRef name;
- if (error_code ec = getSymbolName(Symb, name))
- return ec;
- char ret = StringSwitch<char>(name)
- .StartsWith(".debug", 'N')
- .StartsWith(".sxdata", 'N')
- .Default('?');
-
- if (ret != '?') {
- Result = ret;
- return object_error::success;
- }
-
- uint32_t Characteristics = 0;
- if (symb->SectionNumber > 0) {
- const coff_section *Section = NULL;
- if (error_code ec = getSection(symb->SectionNumber, Section))
- return ec;
- Characteristics = Section->Characteristics;
- }
-
- switch (symb->SectionNumber) {
- case COFF::IMAGE_SYM_UNDEFINED:
- // Check storage classes.
- if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL) {
- Result = 'w';
- return object_error::success; // Don't do ::toupper.
- } else if (symb->Value != 0) // Check for common symbols.
- ret = 'c';
- else
- ret = 'u';
- break;
- case COFF::IMAGE_SYM_ABSOLUTE:
- ret = 'a';
- break;
- case COFF::IMAGE_SYM_DEBUG:
- ret = 'n';
- break;
- default:
- // Check section type.
- if (Characteristics & COFF::IMAGE_SCN_CNT_CODE)
- ret = 't';
- else if ( Characteristics & COFF::IMAGE_SCN_MEM_READ
- && ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only.
- ret = 'r';
- else if (Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
- ret = 'd';
- else if (Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
- ret = 'b';
- else if (Characteristics & COFF::IMAGE_SCN_LNK_INFO)
- ret = 'i';
-
- // Check for section symbol.
- else if ( symb->StorageClass == COFF::IMAGE_SYM_CLASS_STATIC
- && symb->Value == 0)
- ret = 's';
- }
-
- if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL)
- ret = ::toupper(static_cast<unsigned char>(ret));
-
- Result = ret;
- return object_error::success;
-}
-
-error_code COFFObjectFile::getSymbolSection(DataRefImpl Symb,
- section_iterator &Result) const {
- const coff_symbol *symb = toSymb(Symb);
- if (symb->SectionNumber <= COFF::IMAGE_SYM_UNDEFINED)
- Result = end_sections();
- else {
- const coff_section *sec = 0;
- if (error_code ec = getSection(symb->SectionNumber, sec)) return ec;
- DataRefImpl Sec;
- Sec.p = reinterpret_cast<uintptr_t>(sec);
- Result = section_iterator(SectionRef(Sec, this));
+std::error_code
+COFFObjectFile::getSymbolSection(DataRefImpl Ref,
+ section_iterator &Result) const {
+ const coff_symbol *Symb = toSymb(Ref);
+ if (COFF::isReservedSectionNumber(Symb->SectionNumber)) {
+ Result = section_end();
+ } else {
+ const coff_section *Sec = nullptr;
+ if (std::error_code EC = getSection(Symb->SectionNumber, Sec))
+ return EC;
+ DataRefImpl Ref;
+ Ref.p = reinterpret_cast<uintptr_t>(Sec);
+ Result = section_iterator(SectionRef(Ref, this));