https://sourceware.org/bugzilla/show_bug.cgi?id=24786
Bug ID: 24786 Summary: assign wrong lma if first section in overlay is empty input section Product: binutils Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: zyfwong at 163 dot com Target Milestone: --- When using OVERLAY with first input section empty, the lma will be wrong. For example: we have a file `start.S`, which has section `.content`, but not `.noexists`. $ cat start.S .text .global _start _start: .long __load_start_over_content .section .content, "ax" .space 0x4 $ gcc -c start.S -o start.o $ cat over1.ld && ld -Tover1.ld start.o -o s1.elf ENTRY(_start) SECTIONS { .text : { *(.text) } OVERLAY : NOCROSSREFS AT(0x400000) SUBALIGN(4) { .over_empty { *(.noexists) } .over_content { *(.content) } } } $ cat over2.ld && ld -Tover2.ld start.o -o s2.elf ENTRY(_start) SECTIONS { .text : { *(.text) } OVERLAY : NOCROSSREFS AT(0x400000) SUBALIGN(4) { .over_content { *(.content) } .over_empty { *(.noexists) } } } $ nm s1.elf && nm s2.elf 0000000000000004 A __load_start_over_content <-- wrong lma in s1.elf 0000000000000000 T _start 0000000000400000 A __load_start_over_content <-- correct lma in s2.elf 0000000000000000 T _start if we place `.noexists` before `.content` in OVERLAY, we will get wrong lma. it seems like when call `lang_size_sections_1`, when a section is ignored, it will early break, so the `r->last_os` is not set correctly, and make the following sections using a wrong last_os. after I check the document of linker script about usage of OVERLAY, it seems like we should modify `lang_leave_overlay` and set the `os->load_base`. like: /* The first section has the load address specified in the OVERLAY statement. The rest are worked out from that. The base address is not needed (and should be null) if an LMA region was specified. */ if (l->next == 0) { l->os->load_base = lma_expr; l->os->sectype = normal_section; } /* we should add these */ else if (lma_region == NULL) { l->os->load_base = exp_binop('+', exp_nameop (LOADADDR, l->next->os->name), exp_nameop (SIZEOF, l->next->os->name)); } but I'm not sure. -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils