Skip to content

Commit 73bbaaa

Browse files
committed
patcher/linux: cleanup
Signed-off-by: Nathan Hjelm <[email protected]>
1 parent c481e96 commit 73bbaaa

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

opal/mca/patcher/linux/patcher_linux_module.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,31 @@ static void mca_patcher_linux_get_strtab(ElfW(Addr) base, const ElfW(Phdr) *pdyn
134134
table->size = (dyn == NULL) ? 0 : dyn->d_un.d_val;
135135
}
136136

137-
static void * mca_patcher_linux_get_got_entry(ElfW(Addr) base, const char *symbol,
138-
const mca_patcher_linux_elf_jmprel_t *jmprel,
139-
const mca_patcher_linux_elf_symtab_t *symtab,
140-
const mca_patcher_linux_elf_strtab_t *strtab)
137+
static void * mca_patcher_linux_get_got_entry (ElfW(Addr) base, const ElfW(Phdr) *phdr, int16_t phnum,
138+
int phent, const char *symbol)
141139
{
140+
mca_patcher_linux_elf_jmprel_t jmprel;
141+
mca_patcher_linux_elf_symtab_t symtab;
142+
mca_patcher_linux_elf_strtab_t strtab;
142143
ElfW(Rela) *rela, *relaend;
144+
const ElfW(Phdr) *dphdr;
143145
const char *relsymname;
144146
uint32_t relsymidx;
145147

146-
relaend = (ElfW(Rela) *)((char *)jmprel->tab + jmprel->size);
147-
for (rela = jmprel->tab; rela < relaend; ++rela) {
148+
dphdr = mca_patcher_linux_get_phdr_dynamic (phdr, phnum, phent);
149+
150+
mca_patcher_linux_get_jmprel (base, dphdr, &jmprel);
151+
mca_patcher_linux_get_symtab (base, dphdr, &symtab);
152+
mca_patcher_linux_get_strtab (base, dphdr, &strtab);
153+
154+
relaend = (ElfW(Rela) *)((char *)jmprel.tab + jmprel.size);
155+
for (rela = jmprel.tab; rela < relaend; ++rela) {
148156
#if SIZEOF_VOID_P == 8
149157
relsymidx = ELF64_R_SYM(rela->r_info);
150158
#else
151159
relsymidx = ELF32_R_SYM(rela->r_info);
152160
#endif
153-
relsymname = strtab->tab + symtab->tab[relsymidx].st_name;
161+
relsymname = strtab.tab + symtab.tab[relsymidx].st_name;
154162
if (!strcmp(symbol, relsymname)) {
155163
return (void *)(base + rela->r_offset);
156164
}
@@ -217,22 +225,12 @@ static int
217225
mca_patcher_linux_modify_got (ElfW(Addr) base, const ElfW(Phdr) *phdr, const char *phname,
218226
int16_t phnum, int phent, mca_patcher_linux_dl_iter_context_t *ctx)
219227
{
220-
const ElfW(Phdr) *dphdr;
221-
mca_patcher_linux_elf_jmprel_t jmprel;
222-
mca_patcher_linux_elf_symtab_t symtab;
223-
mca_patcher_linux_elf_strtab_t strtab;
224228
long page_size = opal_getpagesize ();
225229
void **entry;
226230
void *page;
227231
int ret;
228232

229-
dphdr = mca_patcher_linux_get_phdr_dynamic (phdr, phnum, phent);
230-
231-
mca_patcher_linux_get_jmprel (base, dphdr, &jmprel);
232-
mca_patcher_linux_get_symtab (base, dphdr, &symtab);
233-
mca_patcher_linux_get_strtab (base, dphdr, &strtab);
234-
235-
entry = mca_patcher_linux_get_got_entry (base, ctx->patch->super.patch_symbol, &jmprel, &symtab, &strtab);
233+
entry = mca_patcher_linux_get_got_entry (base, phdr, phnum, phent, ctx->patch->super.patch_symbol);
236234
if (entry == NULL) {
237235
return OPAL_SUCCESS;
238236
}
@@ -253,7 +251,8 @@ mca_patcher_linux_modify_got (ElfW(Addr) base, const ElfW(Phdr) *phdr, const cha
253251
}
254252

255253
opal_output_verbose (MCA_BASE_VERBOSE_TRACE, opal_patcher_base_framework.framework_output,
256-
"modifying got entry %p with original value %p\n", (void *) entry, *entry);
254+
"patch %p (%s): modifying got entry %p. original value %p. new value %p\n", ctx->patch,
255+
ctx->patch->super.patch_symbol, (void *) entry, *entry, (void *) ctx->patch->super.patch_value);
257256

258257
patch_got->got_entry = entry;
259258
patch_got->got_orig = *entry;
@@ -266,7 +265,7 @@ mca_patcher_linux_modify_got (ElfW(Addr) base, const ElfW(Phdr) *phdr, const cha
266265
if (*entry == (void *) ctx->patch->super.patch_value) {
267266
/* find the appropriate entry and restore the original value */
268267
mca_patcher_linux_patch_got_t *patch_got;
269-
OPAL_LIST_FOREACH(patch_got, &ctx->patch->patch_got_list, mca_patcher_linux_patch_got_t) {
268+
OPAL_LIST_FOREACH_REV(patch_got, &ctx->patch->patch_got_list, mca_patcher_linux_patch_got_t) {
270269
if (patch_got->got_entry == entry) {
271270
opal_output_verbose (MCA_BASE_VERBOSE_TRACE, opal_patcher_base_framework.framework_output,
272271
"restoring got entry %p with original value %p\n", (void *) entry, patch_got->got_orig);

0 commit comments

Comments
 (0)