This is the mail archive of the binutils@sourceware.org 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: [BFD][PR21703]Override the new defined symbol with the old normal symbol when --allow-multiple-definition is provided


Hi Alan,

On 08/07/17 03:11, Alan Modra wrote:
On Fri, Jul 07, 2017 at 05:41:04PM +0100, Renlin Li wrote:
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 471e8ad..e4ab670 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1547,6 +1547,17 @@ _bfd_elf_merge_symbol (bfd *abfd,
        sec = *psec;
      }

+  /* There are multiple definitions of a normal symbol.  */
+  if (olddef && !olddyn && !oldweak && newdef && !newdyn && !newweak
+      && !*matched)

I think !*matched is wrong, and will likely mean the patch doesn't fix
your PR.
I meant to skip the case for versioned symbol. This function will be called with short name for versioned symbol. That's should be skipped.

I correct the condition and add one more condition for ld plugin case.

+    {
+      /* Handle a multiple definition.  */
+      (*info->callbacks->multiple_definition) (info, &h->root,
+					       abfd, sec, sym->st_value);

Please use *pvalue here rather than sym->st_value.

Updated.
A new test case is added. The symbol foo in the final object should be of size 4 which comes from the first object file.


Here, the symbol types are not required to be the same. I think this is the desired behavior?

ld cross and native checked Okay for arm environment. glibc builds Okay with the patched linker.

Okay?

Regards,
Renlin

ld/ChangeLog:

2017-07-11  Renlin Li  <renlin.li@arm.com>

        PR ld/21703
	* testsuite/ld-elf/elf.exp : Run new test case.
	* testsuite/ld-elf/pr21703-1.s: New.
	* testsuite/ld-elf/pr21703-2.s: New.
	* testsuite/ld-elf/pr21703.sd: New.

bfd/ChangeLog:

2017-07-11  Renlin Li  <renlin.li@arm.com>

        PR ld/21703
	* elflink.c (_bfd_elf_merge_symbol): Handle multiple symbol definition
	case.

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 471e8ad..91d2bbb 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1036,6 +1036,7 @@ _bfd_elf_merge_symbol (bfd *abfd,
   bfd_boolean newweak, oldweak, newfunc, oldfunc;
   const struct elf_backend_data *bed;
   char *new_version;
+  bfd_boolean versioned_sym = *matched;
 
   *skip = FALSE;
   *override = FALSE;
@@ -1547,6 +1548,17 @@ _bfd_elf_merge_symbol (bfd *abfd,
       sec = *psec;
     }
 
+  /* There are multiple definitions of a normal symbol.  */
+  if (olddef && !olddyn && !oldweak && newdef && !newdyn && !newweak
+      && !versioned_sym && h->def_regular)
+    {
+      /* Handle a multiple definition.  */
+      (*info->callbacks->multiple_definition) (info, &h->root,
+					       abfd, sec, *pvalue);
+      *skip = TRUE;
+      return TRUE;
+    }
+
   /* If both the old and the new symbols look like common symbols in a
      dynamic object, set the size of the symbol to the larger of the
      two.  */
diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp
index 80a8c42..2dcebb9 100644
--- a/ld/testsuite/ld-elf/elf.exp
+++ b/ld/testsuite/ld-elf/elf.exp
@@ -70,6 +70,12 @@ run_ld_link_tests [list \
 	{symbol3w.s} {} "symbol3w.a" ] \
 ]
 
+run_ld_link_tests [list \
+    [list "PR ld/21703" \
+	"--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
+	{pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" ] \
+]
+
 if { [check_shared_lib_support] } then {
     run_ld_link_tests {
 	{"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
diff --git a/ld/testsuite/ld-elf/pr21703-1.s b/ld/testsuite/ld-elf/pr21703-1.s
new file mode 100644
index 0000000..92a4718
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21703-1.s
@@ -0,0 +1,6 @@
+	.text
+	.globl	foo
+	.type	foo, %function
+foo:
+	.space	4
+	.size	foo, 4
diff --git a/ld/testsuite/ld-elf/pr21703-2.s b/ld/testsuite/ld-elf/pr21703-2.s
new file mode 100644
index 0000000..1d65304
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21703-2.s
@@ -0,0 +1,6 @@
+	.text
+	.globl	foo
+	.type	foo, %function
+foo:
+	.space	16
+	.size	foo, 16
diff --git a/ld/testsuite/ld-elf/pr21703.sd b/ld/testsuite/ld-elf/pr21703.sd
new file mode 100644
index 0000000..955cf17
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21703.sd
@@ -0,0 +1,4 @@
+Symbol table '.symtab' contains .* entries:
+#...
+.*: [0-9a-fA-F]* +4 +FUNC +GLOBAL +DEFAULT +. foo
+#pass

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