Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 gcl (2.6.10-28) unstable; urgency=high
 .
   * enable prelink
Author: Camm Maguire <camm@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- gcl-2.6.10.orig/h/prelink.h
+++ gcl-2.6.10/h/prelink.h
@@ -33,13 +33,13 @@
 #endif
 #endif
 
-PRELINK_EXTER void *my_stdin;
-PRELINK_EXTER void *my_stdout;
-PRELINK_EXTER void *my_stderr;
+PRELINK_EXTER FILE *my_stdin;
+PRELINK_EXTER FILE *my_stdout;
+PRELINK_EXTER FILE *my_stderr;
 
 #ifdef HAVE_READLINE
-PRELINK_EXTER void *my_rl_instream;
-PRELINK_EXTER void *my_rl_completion_entry_function;
+PRELINK_EXTER FILE *my_rl_instream;
+PRELINK_EXTER rl_compentry_func_t *my_rl_completion_entry_function;
 PRELINK_EXTER const char *my_rl_readline_name;
 PRELINK_EXTER char *my_rl_line_buffer;
 #endif
--- gcl-2.6.10.orig/o/unexelf.c
+++ gcl-2.6.10/o/unexelf.c
@@ -751,7 +751,7 @@ unexec (char *new_name, char *old_name,
 #endif
   new_data2_addr = old_bss_addr;
   new_data2_size = new_bss_addr - old_bss_addr;
-  new_data2_offset  = OLD_SECTION_H (old_data_index).sh_offset +
+  new_data2_offset  = OLD_SECTION_H (old_data_index).sh_offset + /*to preserve data offset alignment*/
     (new_data2_addr - OLD_SECTION_H (old_data_index).sh_addr);
 
 #ifdef DEBUG
@@ -787,7 +787,8 @@ unexec (char *new_name, char *old_name,
   new_file_h = (ElfW(Ehdr) *) new_base;
   new_program_h = (ElfW(Phdr) *) ((byte *) new_base + old_file_h->e_phoff);
   new_section_h = (ElfW(Shdr) *)
-    ((byte *) new_base + old_file_h->e_shoff + new_data2_size);
+    ((byte *) new_base + old_file_h->e_shoff + new_data2_size + (new_data2_offset-old_bss_offset));
+
 
   /* Make our new file, program and section headers as copies of the
    * originals.
@@ -804,7 +805,7 @@ unexec (char *new_name, char *old_name,
    * further away now.
    */
 
-  new_file_h->e_shoff += new_data2_size;
+  new_file_h->e_shoff += new_data2_size + (new_data2_offset-old_bss_offset);
   new_file_h->e_shnum += 1;
 
 #ifdef DEBUG
@@ -957,8 +958,7 @@ unexec (char *new_name, char *old_name,
 	      >= OLD_SECTION_H (old_bss_index-1).sh_offset)
 	    NEW_SECTION_H (nn).sh_offset += new_data2_size;
 #else
-	  if (NEW_SECTION_H (nn).sh_offset + NEW_SECTION_H (nn).sh_size
-	      > new_data2_offset)
+	  if (NEW_SECTION_H (nn).sh_offset >= new_data2_offset)
 	    NEW_SECTION_H (nn).sh_offset += new_data2_size+(new_data2_offset-old_bss_offset);
 #endif
 	  /* Any section that was originally placed after the section
@@ -1249,6 +1249,3 @@ unexec (char *new_name, char *old_name,
 #ifdef UNIXSAVE
 #include "save.c"
 #endif
-
-
-
