Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit 88d6987

Browse files
committed
patcher: fix ppc32 support
The table of contents (TOC) code only appears to only apply to ppc64. The code was incorrectly assuming the existence of the TOC on ppc32. This commit updates the necessary code to only apply to ppc64. Signed-off-by: Nathan Hjelm <[email protected]> (cherry picked from commit open-mpi/ompi@71be36d) Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 5e31c5e commit 88d6987

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

opal/mca/patcher/base/base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ OPAL_DECLSPEC int mca_patcher_base_patch_hook (mca_patcher_base_module_t *module
6868
OPAL_DECLSPEC void mca_base_patcher_patch_apply_binary (mca_patcher_base_patch_t *patch);
6969

7070
static inline uintptr_t mca_patcher_base_addr_text (uintptr_t addr) {
71-
#if (defined(__PPC64__) || defined(__powerpc64__) || defined(__PPC__)) && _CALL_ELF != 2
71+
#if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64) && (!defined (_CALL_ELF) || (_CALL_ELF != 2))
7272
struct odp_t {
7373
uintptr_t text;
7474
uintptr_t toc;

opal/mca/patcher/base/patcher_base_patch.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void ModifyMemoryProtection (uintptr_t addr, size_t length, int prot)
122122
if (mprotect((void *)base, page_size, prot))
123123
perror("MemHook: mprotect failed");
124124
base += page_size;
125-
} while (base < addr + length);
125+
} while (base < bound);
126126
#else
127127
if (mprotect((void *) base, length, prot)) {
128128
perror("MemHook: mprotect failed");
@@ -156,26 +156,26 @@ void mca_base_patcher_patch_apply_binary (mca_patcher_base_patch_t *patch)
156156

157157
int mca_patcher_base_patch_hook (mca_patcher_base_module_t *module, uintptr_t hook_addr)
158158
{
159-
#if defined(__PPC64__) || defined(__powerpc64__) || defined(__PPC__)
159+
#if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64)
160160
mca_patcher_base_patch_t *hook_patch;
161161
const unsigned int nop = 0x60000000;
162-
unsigned int *nop_addr;
163162

164163
hook_patch = OBJ_NEW(mca_patcher_base_patch_t);
165164
if (OPAL_UNLIKELY(NULL == hook_patch)) {
166165
return OPAL_ERR_OUT_OF_RESOURCE;
167166
}
168167

169168
// locate reserved code space in hook function
170-
for (nop_addr = (unsigned int *)hook_addr ; ; nop_addr++) {
169+
for (unsigned int *nop_addr = (unsigned int *)hook_addr ; ; nop_addr++) {
171170
if (nop_addr[0] == nop && nop_addr[1] == nop && nop_addr[2] == nop
172171
&& nop_addr[3] == nop && nop_addr[4] == nop) {
172+
hook_patch->patch_orig = (uintptr_t) nop_addr;
173173
break;
174174
}
175175
}
176+
176177
// generate code to restore TOC
177178
register unsigned long toc asm("r2");
178-
hook_patch->patch_orig = (uintptr_t) nop_addr;
179179
hook_patch->patch_data_size = PatchLoadImm((uintptr_t)hook_patch->patch_data, 2, toc);
180180

181181
/* put the hook patch on the patch list so it will be undone on finalize */

opal/mca/patcher/overwrite/patcher_overwrite_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch)
214214
return rc;
215215
}
216216

217-
#if _CALL_ELF == 2
217+
#if defined(_CALL_ELF) && (_CALL_ELF == 2)
218218
sys_addr += 8;
219219
hook_addr += 8;
220220
#endif /* _CALL_ELF == 2*/

opal/mca/patcher/patcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/* Any function being patched in as a hook must use SYMBOLPATCH_BEGIN at the top,
2222
* and SYMBOLPATCH_END before it returns (this is just for PPC). */
2323

24-
#if (defined(__PPC64__) || defined(__powerpc64__) || defined(__PPC__)) && defined(OPAL_GCC_INLINE_ASSEMBLY)
24+
#if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64)
2525

2626
/* special processing for ppc64 to save and restore TOC (r2)
2727
* Reference: "64-bit PowerPC ELF Application Binary Interface Supplement 1.9" */

0 commit comments

Comments
 (0)