This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: PATCH: Fix linkonce for ELF/PPC.
On Mon, Oct 29, 2001 at 01:57:39PM -0800, Geoff Keating wrote:
> > Date: Mon, 29 Oct 2001 09:09:56 -0800
> > From: "H . J . Lu" <hjl@lucon.org>
> > Content-Disposition: inline
> > User-Agent: Mutt/1.2.5i
> >
> > On Mon, Oct 29, 2001 at 08:47:21AM -0800, H . J . Lu wrote:
> > > On Sun, Oct 28, 2001 at 10:49:39PM -0800, H . J . Lu wrote:
> > > > On Mon, Oct 29, 2001 at 05:04:55PM +1030, Alan Modra wrote:
> > > > > On Sun, Oct 28, 2001 at 09:58:26PM -0800, H . J . Lu wrote:
> > > > > >
> > > > > > I don't know how it happens on ELF/PPC. The problem can be in linker,
> > > > > > gcc and glibc. What I saw was the gcc couldn't catch the exception with
> > > > > > libstdc++.so built by the current ld. It just aborted. Also see
> > > > > >
> > > > > > http://gcc.gnu.org/ml/gcc/2001-09/msg01248.html
> > > > > >
> > > > > > It may or may not be related. Feel to find a real fix for the problem.
> > > > > > But we still need a workaround in the meantime.
> > > > >
> > > > > Hmm, considering the above post and Geoff Keating's previous remarks
> > > > > (http://sources.redhat.com/ml/binutils/2001-06/msg00413.html) about
> > > >
> > > > FWIW, binutils 2.11.92.0.10 seems ok with static libstdc++.a in gcc
> > > > 3.1.
> > > >
> > > > > requiring zeros, I can't see how we can implement a correct solution
> > > > > in binutils. It seems to me that this is a gcc bug, and we shouldn't
> > > > > be tweaking binutils at all.
> > > >
> > > > It is ok with me as long as we all agree it is a gcc bug.
> > > >
> > > > Franz, do you have any problems with the current Linux/PPC gcc and
> > > > binutils 2.11.92.0.10? If not, please report it as a gcc 3.x bug.
> > > >
> > > >
> > >
> > > I have a question. Is it possible for ELF/PPC that for symbol reference,
> > > the assembler generates RELA relocations such that the static/dynamic
> > > linkers have to apply addend, even for undefined symbols?
> > >
> >
> > Another question. Will all ELF targets using RELA in DSO have the same
> > problem?
>
> It's not a problem, it's a feature.
>
Then, how abou this patch?
H.J.
----
2001-10-29 H.J. Lu (hjl@gnu.org)
* elf-bfd.h (struct elf_backend_data): Add
elf_backend_remove_linkonce_relocation.
(_bfd_elf32_remove_linkonce_rel): Delcare.
(_bfd_elf32_remove_linkonce_rela): Delcare.
(_bfd_elf64_remove_linkonce_rel): Delcare.
(_bfd_elf64_remove_linkonce_rela): Delcare.
* elfcode.h (elf_remove_linkonce_rel): Define.
(elf_remove_linkonce_rela): Define.
* elflink.h (elf_link_input_bfd): Call
elf_backend_remove_linkonce_relocation to remove a linkonce
relocation.
* elfxx-target.h (elf_backend_remove_linkonce_relocation):
Define.
(elfNN_bed): Init elf_backend_remove_linkonce_relocation.
--- bfd/elf-bfd.h.linkonce Mon Oct 15 11:14:48 2001
+++ bfd/elf-bfd.h Mon Oct 29 16:49:54 2001
@@ -699,6 +699,11 @@ struct elf_backend_data
enum elf_reloc_type_class (*elf_backend_reloc_type_class)
PARAMS ((const Elf_Internal_Rela *));
+ /* This function modifies a relocation against a removed linkonce
+ section. */
+ void (*elf_backend_remove_linkonce_relocation)
+ PARAMS ((Elf_Internal_Rela *));
+
/* The swapping table to use when dealing with ECOFF information.
Used for the MIPS ELF .mdebug section. */
const struct ecoff_debug_swap *elf_backend_ecoff_debug_swap;
@@ -1408,6 +1413,15 @@ extern boolean _bfd_elf64_gc_record_vtin
extern boolean _bfd_elf64_gc_record_vtentry
PARAMS ((bfd *, asection *, struct elf_link_hash_entry *, bfd_vma));
+extern void _bfd_elf32_remove_linkonce_rel
+ PARAMS ((Elf_Internal_Rela *));
+extern void _bfd_elf32_remove_linkonce_rela
+ PARAMS ((Elf_Internal_Rela *));
+extern void _bfd_elf64_remove_linkonce_rel
+ PARAMS ((Elf_Internal_Rela *));
+extern void _bfd_elf64_remove_linkonce_rela
+ PARAMS ((Elf_Internal_Rela *));
+
/* MIPS ELF specific routines. */
extern boolean _bfd_mips_elf_object_p
--- bfd/elfcode.h.linkonce Fri Oct 19 09:57:21 2001
+++ bfd/elfcode.h Mon Oct 29 16:47:44 2001
@@ -135,6 +135,8 @@ Foundation, Inc., 59 Temple Place - Suit
#define elf_gc_record_vtentry NAME(_bfd_elf,gc_record_vtentry)
#define elf_link_record_local_dynamic_symbol \
NAME(_bfd_elf,link_record_local_dynamic_symbol)
+#define elf_remove_linkonce_rel NAME(_bfd_elf,remove_linkonce_rel)
+#define elf_remove_linkonce_rela NAME(_bfd_elf,remove_linkonce_rela)
#if ARCH_SIZE == 64
#define ELF_R_INFO(X,Y) ELF64_R_INFO(X,Y)
@@ -1432,6 +1434,21 @@ elf_slurp_reloc_table (abfd, asect, symb
return true;
}
+void
+elf_remove_linkonce_rel (rel)
+ Elf_Internal_Rela *rel;
+{
+ memset (rel, 0, sizeof (*rel));
+}
+
+void
+elf_remove_linkonce_rela (rel)
+ Elf_Internal_Rela *rel;
+{
+ long r_type = ELF_R_TYPE (rel->r_info);
+ rel->r_info = ELF_R_INFO (STN_UNDEF, r_type);
+}
+
#ifdef DEBUG
static void
elf_debug_section (num, hdr)
--- bfd/elflink.h.linkonce Sun Oct 28 09:42:00 2001
+++ bfd/elflink.h Mon Oct 29 15:21:33 2001
@@ -6332,7 +6332,7 @@ elf_link_input_bfd (finfo, input_bfd)
_("warning: relocation against removed section; zeroing"),
NULL, input_bfd, o, rel->r_offset);
#endif
- memset (rel, 0, sizeof (*rel));
+ (*bed->elf_backend_remove_linkonce_relocation) (rel);
}
}
}
--- bfd/elfxx-target.h.linkonce Mon Oct 15 11:15:21 2001
+++ bfd/elfxx-target.h Mon Oct 29 16:11:46 2001
@@ -355,6 +355,15 @@ Foundation, Inc., 59 Temple Place - Suit
#ifndef elf_backend_reloc_type_class
#define elf_backend_reloc_type_class _bfd_elf_reloc_type_class
#endif
+#ifndef elf_backend_remove_linkonce_relocation
+#ifdef USE_RELA
+#define elf_backend_remove_linkonce_relocation \
+ _bfd_elfNN_remove_linkonce_rela
+#else
+#define elf_backend_remove_linkonce_relocation \
+ _bfd_elfNN_remove_linkonce_rel
+#endif
+#endif
/* Previously, backends could only use SHT_REL or SHT_RELA relocation
sections, but not both. They defined USE_REL to indicate SHT_REL
@@ -443,6 +452,7 @@ static const struct elf_backend_data elf
elf_backend_sprintf_vma,
elf_backend_fprintf_vma,
elf_backend_reloc_type_class,
+ elf_backend_remove_linkonce_relocation,
elf_backend_ecoff_debug_swap,
ELF_MACHINE_ALT1,
ELF_MACHINE_ALT2,