Skip to content

Commit 8327ebd

Browse files
committed
Merge remote-tracking branch 'origin/GP-4265_ghidra1_ElfX86-64_GotAllocation' into patch
2 parents da9e53a + 7608a6e commit 8327ebd

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationContext.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
import ghidra.program.model.mem.MemoryAccessException;
2525
import ghidra.program.model.mem.MemoryBlock;
2626
import ghidra.util.*;
27-
import ghidra.util.exception.AssertException;
28-
import ghidra.util.exception.NotFoundException;
27+
import ghidra.util.exception.*;
2928

3029
/**
3130
* <code>X86_64_ElfRelocationContext</code> provides ability to generate a
@@ -50,7 +49,10 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext {
5049
public long getSymbolValue(ElfSymbol symbol) {
5150
long symbolValue = super.getSymbolValue(symbol);
5251
if (symbolValue == 0 && ElfConstants.GOT_SYMBOL_NAME.equals(symbol.getNameAsString())) {
53-
Address gotAddr = allocateGot();
52+
Address gotAddr = symbolMap.get(symbol);
53+
if (gotAddr == null) {
54+
gotAddr = allocateGot();
55+
}
5456
if (gotAddr != null) {
5557
return gotAddr.getOffset();
5658
}
@@ -145,7 +147,7 @@ private Address allocateGot() {
145147
return null;
146148
}
147149

148-
if (gotElfSymbol != null && getSymbolAddress(gotElfSymbol) != null) {
150+
if (gotElfSymbol != null && gotElfSymbol.getValue() != 0) {
149151
throw new AssertException(ElfConstants.GOT_SYMBOL_NAME + " already allocated");
150152
}
151153

@@ -155,8 +157,16 @@ private Address allocateGot() {
155157
ElfRelocationHandler.GOT_BLOCK_NAME);
156158
if (allocatedGotLimits != null &&
157159
allocatedGotLimits.getMinAddress().getOffset() < Integer.MAX_VALUE) {
158-
// GOT must fall within first 32-bit segment
160+
// NOTE: GOT must fall within first 32-bit segment
159161
if (gotElfSymbol != null) {
162+
// remember where GOT was allocated
163+
try {
164+
loadHelper.createSymbol(allocatedGotLimits.getMinAddress(),
165+
ElfConstants.GOT_SYMBOL_NAME, true, false, null);
166+
}
167+
catch (InvalidInputException e) {
168+
throw new AssertionError("Unexpected exception", e);
169+
}
160170
symbolMap.put(gotElfSymbol, allocatedGotLimits.getMinAddress());
161171
}
162172
allocatedGotAddress = allocatedGotLimits.getMinAddress();

0 commit comments

Comments
 (0)