diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2013-12-12 07:41:27 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2013-12-12 07:41:27 -0800 |
commit | 58e7ebacdd97c858834c07c7dce098aeacd500fb (patch) | |
tree | eacf8465894e3930ae8fcd558de24e58cd22e166 /bfd/elf.c | |
parent | b15e5c540f4b90dbec13bcd5cbac90f9224aef4b (diff) | |
download | gdb-58e7ebacdd97c858834c07c7dce098aeacd500fb.zip gdb-58e7ebacdd97c858834c07c7dce098aeacd500fb.tar.gz gdb-58e7ebacdd97c858834c07c7dce098aeacd500fb.tar.bz2 |
Set ET_EXEC for -pie -Ttext-segment=
bfd/
* elf.c (assign_file_positions_except_relocs): Set e_type in ELF
header to ET_EXEC for -pie -Ttext-segment=.
2013-12-10 H.J. Lu <hongjiu.lu@intel.com>
* ld-pie/vaddr-0.d: New file.
* ld-pie/vaddr-1.d: Likewise.
* ld-pie/vaddr.s: Likewise.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -5152,6 +5152,27 @@ assign_file_positions_except_relocs (bfd *abfd, return FALSE; } + /* Set e_type in ELF header to ET_EXEC for -pie -Ttext-segment=. */ + if (link_info != NULL + && link_info->executable + && link_info->shared) + { + unsigned int num_segments = elf_elfheader (abfd)->e_phnum; + Elf_Internal_Phdr *segment = elf_tdata (abfd)->phdr; + Elf_Internal_Phdr *end_segment = &segment[num_segments]; + + /* Find the lowest p_vaddr in PT_LOAD segments. */ + bfd_vma p_vaddr = (bfd_vma) -1; + for (; segment < end_segment; segment++) + if (segment->p_type == PT_LOAD && p_vaddr > segment->p_vaddr) + p_vaddr = segment->p_vaddr; + + /* Set e_type to ET_EXEC if the lowest p_vaddr in PT_LOAD + segments is non-zero. */ + if (p_vaddr) + i_ehdrp->e_type = ET_EXEC; + } + /* Write out the program headers. */ alloc = elf_program_header_size (abfd) / bed->s->sizeof_phdr; if (bfd_seek (abfd, (bfd_signed_vma) bed->s->sizeof_ehdr, SEEK_SET) != 0 |