Skip to contentSkip to conversation

binutils: fix xtensa ld bug triggered by --gc-sections

PATCH New Max Filippov 2 participants 4 messages May 14, 2015 – May 16, 2015

lore
Share & tools
lore
#0 lore raw

cover binutils: fix xtensa ld bug triggered by --gc-sections

Hi,

this series backports binutils fix for xtensa ld and reverts old workaround for this bug.

Max Filippov (2):
binutils: fix xtensa ld bug triggered by --gc-sections Revert "kmod: disable --gc-sections ld option when building for
xtensa"

 ...localized-symbol-refcounting-with-gc-sect.patch | 57 ++++++++++++++++++++++
 ...localized-symbol-refcounting-with-gc-sect.patch | 57 ++++++++++++++++++++++
 ...localized-symbol-refcounting-with-gc-sect.patch | 57 ++++++++++++++++++++++
 ...localized-symbol-refcounting-with-gc-sect.patch | 57 ++++++++++++++++++++++
 package/kmod/kmod.mk                               |  5 --
 5 files changed, 228 insertions(+), 5 deletions(-)
 create mode 100644 package/binutils/2.22/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch
 create mode 100644 package/binutils/2.23.2/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch
 create mode 100644 package/binutils/2.24/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch
 create mode 100644 package/binutils/2.25/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 1/2 binutils: fix xtensa ld bug triggered by --gc-sections

elf_xtensa_gc_sweep_hook doesn't correctly unreference symbols that were made local, that results in link failure with the following message:

BFD (GNU Binutils) 2.24 internal error, aborting at elf32-xtensa.c line 3372 in elf_xtensa_finish_dynamic_sections

elf_xtensa_gc_sweep_hook determines symbol reference type (PLT or GOT) by relocation type. Relocation types are not changed when symbol becomes local, but its PLT references are added to GOT references and plt.refcount is set to 0. Such symbol cannot be unreferences in the elf_xtensa_gc_sweep_hook and its extra references make calculated GOT relocations section size not match number of GOT relocations.

Fix it by treating PLT reference as GOT reference when plt.refcount is not positive.

Fixes:
http://autobuild.buildroot.net/results/3e2e24f697e26c93d4d95782b1cb7799fa620a7a/
http://autobuild.buildroot.org/results/97d4c96d6f6cdc1ed4007456f4ab70be9dfa41b5/

---
 ...localized-symbol-refcounting-with-gc-sect.patch | 57 ++++++++++++++++++++++
 ...localized-symbol-refcounting-with-gc-sect.patch | 57 ++++++++++++++++++++++
 ...localized-symbol-refcounting-with-gc-sect.patch | 57 ++++++++++++++++++++++
 ...localized-symbol-refcounting-with-gc-sect.patch | 57 ++++++++++++++++++++++
 4 files changed, 228 insertions(+)
 create mode 100644 package/binutils/2.22/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch
 create mode 100644 package/binutils/2.23.2/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch
 create mode 100644 package/binutils/2.24/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch
 create mode 100644 package/binutils/2.25/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch
package/binutils/2.22/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch new file +57 -0
new file mode 100644
index 0000000..9ad6b3b
@@ -0,0 +1,57 @@
+From 8ec76b16f62d1bf386fb2c39af5f66c3afddc5cb Mon Sep 17 00:00:00 2001
+From: Max Filippov <[email protected]>
+Date: Thu, 14 May 2015 05:22:55 +0300
+Subject: [PATCH] xtensa: fix localized symbol refcounting with --gc-sections
+
+elf_xtensa_gc_sweep_hook doesn't correctly unreference symbols that were
+made local, that results in link failure with the following message:
+
+  BFD (GNU Binutils) 2.24 internal error, aborting at elf32-xtensa.c line
+  3372 in elf_xtensa_finish_dynamic_sections
+
+elf_xtensa_gc_sweep_hook determines symbol reference type (PLT or GOT) by
+relocation type. Relocation types are not changed when symbol becomes
+local, but its PLT references are added to GOT references and
+plt.refcount is set to 0. Such symbol cannot be unreferences in the
+elf_xtensa_gc_sweep_hook and its extra references make calculated GOT
+relocations section size not match number of GOT relocations.
+
+Fix it by treating PLT reference as GOT reference when plt.refcount is
+not positive.
+
+2015-05-14  Max Filippov  <[email protected]>
+bfd/
+	* elf32-xtensa.c (elf_xtensa_gc_sweep_hook): Treat PLT reference
+	as GOT reference when plt.refcount is not positive.
+
+Signed-off-by: Max Filippov <[email protected]>
+---
+Backported from: e6c9a083ec5ae7a45bd71682b26aae1939849388
+Changes to ChangeLog are dropped.
+
+ bfd/elf32-xtensa.c | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
+index 53af1c6..2523670 100644
+--- a/bfd/elf32-xtensa.c
++++ b/bfd/elf32-xtensa.c
+@@ -1360,10 +1360,14 @@ elf_xtensa_gc_sweep_hook (bfd *abfd,
+ 	{
+ 	  if (is_plt)
+ 	    {
++	      /* If the symbol has been localized its plt.refcount got moved
++	         to got.refcount.  Handle it as GOT.  */
+ 	      if (h->plt.refcount > 0)
+ 		h->plt.refcount--;
++	      else
++		is_got = TRUE;
+ 	    }
+-	  else if (is_got)
++	  if (is_got)
+ 	    {
+ 	      if (h->got.refcount > 0)
+ 		h->got.refcount--;
+-- 
+1.8.1.4
+
package/binutils/2.23.2/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch new file +57 -0

57 lines not on this page · raw message

package/binutils/2.24/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch new file +57 -0

57 lines not on this page · raw message

package/binutils/2.25/911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/2 Revert "kmod: disable --gc-sections ld option when building for xtensa"

In reply to Max Filippov

This reverts commit 55c83179c4b30c9ec715a75297849abd74a63e05. Now that binutils bug with --gc-section is fixed this workaroud is no longer needed.

---
 package/kmod/kmod.mk | 5 -----
 1 file changed, 5 deletions(-)
package/kmod/kmod.mk +0 -5
index 1ac83ea..98d9998 100644
@@ -39,11 +39,6 @@ KMOD_DEPENDENCIES += $(if $(BR2_PACKAGE_PYTHON),python,python3)
 KMOD_CONF_OPTS += --enable-python
 endif
 
-# --gc-sections triggers a bug in the current Xtensa binutils
-ifeq ($(BR2_xtensa),y)
-KMOD_CONF_ENV += cc_cv_LDFLAGS__Wl___gc_sections=no
-endif
-
 ifeq ($(BR2_PACKAGE_KMOD_TOOLS),y)
 
 # add license info for kmod tools
Signature · 1 line
1.8.1.4
#3 lore raw

cover binutils: fix xtensa ld bug triggered by --gc-sections

In reply to Max Filippov

Dear Max Filippov,

Quoted 9 lines · Max Filippov

Hi,

this series backports binutils fix for xtensa ld and reverts old workaround for this bug.

Max Filippov (2):
binutils: fix xtensa ld bug triggered by --gc-sections Revert "kmod: disable --gc-sections ld option when building for
xtensa"

Both patches applied, thanks a lot!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com