This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Committed: fix undefweak hidden references for CRIS
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: binutils at sourceware dot org
- Date: Tue, 27 Jan 2009 07:10:40 +0100
- Subject: Committed: fix undefweak hidden references for CRIS
The bug caught a bfd_assert, which *REALLY* isn't helpful, as
this is just a call to _bfd_error_handler and then linking
continues with *no* exit error. I've changed bfd_assert locally
to do like bfd_abort and also call _exit (EXIT_FAILURE), and I'd
like to poll interest in doing that or the equivalent for the
FSF code too. If nothing else, a helpful code comment why it
isn't done. I guess letting it continue is helpful for some
situations and bfd users, but not the common case of the linker.
Perhaps do it optionally, default on for the linker?
Over to the patch. Without this, the test-case catches:
./ld-new: BFD (GNU Binutils) 2.19.51.20090118 assertion fail /home/hp/binutils/src/bfd/elf32-cris.c:1544
and continues to emit a relocation with an invalid symbol index.
To avoid this and other R_CRIS_NONE's, elf32-cris.c should be
changed to not allocate room for relocs in
cris_elf_check_relocs, but instead do like elf32-i386.c and do
that separately in elf_cris_size_dynamic_sections. But I'll
have to leave that for later.
Tested cris-elf and committed.
ld/testsuite:
* ld-cris/weakhiddso.d, ld-cris/weakhid.s: New test.
bfd:
* elf32-cris.c (cris_elf_relocate_section) <case R_CRIS_8>
<R_CRIS_16, R_CRIS_32>: Don't call BFD_ASSERT for weak undefined
symbols with non-default visibility.
Index: ld-cris/weakhid.s
===================================================================
RCS file: ld-cris/weakhid.s
diff -N ld-cris/weakhid.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/weakhid.s 27 Jan 2009 05:59:29 -0000
@@ -0,0 +1,13 @@
+ .weak xweakobj
+ .weak xweakhidobj
+ .hidden xweakhidobj
+
+ .data
+ .global x
+ .type x,@object
+x:
+ .dword xweakhidobj
+ .dword xweakobj
+ .dword xregobj
+.Lfe1:
+ .size x,.Lfe1-x
Index: ld-cris/weakhiddso.d
===================================================================
RCS file: ld-cris/weakhiddso.d
diff -N ld-cris/weakhiddso.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/weakhiddso.d 27 Jan 2009 05:59:29 -0000
@@ -0,0 +1,31 @@
+#source: weakhid.s
+#as: --pic --no-underscore --em=criself
+#ld: --shared -m crislinux -z nocombreloc
+#objdump: -s -R -T
+
+# Check that .weak and .weak .hidden object references are handled
+# correctly when generating a DSO. For now, we have to live with the
+# R_CRIS_NONE entry.
+
+.*: file format elf32-cris
+
+DYNAMIC SYMBOL TABLE:
+0+2214 l d \.data 0+ .data
+0+2214 g DO \.data 0+c x
+0+ D \*UND\* 0+ xregobj
+0+2220 g D \*ABS\* 0+ __bss_start
+0+ w D \*UND\* 0+ xweakobj
+0+2220 g D \*ABS\* 0+ _edata
+0+2220 g D \*ABS\* 0+ _end
+
+
+DYNAMIC RELOCATION RECORDS
+OFFSET TYPE VALUE
+0+ R_CRIS_NONE \*ABS\*
+0+2218 R_CRIS_32 xweakobj
+0+221c R_CRIS_32 xregobj
+
+Contents of section \.hash:
+#...
+Contents of section .data:
+ 2214 00000000 00000000 00000000 .*
Index: elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.98
diff -p -u -r1.98 elf32-cris.c
--- elf32-cris.c 19 Jan 2009 17:32:59 -0000 1.98
+++ elf32-cris.c 27 Jan 2009 06:00:25 -0000
@@ -1528,7 +1528,16 @@ cris_elf_relocate_section (output_bfd, i
rel->r_offset);
if (outrel.r_offset == (bfd_vma) -1)
skip = TRUE;
- else if (outrel.r_offset == (bfd_vma) -2)
+ else if (outrel.r_offset == (bfd_vma) -2
+ /* For now, undefined weak symbols with non-default
+ visibility (yielding 0), like exception info for
+ discarded sections, will get a R_CRIS_NONE
+ relocation rather than no relocation, because we
+ notice too late that the symbol doesn't need a
+ relocation. */
+ || (h != NULL
+ && h->root.type == bfd_link_hash_undefweak
+ && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT))
skip = TRUE, relocate = TRUE;
outrel.r_offset += (input_section->output_section->vma
+ input_section->output_offset);
brgds, H-P