aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2013-12-12 07:41:27 -0800
committerH.J. Lu <hjl.tools@gmail.com>2013-12-12 07:41:27 -0800
commit58e7ebacdd97c858834c07c7dce098aeacd500fb (patch)
treeeacf8465894e3930ae8fcd558de24e58cd22e166 /bfd/elf.c
parentb15e5c540f4b90dbec13bcd5cbac90f9224aef4b (diff)
downloadgdb-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.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index 8df38ee..66d9644 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -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