Skip to content

Commit

Permalink
Merge pull request microsoft#118 from microsoft/dev/mookerem/arm6ecfix
Browse files Browse the repository at this point in the history
Merge topic 'bindexplib-arm64ec'
  • Loading branch information
bobbrow authored Mar 28, 2022
2 parents 00f0a29 + 760de71 commit 31dc3ea
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions Source/bindexplib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
# define IMAGE_FILE_MACHINE_ARM64 0xaa64 // ARM64 Little-Endian
# endif

# ifndef IMAGE_FILE_MACHINE_ARM64EC
# define IMAGE_FILE_MACHINE_ARM64EC 0xa641 // ARM64EC Little-Endian
# endif

typedef struct cmANON_OBJECT_HEADER_BIGOBJ
{
/* same as ANON_OBJECT_HEADER_V2 */
Expand Down Expand Up @@ -135,6 +139,13 @@ typedef struct _cmIMAGE_SYMBOL_EX
} cmIMAGE_SYMBOL_EX;
typedef cmIMAGE_SYMBOL_EX UNALIGNED* cmPIMAGE_SYMBOL_EX;

enum class Arch
{
Generic,
I386,
ARM64EC,
};

PIMAGE_SECTION_HEADER GetSectionHeaderOffset(
PIMAGE_FILE_HEADER pImageFileHeader)
{
Expand Down Expand Up @@ -193,7 +204,8 @@ class DumpSymbols
*/

DumpSymbols(ObjectHeaderType* ih, std::set<std::string>& symbols,
std::set<std::string>& dataSymbols, bool isI386)
std::set<std::string>& dataSymbols,
Arch symbolArch = Arch::Generic)
: Symbols(symbols)
, DataSymbols(dataSymbols)
{
Expand All @@ -203,7 +215,7 @@ class DumpSymbols
this->ObjectImageHeader->PointerToSymbolTable);
this->SectionHeaders = GetSectionHeaderOffset(this->ObjectImageHeader);
this->SymbolCount = this->ObjectImageHeader->NumberOfSymbols;
this->IsI386 = isI386;
this->SymbolArch = symbolArch;
}

/*
Expand Down Expand Up @@ -259,7 +271,7 @@ class DumpSymbols
}
}
// For i386 builds we need to remove _
if (this->IsI386 && symbol[0] == '_') {
if (this->SymbolArch == Arch::I386 && symbol[0] == '_') {
symbol.erase(0, 1);
}

Expand All @@ -279,13 +291,20 @@ class DumpSymbols
// skip symbols containing a dot or are from managed code
if (symbol.find('.') == std::string::npos &&
!SymbolIsFromManagedCode(symbol)) {
if (!pSymbolTable->Type && (SectChar & IMAGE_SCN_MEM_WRITE)) {
// Read only (i.e. constants) must be excluded
this->DataSymbols.insert(symbol);
} else {
if (pSymbolTable->Type || !(SectChar & IMAGE_SCN_MEM_READ) ||
(SectChar & IMAGE_SCN_MEM_EXECUTE)) {
this->Symbols.insert(symbol);
// skip arm64ec thunk symbols
if (this->SymbolArch != Arch::ARM64EC ||
(symbol.find("$ientry_thunk") == std::string::npos &&
symbol.find("$entry_thunk") == std::string::npos &&
symbol.find("$iexit_thunk") == std::string::npos &&
symbol.find("$exit_thunk") == std::string::npos)) {
if (!pSymbolTable->Type && (SectChar & IMAGE_SCN_MEM_WRITE)) {
// Read only (i.e. constants) must be excluded
this->DataSymbols.insert(symbol);
} else {
if (pSymbolTable->Type || !(SectChar & IMAGE_SCN_MEM_READ) ||
(SectChar & IMAGE_SCN_MEM_EXECUTE)) {
this->Symbols.insert(symbol);
}
}
}
}
Expand Down Expand Up @@ -316,7 +335,7 @@ class DumpSymbols
PIMAGE_SECTION_HEADER SectionHeaders;
ObjectHeaderType* ObjectImageHeader;
SymbolTableType* SymbolTable;
bool IsI386;
Arch SymbolArch;
};
#endif

Expand Down Expand Up @@ -421,7 +440,8 @@ bool DumpFile(std::string const& nmPath, const char* filename,
(imageHeader->Machine == IMAGE_FILE_MACHINE_AMD64) ||
(imageHeader->Machine == IMAGE_FILE_MACHINE_ARM) ||
(imageHeader->Machine == IMAGE_FILE_MACHINE_ARMNT) ||
(imageHeader->Machine == IMAGE_FILE_MACHINE_ARM64)) &&
(imageHeader->Machine == IMAGE_FILE_MACHINE_ARM64) ||
(imageHeader->Machine == IMAGE_FILE_MACHINE_ARM64EC)) &&
(imageHeader->Characteristics == 0)) {
/*
* The tests above are checking for IMAGE_FILE_HEADER.Machine
Expand All @@ -431,7 +451,11 @@ bool DumpFile(std::string const& nmPath, const char* filename,
*/
DumpSymbols<IMAGE_FILE_HEADER, IMAGE_SYMBOL> symbolDumper(
(PIMAGE_FILE_HEADER)lpFileBase, symbols, dataSymbols,
(imageHeader->Machine == IMAGE_FILE_MACHINE_I386));
(imageHeader->Machine == IMAGE_FILE_MACHINE_I386
? Arch::I386
: (imageHeader->Machine == IMAGE_FILE_MACHINE_ARM64EC
? Arch::ARM64EC
: Arch::Generic)));
symbolDumper.DumpObjFile();
} else {
// check for /bigobj and llvm LTO format
Expand All @@ -440,8 +464,12 @@ bool DumpFile(std::string const& nmPath, const char* filename,
if (h->Sig1 == 0x0 && h->Sig2 == 0xffff) {
// bigobj
DumpSymbols<cmANON_OBJECT_HEADER_BIGOBJ, cmIMAGE_SYMBOL_EX>
symbolDumper((cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase, symbols,
dataSymbols, (h->Machine == IMAGE_FILE_MACHINE_I386));
symbolDumper(
(cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase, symbols, dataSymbols,
(h->Machine == IMAGE_FILE_MACHINE_I386
? Arch::I386
: (h->Machine == IMAGE_FILE_MACHINE_ARM64EC ? Arch::ARM64EC
: Arch::Generic)));
symbolDumper.DumpObjFile();
} else if (
// BCexCODE - llvm bitcode
Expand Down

0 comments on commit 31dc3ea

Please sign in to comment.