aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergei Trofimovich <slyfox@gentoo.org>2018-10-10 21:50:22 +0100
committerMark Hatle <mark.hatle@windriver.com>2018-10-12 11:01:45 -0400
commita89297f08cda5ca48d21088891150e7ccc9ddac3 (patch)
treef8632ad037a6fe5a8b5e32dd70612fa40111a3de
parentbd6e69d4f446253285118b4ef0740918a34a59c4 (diff)
downloadprelink-cross-a89297f08cda5ca48d21088891150e7ccc9ddac3.tar.gz
prelink-cross-a89297f08cda5ca48d21088891150e7ccc9ddac3.tar.bz2
prelink-cross-a89297f08cda5ca48d21088891150e7ccc9ddac3.zip
x86_64: allow prelinking of PIE executables with COPY relocs
COPY relocs are fine to have in PIE executables (as opposed to shared libraries). By enabling prelink on PIEs we achieve a few goals: - prelink more PIE files on system: nicer for uniformity, - avoid spurious warnings about shared libraries with COPY relocs It's usefult to prelink PIEs when kernel ASLR is disabled: kernel.randomize_va_space=0 + PIE-randomization patches. I have gcc built as `--enable-default-pie` (generates PIE executables by default). Testsute results before the change: PASS: 14 FAIL: 31 After the change: PASS: 32 FAIL: 13 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> Added ChangeLog entry Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
-rw-r--r--ChangeLog4
-rw-r--r--src/arch-x86_64.c4
-rw-r--r--src/dso.c19
-rw-r--r--src/prelink.h1
4 files changed, 26 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 73a301c..1118c35 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
2018-10-12 Sergei Trofimovich <slyfox@gentoo.org>
+ * src/arch-x86_64.c, src/dso.c, src/prelink.h: Allow prelink of
+ pie executables with COPY relocs
+
+2018-10-12 Sergei Trofimovich <slyfox@gentoo.org>
* tessuite/functions.sh: Avoid timestamp drift
2018-10-12 Joseph Myers <joseph@codesourcery.com>
diff --git a/src/arch-x86_64.c b/src/arch-x86_64.c
index 5c95f47..2f6c551 100644
--- a/src/arch-x86_64.c
+++ b/src/arch-x86_64.c
@@ -179,7 +179,7 @@ x86_64_prelink_rela (struct prelink_info *info, GElf_Rela *rela,
value + rela->r_addend - info->resolvetls->offset);
break;
case R_X86_64_COPY:
- if (dso->ehdr.e_type == ET_EXEC)
+ if (dso->ehdr.e_type == ET_EXEC || dso_is_pie(dso))
/* COPY relocs are handled specially in generic code. */
return 0;
error (0, 0, "%s: R_X86_64_COPY reloc in shared library?", dso->filename);
@@ -503,7 +503,7 @@ x86_64_undo_prelink_rela (DSO *dso, GElf_Rela *rela, GElf_Addr relaaddr)
write_le32 (dso, rela->r_offset, 0);
break;
case R_X86_64_COPY:
- if (dso->ehdr.e_type == ET_EXEC)
+ if (dso->ehdr.e_type == ET_EXEC || dso_is_pie(dso))
/* COPY relocs are handled specially in generic code. */
return 0;
error (0, 0, "%s: R_X86_64_COPY reloc in shared library?", dso->filename);
diff --git a/src/dso.c b/src/dso.c
index c59d81f..1025c77 100644
--- a/src/dso.c
+++ b/src/dso.c
@@ -1141,6 +1141,25 @@ adjust_old_to_new (DSO *dso, GElf_Addr addr)
return addr;
}
+/* Return true is DSO is position independent executable.
+
+ There is no simple way to distinct between shared library
+ and PIE executable. Use presence of interpreter as a heuristic. */
+
+int dso_is_pie(DSO *dso)
+{
+ int i;
+
+ if (dso->ehdr.e_type != ET_DYN)
+ return 0;
+
+ for (i = 0; i < dso->ehdr.e_phnum; ++i)
+ if (dso->phdr[i].p_type == PT_INTERP)
+ return 1;
+
+ return 0;
+}
+
GElf_Addr
adjust_new_to_old (DSO *dso, GElf_Addr addr)
{
diff --git a/src/prelink.h b/src/prelink.h
index de757df..ec9b8f9 100644
--- a/src/prelink.h
+++ b/src/prelink.h
@@ -298,6 +298,7 @@ int reopen_dso (DSO *dso, struct section_move *move, const char *);
int adjust_symbol_p (DSO *dso, GElf_Sym *sym);
int check_dso (DSO *dso);
int dso_is_rdwr (DSO *dso);
+int dso_is_pie(DSO *dso);
void read_dynamic (DSO *dso);
int set_dynamic (DSO *dso, GElf_Word tag, GElf_Addr value, int fatal);
int addr_to_sec (DSO *dso, GElf_Addr addr);