Looks like the macro ELF_SECTION_IN_SEGMENT_1 checks if a section belongs to a segment based on vma
and considers tbss part of LOAD segment.
&& (!(check_vma) \
|| ((sec_hdr)->sh_flags & SHF_ALLOC) == 0 \
|| ((sec_hdr)->sh_addr >= (segment)->p_vaddr \
&& (!(strict) \
|| ((sec_hdr)->sh_addr - (segment)->p_vaddr \
<= (segment)->p_memsz - 1)) \
&& (((sec_hdr)->sh_addr - (segment)->p_vaddr \
+ ELF_SECTION_SIZE(sec_hdr, segment)) \
<= (segment)->p_memsz)))
and later when it assigns file offsets, it seems to fail after sorting segments.
qsort (sorted_seg_map, alloc, sizeof (*sorted_seg_map),
elf_sort_segments);
sorted segment order:
Im not sure if the fix needs to go into objcopy ie add appropriate checks to ELF_SECTION_IN_SEGMENT_1 or make lld emit lma proper. either of both Im ready to do the needful, please guide me on this.
Thank you.