Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6329 Corrected PowerPC-32 ELF Relocation processing for R_PPC_ADDR16_LO and R_PPC_ADDR16_HA

ghidra1fe35e34add71
diff --git a/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC_ElfRelocationHandler.java b/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC_ElfRelocationHandler.java
index 639340c175..97545dca3c 100644
--- a/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC_ElfRelocationHandler.java
+++ b/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC_ElfRelocationHandler.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -138,7 +138,8 @@ public class PowerPC_ElfRelocationHandler extends
byteLength = 2;
break;
case R_PPC_ADDR16_LO:
- if (Long.compareUnsigned(symbolValue, relocbase) > 0 &&
+ if (sym.isSection() && sym.getValue() != 0 &&
+ Long.compareUnsigned(symbolValue, relocbase) > 0 &&
Long.compareUnsigned(symbolValue, relocbase + addend) <= 0) {
/**
* (freebsd) Addend values are sometimes relative to sections in rela,
@@ -156,7 +157,8 @@ public class PowerPC_ElfRelocationHandler extends
byteLength = 2;
break;
case R_PPC_ADDR16_HA:
- if (Long.compareUnsigned(symbolValue, relocbase) > 0 &&
+ if (sym.isSection() && sym.getValue() != 0 &&
+ Long.compareUnsigned(symbolValue, relocbase) > 0 &&
Long.compareUnsigned(symbolValue, relocbase + addend) <= 0) {
/**
* (freebsd) Addend values are sometimes relative to sections in rela,