[tbb-commits] [tor-browser-bundle/master] add --enable-reloc-section patch from skruffy

mikeperry at torproject.org mikeperry at torproject.org
Fri Aug 29 22:21:32 UTC 2014


commit 1221eecfdc639fe412bc5fe051e3151e1ce5d6a9
Author: Erinn Clark <erinn at torproject.org>
Date:   Thu Aug 21 19:23:30 2014 -0400

    add --enable-reloc-section patch from skruffy
---
 gitian/patches/enable-reloc-section-ld.patch |  216 ++++++++++++++++++++++++++
 1 file changed, 216 insertions(+)

diff --git a/gitian/patches/enable-reloc-section-ld.patch b/gitian/patches/enable-reloc-section-ld.patch
new file mode 100644
index 0000000..f393f51
--- /dev/null
+++ b/gitian/patches/enable-reloc-section-ld.patch
@@ -0,0 +1,216 @@
+From 093b08a9e7af23a258306b710ebc4556d12f94f7 Mon Sep 17 00:00:00 2001
+From: Erinn Clark <erinn at torproject.org>
+Date: Fri, 8 Aug 2014 14:23:44 -0400
+Subject: [PATCH] add relocation section so Windows bundles can have ASLR
+
+Patch by skruffy.
+
+---
+ ld/emultempl/pe.em  |  6 +++++
+ ld/emultempl/pep.em |  8 ++++++-
+ ld/pe-dll.c         | 63 ++++++++++++++++++++++++++++++-----------------------
+ ld/pe-dll.h         |  1 +
+ 4 files changed, 50 insertions(+), 28 deletions(-)
+
+diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
+index 5d6da9e..14c07f7 100644
+--- a/ld/emultempl/pe.em
++++ b/ld/emultempl/pe.em
+@@ -268,6 +268,7 @@ fragment <<EOF
+ #define OPTION_TERMINAL_SERVER_AWARE	(OPTION_WDM_DRIVER + 1)
+ /* Determinism.  */
+ #define OPTION_INSERT_TIMESTAMP		(OPTION_TERMINAL_SERVER_AWARE + 1)
++#define OPTION_ENABLE_RELOC_SECTION	(OPTION_INSERT_TIMESTAMP + 1)
+ 
+ static void
+ gld${EMULATION_NAME}_add_options
+@@ -310,6 +311,7 @@ gld${EMULATION_NAME}_add_options
+     {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
+     {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
+     {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
++    {"enable-reloc-section", no_argument, NULL, OPTION_ENABLE_RELOC_SECTION},
+     {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
+     {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
+     {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
+@@ -773,6 +775,9 @@ gld${EMULATION_NAME}_handle_option (int optc)
+     case OPTION_EXCLUDE_ALL_SYMBOLS:
+       pe_dll_exclude_all_symbols = 1;
+       break;
++    case OPTION_ENABLE_RELOC_SECTION:
++      pe_dll_enable_reloc_section = 1;
++      break;
+     case OPTION_EXCLUDE_LIBS:
+       pe_dll_add_excludes (optarg, EXCLUDELIBS);
+       break;
+@@ -1839,6 +1844,7 @@ gld_${EMULATION_NAME}_finish (void)
+   if (link_info.shared
+ #if !defined(TARGET_IS_shpe)
+       || (!link_info.relocatable && pe_def_file->num_exports != 0)
++      || (!link_info.relocatable && pe_dll_enable_reloc_section)
+ #endif
+     )
+     {
+diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
+index b738800..b566903 100644
+--- a/ld/emultempl/pep.em
++++ b/ld/emultempl/pep.em
+@@ -242,7 +242,8 @@ enum options
+   OPTION_NO_BIND,
+   OPTION_WDM_DRIVER,
+   OPTION_INSERT_TIMESTAMP,
+-  OPTION_TERMINAL_SERVER_AWARE
++  OPTION_TERMINAL_SERVER_AWARE,
++  OPTION_ENABLE_RELOC_SECTION
+ };
+ 
+ static void
+@@ -284,6 +285,7 @@ gld${EMULATION_NAME}_add_options
+     {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
+     {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
+     {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
++    {"enable-reloc-section", no_argument, NULL, OPTION_ENABLE_RELOC_SECTION},
+     {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
+     {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
+     {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
+@@ -727,6 +729,9 @@ gld${EMULATION_NAME}_handle_option (int optc)
+     case OPTION_EXCLUDE_ALL_SYMBOLS:
+       pep_dll_exclude_all_symbols = 1;
+       break;
++    case OPTION_ENABLE_RELOC_SECTION:
++      pe_dll_enable_reloc_section = 1;
++      break;
+     case OPTION_EXCLUDE_LIBS:
+       pep_dll_add_excludes (optarg, EXCLUDELIBS);
+       break;
+@@ -1618,6 +1623,7 @@ gld_${EMULATION_NAME}_finish (void)
+ 
+ #ifdef DLL_SUPPORT
+   if (link_info.shared
++      || (!link_info.relocatable && pe_dll_enable_reloc_section)
+       || (!link_info.relocatable && pep_def_file->num_exports != 0))
+     {
+       pep_dll_fill_sections (link_info.output_bfd, &link_info);
+diff --git a/ld/pe-dll.c b/ld/pe-dll.c
+index e9e133b..4230dc3 100644
+--- a/ld/pe-dll.c
++++ b/ld/pe-dll.c
+@@ -152,6 +152,7 @@ def_file * pe_def_file = 0;
+ int pe_dll_export_everything = 0;
+ int pe_dll_exclude_all_symbols = 0;
+ int pe_dll_do_default_excludes = 1;
++int pe_dll_enable_reloc_section = 0;
+ int pe_dll_kill_ats = 0;
+ int pe_dll_stdcall_aliases = 0;
+ int pe_dll_warn_dup_exports = 0;
+@@ -3370,8 +3371,15 @@ pe_dll_build_sections (bfd *abfd, struct bfd_link_info *info)
+   process_def_file_and_drectve (abfd, info);
+ 
+   if (pe_def_file->num_exports == 0 && !info->shared)
+-    return;
+-
++    {
++      if (pe_dll_enable_reloc_section)
++        {
++          build_filler_bfd (0);
++          pe_output_file_set_long_section_names (filler_bfd);
++        }
++      return;
++    }
++    
+   generate_edata (abfd, info);
+   build_filler_bfd (1);
+   pe_output_file_set_long_section_names (filler_bfd);
+@@ -3386,13 +3394,9 @@ pe_exe_build_sections (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED)
+   pe_output_file_set_long_section_names (filler_bfd);
+ }
+ 
+-void
+-pe_dll_fill_sections (bfd *abfd, struct bfd_link_info *info)
++static void
++pe_dll_create_reloc (bfd *abfd, struct bfd_link_info *info)
+ {
+-  pe_dll_id_target (bfd_get_target (abfd));
+-  pe_output_file_set_long_section_names (abfd);
+-  image_base = pe_data (abfd)->pe_opthdr.ImageBase;
+-
+   generate_reloc (abfd, info);
+   if (reloc_sz > 0)
+     {
+@@ -3409,38 +3413,43 @@ pe_dll_fill_sections (bfd *abfd, struct bfd_link_info *info)
+       lang_do_assignments (lang_final_phase_enum);
+     }
+ 
+-  fill_edata (abfd, info);
+-
+-  if (info->shared && !info->pie)
+-    pe_data (abfd)->dll = 1;
+-
+-  edata_s->contents = edata_d;
+   reloc_s->contents = reloc_d;
+ }
+ 
+ void
+-pe_exe_fill_sections (bfd *abfd, struct bfd_link_info *info)
++pe_dll_fill_sections (bfd *abfd, struct bfd_link_info *info)
+ {
++  if (!reloc_s && !edata_s)
++    return;
+   pe_dll_id_target (bfd_get_target (abfd));
+   pe_output_file_set_long_section_names (abfd);
+   image_base = pe_data (abfd)->pe_opthdr.ImageBase;
+ 
+-  generate_reloc (abfd, info);
+-  if (reloc_sz > 0)
++  if (reloc_s)
++    pe_dll_create_reloc (abfd, info);
++
++  if (edata_s)
+     {
+-      bfd_set_section_size (filler_bfd, reloc_s, reloc_sz);
++      fill_edata (abfd, info);
++      edata_s->contents = edata_d;
++    }
+ 
+-      /* Resize the sections.  */
+-      lang_reset_memory_regions ();
+-      lang_size_sections (NULL, TRUE);
++  if (info->shared && !info->pie)
++    pe_data (abfd)->dll = 1;
+ 
+-      /* Redo special stuff.  */
+-      ldemul_after_allocation ();
+ 
+-      /* Do the assignments again.  */
+-      lang_do_assignments (lang_final_phase_enum);
+-    }
+-  reloc_s->contents = reloc_d;
++}
++
++void
++pe_exe_fill_sections (bfd *abfd, struct bfd_link_info *info)
++{
++  if (!reloc_s)
++    return;
++  pe_dll_id_target (bfd_get_target (abfd));
++  pe_output_file_set_long_section_names (abfd);
++  image_base = pe_data (abfd)->pe_opthdr.ImageBase;
++
++  pe_dll_create_reloc (abfd, info);
+ }
+ 
+ bfd_boolean
+diff --git a/ld/pe-dll.h b/ld/pe-dll.h
+index 4697390..2bf71d9 100644
+--- a/ld/pe-dll.h
++++ b/ld/pe-dll.h
+@@ -31,6 +31,7 @@ extern def_file *pe_def_file;
+ extern int pe_dll_export_everything;
+ extern int pe_dll_exclude_all_symbols;
+ extern int pe_dll_do_default_excludes;
++extern int pe_dll_enable_reloc_section;
+ extern int pe_dll_kill_ats;
+ extern int pe_dll_stdcall_aliases;
+ extern int pe_dll_warn_dup_exports;
+-- 
+2.0.1
+





More information about the tbb-commits mailing list