From 0efc80c807552560f1fd38d78f9cea32abfa0ede Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 24 Dec 2007 16:58:23 +0000 Subject: [PATCH] bfd/ 2007-12-24 H.J. Lu PR binutils/5488 * elf.c (IS_NOTE): New. (IS_COREFILE_NOTE): Use IS_NOTE. (IS_SECTION_IN_INPUT_SEGMENT): Use IS_NOTE instead of IS_COREFILE_NOTE. ld/testsuite/ 2007-12-24 H.J. Lu PR binutils/5488 * ld-elf/note-2.d: New. * ld-elf/note-2.s: Likewise. * ld-elf/note-2.t: Likewise. --- bfd/ChangeLog | 8 ++++++++ bfd/elf.c | 21 +++++++++++++++------ ld/testsuite/ChangeLog | 7 +++++++ ld/testsuite/ld-elf/note-2.d | 15 +++++++++++++++ ld/testsuite/ld-elf/note-2.s | 8 ++++++++ ld/testsuite/ld-elf/note-2.t | 13 +++++++++++++ 6 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 ld/testsuite/ld-elf/note-2.d create mode 100644 ld/testsuite/ld-elf/note-2.s create mode 100644 ld/testsuite/ld-elf/note-2.t diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8ebd721..ef64819 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,13 @@ 2007-12-24 H.J. Lu + PR binutils/5488 + * elf.c (IS_NOTE): New. + (IS_COREFILE_NOTE): Use IS_NOTE. + (IS_SECTION_IN_INPUT_SEGMENT): Use IS_NOTE instead of + IS_COREFILE_NOTE. + +2007-12-24 H.J. Lu + PR binutils/5449 * elf.c (rewrite_elf_program_header): Don't adjust p_paddr if p_paddr is set to 0. diff --git a/bfd/elf.c b/bfd/elf.c index a4607e5..ce9aa80 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5090,15 +5090,22 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd) && (section->lma + SECTION_SIZE (section, segment) \ <= SEGMENT_END (segment, base))) - /* Special case: corefile "NOTE" section containing regs, prpsinfo etc. */ -#define IS_COREFILE_NOTE(p, s) \ + /* Handle PT_NOTE segment. */ +#define IS_NOTE(p, s) \ (p->p_type == PT_NOTE \ - && bfd_get_format (ibfd) == bfd_core \ - && s->vma == 0 && s->lma == 0 \ + && elf_section_type (s) == SHT_NOTE \ && (bfd_vma) s->filepos >= p->p_offset \ && ((bfd_vma) s->filepos + s->size \ <= p->p_offset + p->p_filesz)) + /* Special case: corefile "NOTE" section containing regs, prpsinfo + etc. */ +#define IS_COREFILE_NOTE(p, s) \ + (IS_NOTE (p, s) \ + && bfd_get_format (ibfd) == bfd_core \ + && s->vma == 0 \ + && s->lma == 0) + /* The complicated case when p_vaddr is 0 is to handle the Solaris linker, which generates a PT_INTERP section with p_vaddr and p_memsz set to 0. */ @@ -5117,7 +5124,8 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd) A section will be included if: 1. It is within the address space of the segment -- we use the LMA if that is set for the segment and the VMA otherwise, - 2. It is an allocated segment, + 2. It is an allocated section or a NOTE section in a PT_NOTE + segment. 3. There is an output section associated with it, 4. The section has not already been allocated to a previous segment. 5. PT_GNU_STACK segments do not include any sections. @@ -5130,7 +5138,7 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd) ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr) \ : IS_CONTAINED_BY_VMA (section, segment)) \ && (section->flags & SEC_ALLOC) != 0) \ - || IS_COREFILE_NOTE (segment, section)) \ + || IS_NOTE (segment, section)) \ && segment->p_type != PT_GNU_STACK \ && (segment->p_type != PT_TLS \ || (section->flags & SEC_THREAD_LOCAL)) \ @@ -5664,6 +5672,7 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd) #undef SECTION_SIZE #undef IS_CONTAINED_BY_VMA #undef IS_CONTAINED_BY_LMA +#undef IS_NOTE #undef IS_COREFILE_NOTE #undef IS_SOLARIS_PT_INTERP #undef IS_SECTION_IN_INPUT_SEGMENT diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index e8f18aa..fc82529 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2007-12-24 H.J. Lu + + PR binutils/5488 + * ld-elf/note-2.d: New. + * ld-elf/note-2.s: Likewise. + * ld-elf/note-2.t: Likewise. + 2007-12-20 Hans-Peter Nilsson * ld-elf/seg.d: Restrict to linux and vxworks. diff --git a/ld/testsuite/ld-elf/note-2.d b/ld/testsuite/ld-elf/note-2.d new file mode 100644 index 0000000..aff3240 --- /dev/null +++ b/ld/testsuite/ld-elf/note-2.d @@ -0,0 +1,15 @@ +#ld: -Tnote-2.t +#objcopy_linked_file: -R .foo +#readelf: -l --wide + +#... +Program Headers: + Type.* + LOAD +0x[0-9a-f]+ .* + NOTE +0x[0-9a-f]+ .* + +#... + Segment Sections... + 00[ \t]+.text * + 01[ \t]+.note * +#pass diff --git a/ld/testsuite/ld-elf/note-2.s b/ld/testsuite/ld-elf/note-2.s new file mode 100644 index 0000000..93d6b36 --- /dev/null +++ b/ld/testsuite/ld-elf/note-2.s @@ -0,0 +1,8 @@ + .globl _entry + .text +_entry: + .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .section .foo,"awx",%progbits + .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .section .note,"",%note + .byte 0 diff --git a/ld/testsuite/ld-elf/note-2.t b/ld/testsuite/ld-elf/note-2.t new file mode 100644 index 0000000..a507da9 --- /dev/null +++ b/ld/testsuite/ld-elf/note-2.t @@ -0,0 +1,13 @@ +ENTRY(_entry) +PHDRS +{ + data PT_LOAD; + note PT_NOTE; +} +SECTIONS +{ + .text : { *(.text) } :data + .foo : { *(.foo) } :data + .note : { *(.note) } :note + /DISCARD/ : { *(*) } +} -- 2.7.4