This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Symbols in discarded sections.


This time with the right attachment.

On Wednesday 01 December 2004 20:32, Paul Brook wrote:
> The ELF specification says that when a COMDAT section is discarded, the
> global symbols defined relative to that section should be converted to
> undefined symbols.
>
> Failure to do this was causing problems problems linking some C++ code from
> different vendors. One object file defined a comdat section with a weak
> definition of a symbol. The other defined the same comdat section with a
> strong definition of the symbol. ld discarded the latter section, but still
> resolved symbol references to the [discarded] strong definition.
>
> Tested on i686-linux and cross to arm-none-eabi.
> Ok?
>
> 2004-12-01  Paul Brook  <paul@codesourcery.com>
>
> bfd/
>  * elflink.c (elf_link_add_object_symbols): Make symbols from discarded
>  sections undefined.
> ld/testsuite/
>  * ld-elf/group1.d: New test.
>  * ld-elf/group.ld, ld-elf/group1a.s, ld-elf/group1b.s: New test.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.118
diff -u -p -r1.118 elflink.c
--- bfd/elflink.c	15 Nov 2004 23:21:24 -0000	1.118
+++ bfd/elflink.c	1 Dec 2004 20:09:45 -0000
@@ -3425,6 +3425,13 @@ elf_link_add_object_symbols (bfd *abfd, 
 	  sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
 	  if (sec == NULL)
 	    sec = bfd_abs_section_ptr;
+	  else if (sec->kept_section
+		   && bfd_is_abs_section (sec->output_section))
+	    {
+	      /* Symbols from discarded section are undefined.  */
+	      sec = bfd_und_section_ptr;
+	      isym->st_shndx = SHN_UNDEF;
+	    }
 	  else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
 	    value -= sec->vma;
 	}
Index: ld/testsuite/ld-elf/group.ld
===================================================================
RCS file: ld/testsuite/ld-elf/group.ld
diff -N ld/testsuite/ld-elf/group.ld
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/group.ld	1 Dec 2004 20:09:48 -0000
@@ -0,0 +1,5 @@
+SECTIONS
+{
+  . = 0x1000;
+  .text : { *(.text) }
+}
Index: ld/testsuite/ld-elf/group1.d
===================================================================
RCS file: ld/testsuite/ld-elf/group1.d
diff -N ld/testsuite/ld-elf/group1.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/group1.d	1 Dec 2004 20:09:48 -0000
@@ -0,0 +1,9 @@
+#source: group1a.s
+#source: group1b.s
+#ld: -T group.ld
+#readelf: -s
+Symbol table '.symtab' contains .* entries:
+#...
+    .*: 00001000     0 NOTYPE  WEAK   DEFAULT    . foo
+    .*: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
+#...
Index: ld/testsuite/ld-elf/group1a.s
===================================================================
RCS file: ld/testsuite/ld-elf/group1a.s
diff -N ld/testsuite/ld-elf/group1a.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/group1a.s	1 Dec 2004 20:09:48 -0000
@@ -0,0 +1,4 @@
+	.section .text,"axG",%progbits,foo_group,comdat
+	.weak foo
+foo:
+	.word 0
Index: ld/testsuite/ld-elf/group1b.s
===================================================================
RCS file: ld/testsuite/ld-elf/group1b.s
diff -N ld/testsuite/ld-elf/group1b.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/group1b.s	1 Dec 2004 20:09:48 -0000
@@ -0,0 +1,6 @@
+	.section .text,"axG",%progbits,foo_group,comdat
+	.global foo
+	.global bar
+foo:
+	.word 0
+bar:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]