commit 2378432cb7172967b6cfdb9ed58f989412665bf5 Author: Kai Wang Date: Sun May 13 03:06:58 2018 +0200 Make sure that only TLS sections are sorted into TLS segment. This fixes a bug that the memory size of TLS segment is miscalcuated when the TLS segment's memory map also covers non-TLS sections. diff --git a/elfcopy/elfcopy.h b/elfcopy/elfcopy.h index 1ccd9d6..cad74ca 100644 --- a/elfcopy/elfcopy.h +++ b/elfcopy/elfcopy.h @@ -127,6 +127,7 @@ struct section { uint64_t cap; /* section capacity */ uint64_t align; /* section alignment */ uint64_t type; /* section type */ + uint64_t flags; /* section flags */ uint64_t vma; /* section virtual addr */ uint64_t lma; /* section load addr */ uint64_t pad_sz;/* section padding size */ diff --git a/elfcopy/sections.c b/elfcopy/sections.c index 44b0596..037f928 100644 --- a/elfcopy/sections.c +++ b/elfcopy/sections.c @@ -411,6 +411,7 @@ create_scn(struct elfcopy *ecp) s->sz = ish.sh_size; s->align = ish.sh_addralign; s->type = ish.sh_type; + s->flags = ish.sh_flags; s->vma = ish.sh_addr; /* diff --git a/elfcopy/segments.c b/elfcopy/segments.c index 0214dc4..d37088a 100644 --- a/elfcopy/segments.c +++ b/elfcopy/segments.c @@ -79,6 +79,8 @@ add_to_inseg_list(struct elfcopy *ecp, struct section *s) continue; if (s->vma + s->sz > seg->vaddr + seg->msz) continue; + if (seg->type == PT_TLS && ((s->flags & SHF_TLS) == 0)) + continue; insert_to_inseg_list(seg, s); if (seg->type == PT_LOAD)