GP-2422: Fixed bugs with generating PE .exports files

This commit is contained in:
Ryan Kurtz 2022-08-17 02:45:05 -04:00
parent 34d777bd20
commit 25a32e0023

View File

@ -107,25 +107,36 @@ class LibrarySymbolTable {
while (iter.hasNext()) {
monitor.checkCanceled();
Symbol sym = iter.next();
int ordinal = SymbolUtilities.getOrdinalValue(sym.getName());
if (ordinal == -1) {
throw new RuntimeException("Should never happen!");
}
Address symAddr = sym.getAddress();
String realName = sym.getName();
Symbol primary = symTab.getPrimarySymbol(symAddr);
if (primary != null) {
realName = primary.getName();
// Only consider ordinal exports, not ordinal imports
if (!(sym.isGlobal() && sym.isExternalEntryPoint())) {
continue;
}
// assumes that Ordinal_# name comes right before the actual name
int ordinal = SymbolUtilities.getOrdinalValue(sym.getName());
if (ordinal == -1) {
continue;
}
// The symbols at the given address should be in a list ordered like:
// [realName1, ordinalName1, realName2, ordinalName2, ...]
// where the realName elements are optional. For example,
// [ordinalName1, realName2, ordinalName2, ordinalName3, ...]
// is also valid. We want to find our ordinalName in the list and look at the
// previous entry to find its corresponding realName. If there is no previous
// entry or the previous entry starts with Ordinal_, then we'll assume it's
// a [NONAME] export and we'll just use the ordinalName as the realName.
String ordinalName = sym.getName();
String realName = ordinalName;
Address symAddr = sym.getAddress();
Symbol symbolsAt[] = symTab.getSymbols(symAddr);
for (int i = 0; i < symbolsAt.length; i++) {
if (symbolsAt[i].getName().equals(sym.getName())) {
if (i + 1 < symbolsAt.length) {
realName = symbolsAt[i + 1].getName();
break;
if (symbolsAt[i].getName().equals(ordinalName)) {
if (i > 0 &&
!symbolsAt[i - 1].getName().startsWith(SymbolUtilities.ORDINAL_PREFIX)) {
realName = symbolsAt[i - 1].getName();
}
break;
}
}