mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-01 04:15:22 +08:00
Merge remote-tracking branch
'origin/GP-3610_ghidra1_ELF_x86-64_GOTRelocations' into patch (Closes #5519)
This commit is contained in:
+15
-9
@@ -87,7 +87,7 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext {
|
|||||||
// NOTE: GOT allocation calculation assumes all GOT entries correspond to a specific
|
// NOTE: GOT allocation calculation assumes all GOT entries correspond to a specific
|
||||||
// symbol and not a computed offset. This assumption may need to be revised based upon
|
// symbol and not a computed offset. This assumption may need to be revised based upon
|
||||||
// uses of getGotEntryAddress method
|
// uses of getGotEntryAddress method
|
||||||
Set<Long> uniqueSymbolValues = new HashSet<>();
|
Set<Object> uniqueSymbolValues = new HashSet<>();
|
||||||
for (ElfRelocationTable rt : getElfHeader().getRelocationTables()) {
|
for (ElfRelocationTable rt : getElfHeader().getRelocationTables()) {
|
||||||
ElfSymbolTable st = rt.getAssociatedSymbolTable();
|
ElfSymbolTable st = rt.getAssociatedSymbolTable();
|
||||||
if (st == null) {
|
if (st == null) {
|
||||||
@@ -102,7 +102,9 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext {
|
|||||||
if (elfSymbol == null) {
|
if (elfSymbol == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
uniqueSymbolValues.add(elfSymbol.getValue());
|
long value = elfSymbol.getValue();
|
||||||
|
Object uniqueValue = value == 0 ? elfSymbol.getNameAsString() : Long.valueOf(value);
|
||||||
|
uniqueSymbolValues.add(uniqueValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Math.max(8, uniqueSymbolValues.size() * 8);
|
return Math.max(8, uniqueSymbolValues.size() * 8);
|
||||||
@@ -130,13 +132,14 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext {
|
|||||||
nextAllocatedGotEntryAddress = Address.NO_ADDRESS;
|
nextAllocatedGotEntryAddress = Address.NO_ADDRESS;
|
||||||
|
|
||||||
ElfSymbol gotElfSymbol = findGotElfSymbol();
|
ElfSymbol gotElfSymbol = findGotElfSymbol();
|
||||||
if (gotElfSymbol == null) {
|
|
||||||
// TODO: may need to support cases where GOT symbol not defined
|
if (gotElfSymbol == null && !getElfHeader().isRelocatable()) {
|
||||||
loadHelper.log(
|
loadHelper.log(
|
||||||
"GOT allocatiom failed. " + ElfConstants.GOT_SYMBOL_NAME + " not defined");
|
"GOT allocatiom failed. " + ElfConstants.GOT_SYMBOL_NAME + " not defined");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (getSymbolAddress(gotElfSymbol) != null) {
|
|
||||||
|
if (gotElfSymbol != null && getSymbolAddress(gotElfSymbol) != null) {
|
||||||
throw new AssertException(ElfConstants.GOT_SYMBOL_NAME + " already allocated");
|
throw new AssertException(ElfConstants.GOT_SYMBOL_NAME + " already allocated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +150,9 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext {
|
|||||||
if (allocatedGotLimits != null &&
|
if (allocatedGotLimits != null &&
|
||||||
allocatedGotLimits.getMinAddress().getOffset() < Integer.MAX_VALUE) {
|
allocatedGotLimits.getMinAddress().getOffset() < Integer.MAX_VALUE) {
|
||||||
// GOT must fall within first 32-bit segment
|
// GOT must fall within first 32-bit segment
|
||||||
symbolMap.put(gotElfSymbol, allocatedGotLimits.getMinAddress());
|
if (gotElfSymbol != null) {
|
||||||
|
symbolMap.put(gotElfSymbol, allocatedGotLimits.getMinAddress());
|
||||||
|
}
|
||||||
allocatedGotAddress = allocatedGotLimits.getMinAddress();
|
allocatedGotAddress = allocatedGotLimits.getMinAddress();
|
||||||
nextAllocatedGotEntryAddress = allocatedGotAddress;
|
nextAllocatedGotEntryAddress = allocatedGotAddress;
|
||||||
gotMap = new HashMap<>();
|
gotMap = new HashMap<>();
|
||||||
@@ -156,8 +161,7 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext {
|
|||||||
return allocatedGotAddress;
|
return allocatedGotAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadHelper.log("Failed to allocate " + ElfRelocationHandler.GOT_BLOCK_NAME +
|
loadHelper.log("Failed to allocate GOT block required for relocation processing");
|
||||||
" block required for relocation processing");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +217,9 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext {
|
|||||||
}
|
}
|
||||||
if (addr == null) {
|
if (addr == null) {
|
||||||
addr = getNextAllocatedGotEntryAddress();
|
addr = getNextAllocatedGotEntryAddress();
|
||||||
gotMap.put(symbolValue, addr);
|
if (gotMap != null) {
|
||||||
|
gotMap.put(symbolValue, addr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return addr == Address.NO_ADDRESS ? null : addr;
|
return addr == Address.NO_ADDRESS ? null : addr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user