2.10.91: A problem with LINK_ONCE_DISCARD sections on mipsel-linux

Alan Modra alan@linuxcare.com.au
Wed Oct 4 21:56:00 GMT 2000


On Tue, 3 Oct 2000, Maciej W. Rozycki wrote:

>  Hmm, maybe we could mark such symbols global?...

This patch does the trick.

bfd/ChangeLog
	* elf.c (swap_out_syms): Handle global section symbols.

gas/ChangeLog
	* config/obj-elf.c (elf_frob_symbol): Make section syms global on
	link-once sections.

Not installed yet, because I'd like to hear from Ian (and any other ELF
expert who'd like to comment) whether this is a wise move.  Grepping
through the code says it's unlikely to break any port, with the
possibile exception of elf32-mips.

Alan Modra
-- 
Linuxcare.  Support for the Revolution.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.55
diff -u -p -r1.55 elf.c
--- elf.c	2000/09/30 00:44:49	1.55
+++ elf.c	2000/10/05 04:23:47
@@ -4346,8 +4346,9 @@ swap_out_syms (abfd, sttp, relocatable_p
 	flagword flags = syms[idx]->flags;
 	int type;
 
-	if (flags & BSF_SECTION_SYM)
-	  /* Section symbols have no names.  */
+	/* Section symbols usually have no name.  The exception is
+	   link-once section symbols, which we make global.  */
+	if ((flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)
 	  sym.st_name = 0;
 	else
 	  {
@@ -4455,7 +4456,8 @@ swap_out_syms (abfd, sttp, relocatable_p
           type = (*bed->elf_backend_get_symbol_type) (&type_ptr->internal_elf_sym, type);
 
 	if (flags & BSF_SECTION_SYM)
-	  sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
+	  sym.st_info = ELF_ST_INFO ((flags & BSF_GLOBAL
+				      ? STB_GLOBAL : STB_LOCAL), STT_SECTION);
 	else if (bfd_is_com_section (syms[idx]->section))
 	  sym.st_info = ELF_ST_INFO (STB_GLOBAL, type);
 	else if (bfd_is_und_section (syms[idx]->section))
Index: gas/config/obj-elf.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.c,v
retrieving revision 1.21
diff -u -p -r1.21 obj-elf.c
--- obj-elf.c	2000/09/14 11:48:26	1.21
+++ obj-elf.c	2000/10/05 04:24:43
@@ -1742,6 +1742,21 @@ elf_frob_symbol (symp, puntp)
       && S_IS_DEFINED (symp))
     symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
 #endif
+
+  if (symbol_section_p (symp))
+    {
+      asection *symsec = S_GET_SEGMENT (symp);
+
+      if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE) != 0
+	  || strncmp (segment_name (symsec), ".gnu.linkonce",
+		      sizeof ".gnu.linkonce" - 1) == 0)
+	{
+	  /* Make section syms global on ELF linkonce sections.
+	     This way, any reference to the section symbol will
+	     resolve to the section that actually stays in.  */
+	  S_SET_EXTERNAL (symp);
+	}
+    }
 }
 
 void




More information about the Binutils mailing list