1From 4e8aef974603dcb5b994d7fdf7c9f4f1a7493150 Mon Sep 17 00:00:00 2001 2From: Chao-ying Fu <fu@mips.com> 3Date: Fri, 25 May 2012 11:59:55 -0700 4Subject: [PATCH] Fix elfxx-mips.c, mipself.em and elf.c with 5 fixes: a. 5 http://sourceware.org/bugzilla/show_bug.cgi?id=12637 6 mips-linux-gnu: relocation truncated to fit: R_MIPS_TLS_LDM 7 b. http://sourceware.org/bugzilla/show_bug.cgi?id=12845 ld 8 segfaults when using --gc-sections c. 9 http://sourceware.org/ml/binutils/2011-05/msg00198.html 10 Refix MIPS GOT_PAGE counting d. Follow warning symbol link 11 in mips_elf_count_got_symbols. e. Follow warning symbol 12 link in mips_elf_allocate_lazy_stub. 13 14--- 15 binutils-2.21/bfd/elf.c | 2 ++ 16 binutils-2.21/bfd/elfxx-mips.c | 32 ++++++++++++++++++++++++-------- 17 binutils-2.21/ld/emultempl/mipself.em | 5 +++++ 18 3 files changed, 31 insertions(+), 8 deletions(-) 19 20diff --git a/binutils-2.21/bfd/elf.c b/binutils-2.21/bfd/elf.c 21index 92993a0..3c11bec 100644 22--- a/binutils-2.21/bfd/elf.c 23+++ b/binutils-2.21/bfd/elf.c 24@@ -6213,6 +6213,8 @@ _bfd_elf_init_private_section_data (bfd *ibfd, 25 || obfd->xvec->flavour != bfd_target_elf_flavour) 26 return TRUE; 27 28+ BFD_ASSERT (elf_section_data (osec) != NULL); 29+ 30 /* For objcopy and relocatable link, don't copy the output ELF 31 section type from input if the output BFD section flags have been 32 set to something different. For a final link allow some flags 33diff --git a/binutils-2.21/bfd/elfxx-mips.c b/binutils-2.21/bfd/elfxx-mips.c 34index 4718dd4..5178b20 100644 35--- a/binutils-2.21/bfd/elfxx-mips.c 36+++ b/binutils-2.21/bfd/elfxx-mips.c 37@@ -1726,6 +1726,11 @@ mips_elf_check_symbols (struct mips_elf_link_hash_entry *h, void *data) 38 39 if (mips_elf_local_pic_function_p (h)) 40 { 41+ /* PR 12845: If H is in a section that has been garbage 42+ collected it will have its output section set to *ABS*. */ 43+ if (bfd_is_abs_section (h->root.root.u.def.section->output_section)) 44+ return TRUE; 45+ 46 /* H is a function that might need $25 to be valid on entry. 47 If we're creating a non-PIC relocatable object, mark H as 48 being PIC. If we're creating a non-relocatable object with 49@@ -3852,6 +3857,10 @@ mips_elf_count_got_symbols (struct mips_elf_link_hash_entry *h, void *data) 50 struct mips_elf_link_hash_table *htab; 51 struct mips_got_info *g; 52 53+ /* Follow warning symbol link. */ 54+ if (h->root.root.type == bfd_link_hash_warning) 55+ h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link; 56+ 57 info = (struct bfd_link_info *) data; 58 htab = mips_elf_hash_table (info); 59 g = htab->got_info; 60@@ -4080,14 +4089,18 @@ mips_elf_merge_got_with (struct mips_elf_bfd2got_hash *bfd2got, 61 if (estimate >= from->page_gotno + to->page_gotno) 62 estimate = from->page_gotno + to->page_gotno; 63 64- /* And conservatively estimate how many local, global and TLS entries 65+ /* And conservatively estimate how many local and TLS entries 66 would be needed. */ 67- estimate += (from->local_gotno 68- + from->global_gotno 69- + from->tls_gotno 70- + to->local_gotno 71- + to->global_gotno 72- + to->tls_gotno); 73+ estimate += from->local_gotno + to->local_gotno; 74+ estimate += from->tls_gotno + to->tls_gotno; 75+ 76+ /* If we're merging with the primary got, we will always have 77+ the full set of global entries. Otherwise estimate those 78+ conservatively as well. */ 79+ if (to == arg->primary) 80+ estimate += arg->global_count; 81+ else 82+ estimate += from->global_gotno + to->global_gotno; 83 84 /* Bail out if the combined GOT might be too big. */ 85 if (estimate > arg->max_count) 86@@ -7736,7 +7749,6 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, 87 if (!mips_elf_record_got_page_entry (info, abfd, r_symndx, 88 addend)) 89 return FALSE; 90- break; 91 } 92 /* Fall through. */ 93 94@@ -8601,6 +8613,10 @@ mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry *h, void **data) 95 { 96 struct mips_elf_link_hash_table *htab; 97 98+ /* Follow warning symbol link. */ 99+ if (h->root.root.type == bfd_link_hash_warning) 100+ h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link; 101+ 102 htab = (struct mips_elf_link_hash_table *) data; 103 if (h->needs_lazy_stub) 104 { 105diff --git a/binutils-2.21/ld/emultempl/mipself.em b/binutils-2.21/ld/emultempl/mipself.em 106index 7a13d4d..ada0786 100644 107--- a/binutils-2.21/ld/emultempl/mipself.em 108+++ b/binutils-2.21/ld/emultempl/mipself.em 109@@ -138,6 +138,11 @@ mips_add_stub_section (const char *stub_sec_name, asection *input_section, 110 lang_output_section_statement_type *os; 111 struct hook_stub_info info; 112 113+ /* PR 12845: If the input section has been garbage collected it will 114+ not have its output section set to *ABS*. */ 115+ if (bfd_is_abs_section (output_section)) 116+ return NULL; 117+ 118 /* Create the stub file, if we haven't already. */ 119 if (stub_file == NULL) 120 { 121-- 1221.7.7.3 123 124