X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=src%2Flibelfu%2Fmodelops%2Freladd.c;h=55438db523eb237552c7f70f41f6cba31eecb444;hb=a5a7af50662f99f933f6e657a131f2ff0e3a358e;hp=82b562b557079d0ce03610d49bebb5853497f120;hpb=e28b7c5e31e8ab929c2392c079aa2c0bda49b7ac;p=centaur.git 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: