diff options
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 9 | ||||
-rw-r--r-- | bfd/elf.c | 66 |
2 files changed, 73 insertions, 2 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 5b0211f..46d92a0 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2017-04-04 H.J. Lu <hongjiu.lu@intel.com> + + * elf.c (get_program_header_size): Add a GNU_MBIND segment for + each GNU_MBIND section and align GNU_MBIND section to page size. + (_bfd_elf_map_sections_to_segments): Create a GNU_MBIND + segment for each GNU_MBIND section. + (_bfd_elf_init_private_section_data): Copy sh_info from input + for GNU_MBIND section. + 2017-04-03 Palmer Dabbelt <palmer@dabbelt.com> * elfnn-riscv.c (GP_NAME): Delete. @@ -4330,9 +4330,33 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info) } } - /* Let the backend count up any program headers it might need. */ bed = get_elf_backend_data (abfd); - if (bed->elf_backend_additional_program_headers) + + if ((abfd->flags & D_PAGED) != 0) + { + /* Add a PT_GNU_MBIND segment for each mbind section. */ + unsigned int page_align_power = bfd_log2 (bed->commonpagesize); + for (s = abfd->sections; s != NULL; s = s->next) + if (elf_section_flags (s) & SHF_GNU_MBIND) + { + if (elf_section_data (s)->this_hdr.sh_info + > PT_GNU_MBIND_NUM) + { + _bfd_error_handler + /* xgettext:c-format */ + (_("%B: GNU_MBIN section `%A' has invalid sh_info field: %d"), + abfd, s, elf_section_data (s)->this_hdr.sh_info); + continue; + } + /* Align mbind section to page size. */ + if (s->alignment_power < page_align_power) + s->alignment_power = page_align_power; + segs ++; + } + } + + /* Let the backend count up any program headers it might need. */ + if (bed->elf_backend_additional_program_headers) { int a; @@ -4504,6 +4528,7 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info) bfd_boolean writable; int tls_count = 0; asection *first_tls = NULL; + asection *first_mbind = NULL; asection *dynsec, *eh_frame_hdr; bfd_size_type amt; bfd_vma addr_mask, wrap_to = 0; @@ -4836,6 +4861,9 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info) first_tls = s; tls_count++; } + if (first_mbind == NULL + && (elf_section_flags (s) & SHF_GNU_MBIND) != 0) + first_mbind = s; } /* If there are any SHF_TLS output sections, add PT_TLS segment. */ @@ -4883,6 +4911,35 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info) pm = &m->next; } + if (first_mbind && (abfd->flags & D_PAGED) != 0) + for (s = first_mbind; s != NULL; s = s->next) + if ((elf_section_flags (s) & SHF_GNU_MBIND) != 0 + && (elf_section_data (s)->this_hdr.sh_info + <= PT_GNU_MBIND_NUM)) + { + /* Mandated PF_R. */ + unsigned long p_flags = PF_R; + if ((s->flags & SEC_READONLY) == 0) + p_flags |= PF_W; + if ((s->flags & SEC_CODE) != 0) + p_flags |= PF_X; + + amt = sizeof (struct elf_segment_map) + sizeof (asection *); + m = bfd_zalloc (abfd, amt); + if (m == NULL) + goto error_return; + m->next = NULL; + m->p_type = (PT_GNU_MBIND_LO + + elf_section_data (s)->this_hdr.sh_info); + m->count = 1; + m->p_flags_valid = 1; + m->sections[0] = s; + m->p_flags = p_flags; + + *pm = m; + pm = &m->next; + } + /* If there is a .eh_frame_hdr section, throw in a PT_GNU_EH_FRAME segment. */ eh_frame_hdr = elf_eh_frame_hdr (abfd); @@ -7359,6 +7416,11 @@ _bfd_elf_init_private_section_data (bfd *ibfd, elf_section_flags (osec) |= (elf_section_flags (isec) & (SHF_MASKOS | SHF_MASKPROC)); + /* Copy sh_info from input for mbind section. */ + if (elf_section_flags (isec) & SHF_GNU_MBIND) + elf_section_data (osec)->this_hdr.sh_info + = elf_section_data (isec)->this_hdr.sh_info; + /* Set things up for objcopy and relocatable link. The output SHT_GROUP section will have its elf_next_in_group pointing back to the input group members. Ignore linker created group section. |