From a5a7af50662f99f933f6e657a131f2ff0e3a358e Mon Sep 17 00:00:00 2001 From: norly Date: Sat, 22 Jun 2013 01:03:28 +0100 Subject: [PATCH] reladd: Work more with sh_addr instead of sh_offset --- src/libelfu/modelops/reladd.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libelfu/modelops/reladd.c b/src/libelfu/modelops/reladd.c index 82b562b..55438db 100644 --- a/src/libelfu/modelops/reladd.c +++ b/src/libelfu/modelops/reladd.c @@ -66,7 +66,13 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn) GElf_Off injOffset; ElfuPhdr *injPhdr; - if (oldscn->shdr.sh_flags & SHF_ALLOC) { + if (!(oldscn->shdr.sh_flags & SHF_ALLOC)) { + ELFU_WARN("insertSection: Skipping non-memory section %s (type %d flags %u).\n", + elfu_mScnName(mrel, oldscn), + oldscn->shdr.sh_type, + (unsigned)oldscn->shdr.sh_flags); + goto ERROR; + } else { newscn = cloneScn(oldscn); if (!newscn) { return NULL; @@ -105,13 +111,14 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn) newscn->shdr.sh_addr = injAddr; newscn->shdr.sh_offset = injOffset; + /* Insert section in child list, ordered by memory address */ if (CIRCLEQ_EMPTY(&injPhdr->childScnList) - || CIRCLEQ_LAST(&injPhdr->childScnList)->shdr.sh_offset < injOffset) { + || CIRCLEQ_LAST(&injPhdr->childScnList)->shdr.sh_addr < injAddr) { CIRCLEQ_INSERT_TAIL(&injPhdr->childScnList, newscn, elemChildScn); } else { ElfuScn *ms; CIRCLEQ_FOREACH(ms, &injPhdr->childScnList, elemChildScn) { - if (injOffset < ms->shdr.sh_offset) { + if (injAddr < ms->shdr.sh_addr) { CIRCLEQ_INSERT_BEFORE(&injPhdr->childScnList, ms, newscn, elemChildScn); break; } @@ -148,12 +155,6 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn) } return newscn; - } else { - ELFU_WARN("insertSection: Skipping non-memory section %s (type %d flags %u).\n", - elfu_mScnName(mrel, oldscn), - oldscn->shdr.sh_type, - (unsigned)oldscn->shdr.sh_flags); - goto ERROR; } ERROR: -- 2.30.2