yann@1: From http://sources.redhat.com/ml/binutils/2004-08/msg00190.html yann@1: yann@1: Date: Tue, 17 Aug 2004 12:04:29 +0200 yann@1: From: Jakub Jelinek yann@1: To: binutils at sources dot redhat dot com yann@1: Subject: [PATCH] Fix `defined in discarded section' errors when building ia64 gcc yann@1: Message-ID: <20040817100429.GL30497@sunsite.ms.mff.cuni.cz> yann@1: Reply-To: Jakub Jelinek yann@1: References: <20040817090201.GK30497@sunsite.ms.mff.cuni.cz> yann@1: In-Reply-To: <20040817090201 dot GK30497 at sunsite dot ms dot mff dot cuni dot cz> yann@1: yann@1: On Tue, Aug 17, 2004 at 11:02:01AM +0200, Jakub Jelinek wrote: yann@1: > Current gcc 3.4.x (at least gcc-3_4-rhl-branch) doesn't build with CVS yann@1: > binutils (nor 2.15.91.0.2). yann@1: > The problem is that libstdc++.so linking fails with: yann@1: > `.gnu.linkonce.t._ZNSdD2Ev' referenced in section `.gnu.linkonce.ia64unw._ZNSdD2Ev' of .libs/sstream-inst.o: defined in discarded section `.gnu.linkonce.t._ZNSdD2Ev' of .libs/sstream-inst.o yann@1: > The problem is that both io-inst.s and sstream-inst.s have yann@1: > .gnu.linkonce.t._ZNSdD2Ev definition, but because io-inst.cc yann@1: > also instantiates some templates sstream-inst.cc doesn't instantiate, yann@1: > the inliner can do a better job in io-inst.cc. yann@1: > The result is that _ZNSdD2Ev in io-inst.cc is a leaf routine, while yann@1: > it is not in sstream-inst.cc (in assembly, yann@1: > _ZNSdD2Ev in io-inst.s starts with .prologue and no .save directives, yann@1: > while _ZNSdD2Ev] in sstream-inst.s has .prologue 12, 35 and some yann@1: > .save directives. yann@1: > IA-64 ABI allows leaf routines to have no unwind section at all, yann@1: > which means .gnu.linkonce.ia64unw._ZNSdD2Ev is not created in yann@1: > io-inst.o at all and as .gnu.linkonce.t._ZNSdD2Ev comes first yann@1: > and wins, .gnu.linkonce.ia64unw._ZNSdD2Ev in sstream.o suddenly yann@1: > references a discarded section. yann@1: > yann@1: > Not sure what should be done here, but certainly the compiler yann@1: > isn't at fault here, it is a binutils problem. yann@1: > One fix could be to create empty .gnu.linkonce.ia64unw.* section yann@1: > in assembler, another special case ia64 unwind sections in the linker. yann@1: yann@1: Here is a patch for the first possibility. yann@1: It certainly makes libstdc++.so to link and even the unwind info looks yann@1: good on brief skimming. yann@1: yann@1: 2004-08-17 Jakub Jelinek yann@1: yann@1: * config/tc-ia64.c (start_unwind_section): Add linkonce_empty yann@1: argument, don't do anything if current section is not yann@1: .gnu.linkonce.t.* and linkonce_empty is set. yann@1: (generate_unwind_image, dot_endp): Adjust callers, call yann@1: start_unwind_section (*, 1) if nothing will be put into the yann@1: section. yann@1: yann@1: --- binutils/gas/config/tc-ia64.c.jj 2004-07-30 11:42:24.000000000 +0200 yann@1: +++ binutils/gas/config/tc-ia64.c 2004-08-17 13:45:04.288173205 +0200 yann@1: @@ -1,5 +1,6 @@ yann@1: /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture. yann@1: - Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. yann@1: + Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 yann@1: + Free Software Foundation, Inc. yann@1: Contributed by David Mosberger-Tang yann@1: yann@1: This file is part of GAS, the GNU Assembler. yann@1: @@ -3297,7 +3298,7 @@ static char *special_linkonce_name[] = yann@1: }; yann@1: yann@1: static void yann@1: -start_unwind_section (const segT text_seg, int sec_index) yann@1: +start_unwind_section (const segT text_seg, int sec_index, int linkonce_empty) yann@1: { yann@1: /* yann@1: Use a slightly ugly scheme to derive the unwind section names from yann@1: @@ -3359,6 +3360,8 @@ start_unwind_section (const segT text_se yann@1: prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND]; yann@1: suffix += sizeof (".gnu.linkonce.t.") - 1; yann@1: } yann@1: + else if (linkonce_empty) yann@1: + return; yann@1: yann@1: prefix_len = strlen (prefix); yann@1: suffix_len = strlen (suffix); yann@1: @@ -3444,7 +3447,7 @@ generate_unwind_image (const segT text_s yann@1: expressionS exp; yann@1: bfd_reloc_code_real_type reloc; yann@1: yann@1: - start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO); yann@1: + start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO, 0); yann@1: yann@1: /* Make sure the section has 4 byte alignment for ILP32 and yann@1: 8 byte alignment for LP64. */ yann@1: @@ -3485,6 +3488,8 @@ generate_unwind_image (const segT text_s yann@1: unwind.personality_routine = 0; yann@1: } yann@1: } yann@1: + else yann@1: + start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO, 1); yann@1: yann@1: free_saved_prologue_counts (); yann@1: unwind.list = unwind.tail = unwind.current_entry = NULL; yann@1: @@ -4164,7 +4169,7 @@ dot_endp (dummy) yann@1: subseg_set (md.last_text_seg, 0); yann@1: unwind.proc_end = expr_build_dot (); yann@1: yann@1: - start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND); yann@1: + start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND, 0); yann@1: yann@1: /* Make sure that section has 4 byte alignment for ILP32 and yann@1: 8 byte alignment for LP64. */ yann@1: @@ -4204,6 +4209,9 @@ dot_endp (dummy) yann@1: bytes_per_address); yann@1: yann@1: } yann@1: + else yann@1: + start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND, 1); yann@1: + yann@1: subseg_set (saved_seg, saved_subseg); yann@1: yann@1: /* Parse names of main and alternate entry points and set symbol sizes. */ yann@1: yann@1: yann@1: Jakub yann@1: