diff --git a/build/unix/elfhack/elfhack.cpp b/build/unix/elfhack/elfhack.cpp index 4ba4296764b..3674dbd3ea7 100644 --- a/build/unix/elfhack/elfhack.cpp +++ b/build/unix/elfhack/elfhack.cpp @@ -442,7 +442,7 @@ int do_relocation_section(Elf *elf, unsigned int rel_type, unsigned int rel_type relhack_entry.r_offset = relhack_entry.r_info = 0; relhack->push_back(relhack_entry); - relhackcode->insertAfter(section); + relhackcode->insertBefore(section); relhack->insertAfter(relhackcode); unsigned int old_end = section->getOffset() + section->getSize(); diff --git a/build/unix/elfhack/elfxx.h b/build/unix/elfhack/elfxx.h index 74a30c9007f..ee438b48df8 100644 --- a/build/unix/elfhack/elfxx.h +++ b/build/unix/elfhack/elfxx.h @@ -360,6 +360,23 @@ public: markDirty(); } + void insertBefore(ElfSection *section, bool dirty = true) { + if (previous != NULL) + previous->next = next; + if (next != NULL) + next->previous = previous; + next = section; + if (section != NULL) { + previous = section->previous; + section->previous = this; + } else + previous = NULL; + if (previous != NULL) + previous->next = this; + if (dirty) + markDirty(); + } + void markDirty() { if (link != NULL) shdr.sh_link = -1;