diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2007-09-18 00:25:07 +0000 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2007-09-18 00:25:07 +0000 |
commit | b10a8ae01c27969e5104f76209272fb457c1e20b (patch) | |
tree | 6005c9c87f56f91ee161c26390fedc00d0222271 /bfd/elf.c | |
parent | 87dcefc059a01fa0d2db1cc00cc6f8f4de505291 (diff) | |
download | gdb-b10a8ae01c27969e5104f76209272fb457c1e20b.zip gdb-b10a8ae01c27969e5104f76209272fb457c1e20b.tar.gz gdb-b10a8ae01c27969e5104f76209272fb457c1e20b.tar.bz2 |
bfd/
2007-09-17 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/3281
PR binutils/5037
* elf-bfd.h (elf_obj_tdata): Remove relro.
* elf.c (get_program_header_size): Check info->relro instead
of elf_tdata (abfd)->relro.
(_bfd_elf_map_sections_to_segments): Likewise.
(assign_file_positions_for_load_sections): Don't set
PT_GNU_RELRO segment alignment here.
(assign_file_positions_for_non_load_sections): Properly set up
PT_GNU_RELRO segment for copying executable/shared library.
(rewrite_elf_program_header): Remove PT_GNU_RELRO segment.
(copy_elf_program_header): Set p_size and p_size_valid fields for
PT_GNU_RELRO segment.
include/elf/
2007-09-17 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/3281
PR binutils/5037
* internal.h (elf_segment_map): Add p_size and p_size_valid.
(ELF_IS_SECTION_IN_SEGMENT): Allow SHF_TLS sections in
PT_GNU_RELRO segments.
ld/
2007-09-17 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/3281
PR binutils/5037
* ldexp.h (ldexp_control): Add relro, relro_start_stat and
relro_end_stat.
* ldexp.c (fold_binary): Set expld.dataseg.relro to
exp_dataseg_relro_start or exp_dataseg_relro_end when
seeing DATA_SEGMENT_ALIGN or DATA_SEGMENT_RELRO_END,
respectively.
* ldlang.c (lang_size_sections_1): Properly set
expld.dataseg.relro_start_stat and
expld.dataseg.relro_end_stat.
(find_relro_section_callback): New function.
(lang_find_relro_sections_1): Likewise.
(lang_find_relro_sections): Likewise.
(lang_process): Call lang_find_relro_sections for
non-relocatable link.
ld/testsuite/
2007-09-17 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/3281
PR binutils/5037
* ld-elf/binutils.exp: Update "-z relro" tests to use relro1.s.
Add "-z relro" tests with relro2.s. Add "-z relro" tests with
TLS for objcopy.
* ld-elf/relro1.s: New file.
* ld-elf/relro2.s: Likewise.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 77 |
1 files changed, 63 insertions, 14 deletions
@@ -3357,7 +3357,7 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info) /* We need a PT_DYNAMIC segment. */ ++segs; - if (elf_tdata (abfd)->relro) + if (info->relro) { /* We need a PT_GNU_RELRO segment only when there is a PT_DYNAMIC segment. */ @@ -3887,7 +3887,7 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info) pm = &m->next; } - if (dynsec != NULL && elf_tdata (abfd)->relro) + if (dynsec != NULL && info->relro) { /* We make a PT_GNU_RELRO segment only when there is a PT_DYNAMIC segment. */ @@ -4388,12 +4388,10 @@ assign_file_positions_for_load_sections (bfd *abfd, p->p_memsz += this_hdr->sh_size; } - if (p->p_type == PT_GNU_RELRO) - p->p_align = 1; - else if (align > p->p_align - && !m->p_align_valid - && (p->p_type != PT_LOAD - || (abfd->flags & D_PAGED) == 0)) + if (align > p->p_align + && !m->p_align_valid + && (p->p_type != PT_LOAD + || (abfd->flags & D_PAGED) == 0)) p->p_align = align; } @@ -4543,18 +4541,53 @@ assign_file_positions_for_non_load_sections (bfd *abfd, if (m->count != 0) { if (p->p_type != PT_LOAD - && (p->p_type != PT_NOTE || bfd_get_format (abfd) != bfd_core)) + && (p->p_type != PT_NOTE + || bfd_get_format (abfd) != bfd_core)) { Elf_Internal_Shdr *hdr; + asection *sect; + BFD_ASSERT (!m->includes_filehdr && !m->includes_phdrs); - hdr = &elf_section_data (m->sections[m->count - 1])->this_hdr; - p->p_filesz = (m->sections[m->count - 1]->filepos - - m->sections[0]->filepos); + sect = m->sections[m->count - 1]; + hdr = &elf_section_data (sect)->this_hdr; + p->p_filesz = sect->filepos - m->sections[0]->filepos; if (hdr->sh_type != SHT_NOBITS) p->p_filesz += hdr->sh_size; - p->p_offset = m->sections[0]->filepos; + if (p->p_type == PT_GNU_RELRO) + { + /* When we get here, we are copying executable + or shared library. But we need to use the same + linker logic. */ + Elf_Internal_Phdr *lp; + + for (lp = phdrs; lp < phdrs + count; ++lp) + { + if (lp->p_type == PT_LOAD + && lp->p_paddr == p->p_paddr) + break; + } + + if (lp < phdrs + count) + { + /* We should use p_size if it is valid since it + may contain the first few bytes of the next + SEC_ALLOC section. */ + if (m->p_size_valid) + p->p_filesz = m->p_size; + else + abort (); + p->p_vaddr = lp->p_vaddr; + p->p_offset = lp->p_offset; + p->p_memsz = p->p_filesz; + p->p_align = 1; + } + else + abort (); + } + else + p->p_offset = m->sections[0]->filepos; } } else @@ -5143,7 +5176,12 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd) } if (segment->p_type != PT_LOAD) - continue; + { + /* Remove PT_GNU_RELRO segment. */ + if (segment->p_type == PT_GNU_RELRO) + segment->p_type = PT_NULL; + continue; + } /* Determine if this segment overlaps any previous segments. */ for (j = 0, segment2 = elf_tdata (ibfd)->phdr; j < i; j++, segment2 ++) @@ -5667,6 +5705,17 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd) map->p_align_valid = 1; map->p_vaddr_offset = 0; + if (map->p_type == PT_GNU_RELRO + && segment->p_filesz == segment->p_memsz) + { + /* The PT_GNU_RELRO segment may contain the first a few + bytes in the .got.plt section even if the whole .got.plt + section isn't in the PT_GNU_RELRO segment. We won't + change the size of the PT_GNU_RELRO segment. */ + map->p_size = segment->p_filesz; + map->p_size_valid = 1; + } + /* Determine if this segment contains the ELF file header and if it contains the program headers themselves. */ map->includes_filehdr = (segment->p_offset == 0 |