This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[patch] sort unwind sections for elf64-hppa target
- From: Randolph Chung <tausq at debian dot org>
- To: binutils at sources dot redhat dot com
- Date: Sun, 7 Apr 2002 21:27:44 -0700
- Subject: [patch] sort unwind sections for elf64-hppa target
- Reply-to: Randolph Chung <tausq at debian dot org>
elf{32,64}-hppa targets are supposed to keep the unwind section in sorted
order, but in the current binutils this was only done on 32-bit targets
and not 64-bit ones (thanks Alan for the pointer...). The attached patch
should fix this.
Does this look ok?
randolph
* elf32-hppa.c (elf32_hppa_final_link): Move sorting logic to
elf_hppa_sort_unwind in elf-hppa.h and call it from here
* elf32-hppa.c (hppa_unwind_entry_compare): Move to elf-hppa.h
* elf-hppa.h (elf_hppa_final_link): Call elf_hppa_sort_unwind
--- binutils-2.11.92.0.12.3/bfd/elf32-hppa.c.orig Sun Apr 7 20:37:51 2002
+++ binutils-2.11.92.0.12.3/bfd/elf32-hppa.c Sun Apr 7 21:00:54 2002
@@ -373,9 +373,6 @@
PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
-static int hppa_unwind_entry_compare
- PARAMS ((const PTR, const PTR));
-
static boolean elf32_hppa_finish_dynamic_symbol
PARAMS ((bfd *, struct bfd_link_info *,
struct elf_link_hash_entry *, Elf_Internal_Sym *));
@@ -3235,37 +3232,15 @@
bfd *abfd;
struct bfd_link_info *info;
{
- asection *s;
/* Invoke the regular ELF linker to do all the work. */
if (!bfd_elf32_bfd_final_link (abfd, info))
return false;
/* If we're producing a final executable, sort the contents of the
- unwind section. Magic section names, but this is much safer than
- having elf32_hppa_relocate_section remember where SEGREL32 relocs
- occurred. Consider what happens if someone inept creates a
- linker script that puts unwind information in .text. */
- s = bfd_get_section_by_name (abfd, ".PARISC.unwind");
- if (s != NULL)
- {
- bfd_size_type size;
- char *contents;
-
- size = s->_raw_size;
- contents = bfd_malloc (size);
- if (contents == NULL)
- return false;
-
- if (! bfd_get_section_contents (abfd, s, contents, (file_ptr) 0, size))
- return false;
-
- qsort (contents, (size_t) (size / 16), 16, hppa_unwind_entry_compare);
-
- if (! bfd_set_section_contents (abfd, s, contents, (file_ptr) 0, size))
- return false;
- }
- return true;
+ unwind section. */
+
+ return elf_hppa_sort_unwind (abfd);
}
/* Record the lowest address for the data and text segments. */
@@ -4082,32 +4057,6 @@
}
return true;
-}
-
-/* Comparison function for qsort to sort unwind section during a
- final link. */
-
-static int
-hppa_unwind_entry_compare (a, b)
- const PTR a;
- const PTR b;
-{
- const bfd_byte *ap, *bp;
- unsigned long av, bv;
-
- ap = (const bfd_byte *) a;
- av = (unsigned long) ap[0] << 24;
- av |= (unsigned long) ap[1] << 16;
- av |= (unsigned long) ap[2] << 8;
- av |= (unsigned long) ap[3];
-
- bp = (const bfd_byte *) b;
- bv = (unsigned long) bp[0] << 24;
- bv |= (unsigned long) bp[1] << 16;
- bv |= (unsigned long) bp[2] << 8;
- bv |= (unsigned long) bp[3];
-
- return av < bv ? -1 : av > bv ? 1 : 0;
}
/* Finish up dynamic symbol handling. We set the contents of various
--- binutils-2.11.92.0.12.3/bfd/elf-hppa.h.orig Sun Apr 7 20:37:46 2002
+++ binutils-2.11.92.0.12.3/bfd/elf-hppa.h Sun Apr 7 21:01:20 2002
@@ -65,6 +65,12 @@
static void elf_hppa_final_write_processing
PARAMS ((bfd *, boolean));
+static int hppa_unwind_entry_compare
+ PARAMS ((const PTR, const PTR));
+
+static boolean elf_hppa_sort_unwind
+ PARAMS ((bfd *));
+
#if ARCH_SIZE == 64
static boolean elf_hppa_add_symbol_hook
PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
@@ -1022,6 +1028,65 @@
| EF_PARISC_TRAPNIL);
}
+/* Comparison function for qsort to sort unwind section during a
+ final link. */
+
+static int
+hppa_unwind_entry_compare (a, b)
+ const PTR a;
+ const PTR b;
+{
+ const bfd_byte *ap, *bp;
+ unsigned long av, bv;
+
+ ap = (const bfd_byte *) a;
+ av = (unsigned long) ap[0] << 24;
+ av |= (unsigned long) ap[1] << 16;
+ av |= (unsigned long) ap[2] << 8;
+ av |= (unsigned long) ap[3];
+
+ bp = (const bfd_byte *) b;
+ bv = (unsigned long) bp[0] << 24;
+ bv |= (unsigned long) bp[1] << 16;
+ bv |= (unsigned long) bp[2] << 8;
+ bv |= (unsigned long) bp[3];
+
+ return av < bv ? -1 : av > bv ? 1 : 0;
+}
+
+static boolean elf_hppa_sort_unwind (abfd)
+ bfd *abfd;
+{
+ asection *s;
+
+ /* Magic section names, but this is much safer than having
+ elf32_hppa_relocate_section remember where SEGREL32 relocs
+ occurred. Consider what happens if someone inept creates a
+ linker script that puts unwind information in .text. */
+
+ s = bfd_get_section_by_name (abfd, ".PARISC.unwind");
+ if (s != NULL)
+ {
+ bfd_size_type size;
+ char *contents;
+
+ size = s->_raw_size;
+ contents = bfd_malloc (size);
+ if (contents == NULL)
+ return false;
+
+ if (! bfd_get_section_contents (abfd, s, contents, (file_ptr) 0, size))
+ return false;
+
+ qsort (contents, (size_t) (size / 16), 16, hppa_unwind_entry_compare);
+
+ if (! bfd_set_section_contents (abfd, s, contents, (file_ptr) 0, size))
+ return false;
+ }
+
+ return true;
+}
+
#if ARCH_SIZE == 64
/* Hook called by the linker routine which adds symbols from an object
file. HP's libraries define symbols with HP specific section
@@ -1245,6 +1310,12 @@
elf_link_hash_traverse (elf_hash_table (info),
elf_hppa_remark_useless_dynamic_symbols,
info);
+
+ /* If we're producing a final executable, sort the contents of the
+ unwind section. */
+
+ if (retval)
+ retval = elf_hppa_sort_unwind (abfd);
return retval;
}