PATCH: PR ld/4007: Linker failed to issue an error on bad section in segment
H. J. Lu
hjl@lucon.org
Thu Mar 22 15:47:00 GMT 2007
More information about the Binutils mailing list
Thu Mar 22 15:47:00 GMT 2007
- Previous message (by thread): PATCH: PR ld/4007: Linker failed to issue an error on bad section in segment
- Next message (by thread): PATCH: PR ld/4007: Linker failed to issue an error on bad section in segment
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Mar 22, 2007 at 03:34:00PM +0000, Nick Clifton wrote: > Hi H.J. > > >>Is that a necessary constraint for the test ? ie can this problem occur > >>for toolchains other the i386 based ones, (I think that it can), and if > >>so then is there any reason not to make a more generic test that can > >>check the behaviour of non-i386 based toolchains ? > > > >I don't know. i386 is unique due to address wrap around. > > Fair enough then. Go with the test as-is. > This is the patch I am checking in. I added a testcase for NOTE section. H.J. ---- bfd/ 2007-02-27 H.J. Lu <hongjiu.lu@intel.com> PR ld/4007 * elf.c (assign_file_positions_for_load_sections): Check if all sections are in the segment. ld/testsuite/ 2007-02-27 H.J. Lu <hongjiu.lu@intel.com> PR ld/4007 * ld-elf/note-1.d: New file. * ld-elf/note-1.s: Likewise. * ld-elf/note-1.t: Likewise. * ld-i386/alloc.d: Likewise. * ld-i386/alloc.s: Likewise. * ld-i386/alloc.t: Likewise. * ld-i386/i386.exp: Run "alloc". --- binutils/bfd/elf.c.phdr 2007-03-14 15:08:44.000000000 -0700 +++ binutils/bfd/elf.c 2007-03-14 17:50:31.000000000 -0700 @@ -4348,7 +4348,7 @@ assign_file_positions_for_load_sections file_ptr off, voff; bfd_size_type maxpagesize; unsigned int alloc; - unsigned int i; + unsigned int i, j; if (link_info == NULL && !elf_modify_segment_map (abfd, link_info)) @@ -4386,9 +4386,9 @@ assign_file_positions_for_load_sections off = bed->s->sizeof_ehdr; off += alloc * bed->s->sizeof_phdr; - for (m = elf_tdata (abfd)->segment_map, p = phdrs; + for (m = elf_tdata (abfd)->segment_map, p = phdrs, j = 0; m != NULL; - m = m->next, p++) + m = m->next, p++, j++) { asection **secpp; @@ -4705,6 +4705,29 @@ assign_file_positions_for_load_sections p->p_flags |= PF_W; } } + + /* Check if all sections are in the segment. Skip PT_GNU_RELRO + and PT_NOTE segments since they will be processed by + assign_file_positions_for_non_load_sections later. */ + if (p->p_type != PT_GNU_RELRO + && p->p_type != PT_NOTE) + for (i = 0, secpp = m->sections; i < m->count; i++, secpp++) + { + Elf_Internal_Shdr *this_hdr; + asection *sec; + + sec = *secpp; + this_hdr = &(elf_section_data(sec)->this_hdr); + if (this_hdr->sh_size != 0 + && !ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, p)) + { + (*_bfd_error_handler) + (_("%B: section `%A' can't be allocated in segment %d"), + abfd, sec, j); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + } } elf_tdata (abfd)->next_file_pos = off; --- binutils/ld/testsuite/ld-elf/note-1.d.phdr 2007-03-14 18:05:22.000000000 -0700 +++ binutils/ld/testsuite/ld-elf/note-1.d 2007-03-14 18:04:59.000000000 -0700 @@ -0,0 +1,8 @@ +#ld: -Tnote-1.t +#readelf: -l --wide + +#... + Section to Segment mapping: + Segment Sections... + 00 .foo + 01 .note --- binutils/ld/testsuite/ld-elf/note-1.s.phdr 2007-03-14 18:05:24.000000000 -0700 +++ binutils/ld/testsuite/ld-elf/note-1.s 2007-03-14 18:01:51.000000000 -0700 @@ -0,0 +1,6 @@ + .globl _entry + .section .foo,"awx",%progbits +_entry: + .byte 0 + .section .note,"",%note + .byte 0 --- binutils/ld/testsuite/ld-elf/note-1.t.phdr 2007-03-14 18:05:26.000000000 -0700 +++ binutils/ld/testsuite/ld-elf/note-1.t 2007-03-14 17:56:46.000000000 -0700 @@ -0,0 +1,14 @@ +ENTRY(_entry) +PHDRS +{ + data PT_LOAD; + note PT_NOTE; +} +SECTIONS +{ + . = 0x1000000; + .foo : { *(.foo) } :data + . = 0x2000000; + .note : { *(.note) } :note + /DISCARD/ : { *(*) } +} --- binutils/ld/testsuite/ld-i386/alloc.d.phdr 2007-03-14 15:08:44.000000000 -0700 +++ binutils/ld/testsuite/ld-i386/alloc.d 2007-03-14 17:22:54.000000000 -0700 @@ -0,0 +1,4 @@ +#name: Invalid allocated section +#as: --32 +#ld: -melf_i386 -T alloc.t +#error: .*section `.foo' can't be allocated in segment 0.* --- binutils/ld/testsuite/ld-i386/alloc.s.phdr 2007-03-14 15:08:44.000000000 -0700 +++ binutils/ld/testsuite/ld-i386/alloc.s 2007-03-14 17:22:54.000000000 -0700 @@ -0,0 +1,6 @@ + .section .bar,"ax","progbits" + .byte 0 + .section .foo,"aw","progbits" + .byte 0 + .bss + .long 0 --- binutils/ld/testsuite/ld-i386/alloc.t.phdr 2007-03-14 15:08:44.000000000 -0700 +++ binutils/ld/testsuite/ld-i386/alloc.t 2007-03-14 17:22:54.000000000 -0700 @@ -0,0 +1,13 @@ +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) +PHDRS { + text PT_LOAD FLAGS(5); /* R_E */ +} +SECTIONS +{ + . = 0xC0000000 + ((0x100000 + (0x100000 - 1)) & ~(0x100000 - 1)); + .bar : AT(ADDR(.bar) - 0xC0000000) { *(.bar) } :text + .bss : AT(ADDR(.bss) - 0xC0000000) { *(.bss) } + .foo 0 : AT(ADDR(.bss) + SIZEOF(.bss) - 0xC0000000) { *(.foo) } :text + /DISCARD/ : { *(.*) } +} --- binutils/ld/testsuite/ld-i386/i386.exp.phdr 2007-03-07 09:46:17.000000000 -0800 +++ binutils/ld/testsuite/ld-i386/i386.exp 2007-03-14 17:22:54.000000000 -0700 @@ -114,3 +114,4 @@ run_dump_test "abs" run_dump_test "pcrel8" run_dump_test "pcrel16" run_dump_test "pcrel16abs" +run_dump_test "alloc"
- Previous message (by thread): PATCH: PR ld/4007: Linker failed to issue an error on bad section in segment
- Next message (by thread): PATCH: PR ld/4007: Linker failed to issue an error on bad section in segment
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list