public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [alpha] enable --gc-sections
@ 2011-03-29 21:19 Richard Henderson
  2011-03-29 21:35 ` [rfc] fixup ld testsuite for alpha " Richard Henderson
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2011-03-29 21:19 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 298 bytes --]

Only about a decade late, I'd gotten tired of seeing these
failures when testing alpha.

There are a number of testsuite changes required here, some of
which affect generic tests.  I'll send a separate message and
rfa for those.

The actual bfd backend bits are really quite straight-forward.


r~

[-- Attachment #2: zz --]
[-- Type: text/plain, Size: 3644 bytes --]

        * elf64-alpha.c (elf64_alpha_gc_mark_hook): New.
        (elf64_alpha_gc_sweep_hook): New.
        (elf_backend_gc_mark_hook, elf_backend_gc_sweep_hook): New.
        (elf_backend_can_gc_sections): New.

diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
index aaa6e20..e83ff72 100644
--- a/bfd/elf64-alpha.c
+++ b/bfd/elf64-alpha.c
@@ -1988,6 +1988,93 @@ elf64_alpha_check_relocs (bfd *abfd, struct bfd_link_info *info,
   return TRUE;
 }
 
+/* Return the section that should be marked against GC for a given
+   relocation.  */
+
+static asection *
+elf64_alpha_gc_mark_hook (asection *sec, struct bfd_link_info *info,
+			  Elf_Internal_Rela *rel,
+			  struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)
+{
+  /* These relocations don't really reference a symbol.  Instead we store
+     extra data in their addend slot.  Ignore the symbol.  */
+  switch (ELF64_R_TYPE (rel->r_info))
+    {
+    case R_ALPHA_LITUSE:
+    case R_ALPHA_GPDISP:
+    case R_ALPHA_HINT:
+      return NULL;
+    }
+
+  return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
+}
+
+/* Update the got entry reference counts for the section being removed.  */
+
+static bfd_boolean
+elf64_alpha_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
+			   asection *sec, const Elf_Internal_Rela *relocs)
+{
+  Elf_Internal_Shdr *symtab_hdr;
+  struct alpha_elf_link_hash_entry **sym_hashes;
+  const Elf_Internal_Rela *rel, *relend;
+
+  if (info->relocatable)
+    return TRUE;
+
+  symtab_hdr = &elf_symtab_hdr (abfd);
+  sym_hashes = alpha_elf_sym_hashes (abfd);
+
+  relend = relocs + sec->reloc_count;
+  for (rel = relocs; rel < relend; rel++)
+    {
+      unsigned long r_symndx, r_type;
+      struct alpha_elf_link_hash_entry *h = NULL;
+      struct alpha_elf_got_entry *gotent;
+
+      r_symndx = ELF64_R_SYM (rel->r_info);
+      if (r_symndx >= symtab_hdr->sh_info)
+	{
+	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+	  while (h->root.root.type == bfd_link_hash_indirect
+		 || h->root.root.type == bfd_link_hash_warning)
+	    h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
+	}
+
+      r_type = ELF64_R_TYPE (rel->r_info);
+      switch (r_type)
+	{
+	case R_ALPHA_LITERAL:
+	  /* ??? Ignore re-computation of gotent_flags.  We're not
+	     carrying a use-count for each bit in that mask.  */
+
+	case R_ALPHA_TLSGD:
+	case R_ALPHA_GOTDTPREL:
+	case R_ALPHA_GOTTPREL:
+	  /* Fetch the got entry from the tables.  */
+	  gotent = get_got_entry (abfd, h, r_type, r_symndx, rel->r_addend);
+
+	  /* The got entry *must* exist, since we should have created it
+	     before during check_relocs.  Also note that get_got_entry
+	     assumed this was going to be another use, and so incremented
+	     the use count again.  Thus the use count must be at least the
+	     one real use and the "use" we just added.  */
+	  if (gotent == NULL || gotent->use_count < 2)
+	    {
+	      abort ();
+	      return FALSE;
+	    }
+	  gotent->use_count -= 2;
+	  break;
+
+	default:
+	  break;
+	}
+    }
+
+  return TRUE;
+}
+
 /* Adjust a symbol defined by a dynamic object and referenced by a
    regular object.  The current definition is in some section of the
    dynamic object, but we're not including those sections.  We have to
@@ -5384,6 +5471,10 @@ static const struct elf_size_info alpha_elf_size_info =
 #define elf_backend_reloc_type_class \
   elf64_alpha_reloc_type_class
 
+#define elf_backend_can_gc_sections	1
+#define elf_backend_gc_mark_hook	elf64_alpha_gc_mark_hook
+#define elf_backend_gc_sweep_hook	elf64_alpha_gc_sweep_hook
+
 #define elf_backend_ecoff_debug_swap \
   &elf64_alpha_ecoff_debug_swap
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [rfc] fixup ld testsuite for alpha enable --gc-sections
  2011-03-29 21:19 [alpha] enable --gc-sections Richard Henderson
@ 2011-03-29 21:35 ` Richard Henderson
  2011-03-30  5:16   ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2011-03-29 21:35 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 779 bytes --]

On 03/29/2011 02:19 PM, Richard Henderson wrote:
> Only about a decade late, I'd gotten tired of seeing these
> failures when testing alpha.
> 
> There are a number of testsuite changes required here, some of
> which affect generic tests.  I'll send a separate message and
> rfa for those.

And here's that.

The Problem is that two "generic" tests are written expecting
32-bit absolute addresses are ok, even for 64-bit targets.  For
a fair number of targets this is even true.

But alpha by default places the image base at 0x1_2000_0000,
which results in all sorts of relocation truncated errors.

This adjusts the two relevant test cases for 64-bit targets.
Which... probably causes just as many problems for some 32-bit
targets.

So.  What's the best way forward here?


r~

[-- Attachment #2: z --]
[-- Type: text/plain, Size: 5158 bytes --]

? bfd/doc/bfd.info
? gold/po/es.gmo
? gold/po/id.gmo
Index: ld/testsuite/ld-elf/compress1.s
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/compress1.s,v
retrieving revision 1.1
diff -u -p -r1.1 compress1.s
--- ld/testsuite/ld-elf/compress1.s	29 Oct 2010 12:10:39 -0000	1.1
+++ ld/testsuite/ld-elf/compress1.s	29 Mar 2011 21:19:59 -0000
@@ -37,13 +37,13 @@ func_cu2:
 .Lcu1_start:
 	.2byte	2				/* DWARF Version */
 	.4byte	.Labbrev1_begin			/* Offset into abbrev section */
-	.byte	4				/* Pointer size */
+	.byte	8				/* Pointer size */
 
 	/* CU die */
 	.uleb128 1				/* Abbrev: DW_TAG_compile_unit */
 	.4byte	.Lline1_begin			/* DW_AT_stmt_list */
-	.4byte	.Lend_text1			/* DW_AT_high_pc */
-	.4byte	.Lbegin_text1			/* DW_AT_low_pc */
+	.8byte	.Lend_text1			/* DW_AT_high_pc */
+	.8byte	.Lbegin_text1			/* DW_AT_low_pc */
 	.ascii	"file1.txt\0"			/* DW_AT_name */
 	.ascii	"GNU C 3.3.3\0"			/* DW_AT_producer */
 	.byte	1				/* DW_AT_language (C) */
@@ -55,8 +55,8 @@ func_cu2:
 	.byte		2			/* DW_AT_decl_line */
 	.ascii		"func_cu2\0"		/* DW_AT_name */
 	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
-	.4byte		.Lbegin_func_cu2	/* DW_AT_low_pc */
-	.4byte		.Lend_func_cu2		/* DW_AT_high_pc */
+	.8byte		.Lbegin_func_cu2	/* DW_AT_low_pc */
+	.8byte		.Lend_func_cu2		/* DW_AT_high_pc */
 	.byte		1			/* DW_AT_frame_base: length */
 	.byte		0x55			/* DW_AT_frame_base: DW_OP_reg5 */
 
@@ -114,9 +114,9 @@ func_cu2:
 
 .Lline1_lines:
 	.byte		0	/* DW_LNE_set_address */
-	.uleb128	5
+	.uleb128	9
 	.byte		2
-	.4byte		.Lbegin_func_cu2
+	.8byte		.Lbegin_func_cu2
 
 	.byte		3	/* DW_LNS_advance_line */
 	.sleb128	3	/* ... to 4 */
@@ -126,9 +126,9 @@ func_cu2:
 	.byte		1	/* DW_LNS_copy (second time as an end-of-prologue marker) */
 
 	.byte		0	/* DW_LNE_set_address */
-	.uleb128	5
+	.uleb128	9
 	.byte		2
-	.4byte		.Lend_func_cu2
+	.8byte		.Lend_func_cu2
 
 	.byte		0	/* DW_LNE_end_of_sequence */
 	.uleb128	1
@@ -202,15 +202,17 @@ func_cu2:
 	.4byte	0x25
 	.string	"func_cu2"
 	.4byte	0x0
+
 	.section	.debug_aranges,"",%progbits
-	.4byte	0x1c
-	.2byte	0x2
-	.4byte	.Lcu1_begin
-	.byte	0x4
-	.byte	0x0
-	.2byte	0x0
-	.2byte	0x0
-	.4byte	.Lbegin_text1
-	.4byte	.Lbegin_text1-.Lend_text1
-	.4byte	0x0
-	.4byte	0x0
+	.4byte	.Lar_end - .Lar_start		/* Length of aranges.  */
+.Lar_start:
+	.2byte	0x2				/* Dwarf version.  */
+	.4byte	.Lcu1_begin			/* Offset to debug_info.  */
+	.byte	0x8				/* Address size */
+	.byte	0x0				/* Segment size.  */
+	.balign 8
+	.8byte	.Lbegin_text1
+	.8byte	.Lbegin_text1-.Lend_text1
+	.8byte	0x0
+	.8byte	0x0
+.Lar_end:
Index: ld/testsuite/ld-elf/compress1a.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/compress1a.d,v
retrieving revision 1.2
diff -u -p -r1.2 compress1a.d
--- ld/testsuite/ld-elf/compress1a.d	2 Nov 2010 13:47:44 -0000	1.2
+++ ld/testsuite/ld-elf/compress1a.d	29 Mar 2011 21:19:59 -0000
@@ -2,7 +2,6 @@
 #as: --compress-debug-sections
 #ld: -e func_cu2
 #readelf: -S --wide
-#notarget: alpha-*
 
 #failif
 #...
Index: ld/testsuite/ld-elf/group8a.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/group8a.d,v
retrieving revision 1.4
diff -u -p -r1.4 group8a.d
--- ld/testsuite/ld-elf/group8a.d	18 Sep 2010 02:30:41 -0000	1.4
+++ ld/testsuite/ld-elf/group8a.d	29 Mar 2011 21:20:00 -0000
@@ -2,7 +2,7 @@
 #ld: -r --gc-sections --entry foo
 #readelf: -g --wide
 #notarget: arc-*-* d30v-*-* dlx-*-* i960-*-* or32-*-* pj*-*-*
-#notarget: alpha-*-* hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
+#notarget: hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
 #xfail: cr16-*-* crx-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 # cr16 and crx use non-standard scripts with memory regions, which don't play
Index: ld/testsuite/ld-elf/group8b.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/group8b.d,v
retrieving revision 1.4
diff -u -p -r1.4 group8b.d
--- ld/testsuite/ld-elf/group8b.d	18 Sep 2010 02:30:41 -0000	1.4
+++ ld/testsuite/ld-elf/group8b.d	29 Mar 2011 21:20:00 -0000
@@ -2,7 +2,7 @@
 #ld: -r --gc-sections --entry bar
 #readelf: -g --wide
 #notarget: arc-*-* d30v-*-* dlx-*-* i960-*-* or32-*-* pj*-*-*
-#notarget: alpha-*-* hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
+#notarget: hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
 #xfail: cr16-*-* crx-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 # cr16 and crx use non-standard scripts with memory regions, which don't play
Index: ld/testsuite/ld-gc/start.s
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-gc/start.s,v
retrieving revision 1.1
diff -u -p -r1.1 start.s
--- ld/testsuite/ld-gc/start.s	8 Jan 2010 01:43:23 -0000	1.1
+++ ld/testsuite/ld-gc/start.s	29 Mar 2011 21:20:00 -0000
@@ -1,6 +1,6 @@
 .globl _start
 _start:
-	.long __start__foo
+	.quad	__start__foo
 	.section	_foo,"aw",%progbits
 foo:
 	.long	1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [rfc] fixup ld testsuite for alpha enable --gc-sections
  2011-03-29 21:35 ` [rfc] fixup ld testsuite for alpha " Richard Henderson
@ 2011-03-30  5:16   ` Alan Modra
  2011-03-30 17:43     ` Richard Henderson
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2011-03-30  5:16 UTC (permalink / raw)
  To: Richard Henderson; +Cc: binutils

On Tue, Mar 29, 2011 at 02:35:02PM -0700, Richard Henderson wrote:
> This adjusts the two relevant test cases for 64-bit targets.
> Which... probably causes just as many problems for some 32-bit
> targets.

No probably about it. :)

> So.  What's the best way forward here?

> --- ld/testsuite/ld-gc/start.s	8 Jan 2010 01:43:23 -0000	1.1
> +++ ld/testsuite/ld-gc/start.s	29 Mar 2011 21:20:00 -0000
> @@ -1,6 +1,6 @@
>  .globl _start
>  _start:
> -	.long __start__foo
> +	.quad	__start__foo

.dc.a here maybe, and leave the compress test as notarget for alpha.
If you really want a compress test, put a modified version in
testsuite/ld-alpha/.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [rfc] fixup ld testsuite for alpha enable --gc-sections
  2011-03-30  5:16   ` Alan Modra
@ 2011-03-30 17:43     ` Richard Henderson
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2011-03-30 17:43 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 302 bytes --]

I hacked a 32-bit start address into elf.exp for alpha, and used your
suggestion for .dc.a in start.s.

Committed.


r~


	* ld-elf/elf.exp: Force 32-bit start address for alpha.
	* ld-elf/group8a.d: Don't disable for alpha.
	* ld-elf/group8b.d: Likewise.
	* ld-gc/start.s: Use .dc.a instead of .long.

[-- Attachment #2: z --]
[-- Type: text/plain, Size: 2916 bytes --]

? bfd/doc/bfd.info
? gold/po/es.gmo
? gold/po/id.gmo
Index: ld/testsuite/ld-elf/elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/elf.exp,v
retrieving revision 1.19
diff -u -p -r1.19 elf.exp
--- ld/testsuite/ld-elf/elf.exp	21 Dec 2010 11:00:48 -0000	1.19
+++ ld/testsuite/ld-elf/elf.exp	30 Mar 2011 17:39:14 -0000
@@ -29,6 +29,12 @@ set old_ldflags $LDFLAGS
 if { [istarget spu*-*-*] } {
     set LDFLAGS "$LDFLAGS --local-store 0:0"
 }
+if { [istarget alpha*-*-* ] } {
+    # The compress1 test is written expecting 32-bit addresses; force the
+    # executable down into the low address space to match.
+    # ??? How can we adjust just the one testcase?
+    set LDFLAGS "$LDFLAGS -Ttext-segment 0x1000000"
+}
 
 if { [is_remote host] } then {
     remote_download host merge.ld
Index: ld/testsuite/ld-elf/group8a.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/group8a.d,v
retrieving revision 1.4
diff -u -p -r1.4 group8a.d
--- ld/testsuite/ld-elf/group8a.d	18 Sep 2010 02:30:41 -0000	1.4
+++ ld/testsuite/ld-elf/group8a.d	30 Mar 2011 17:39:14 -0000
@@ -2,7 +2,7 @@
 #ld: -r --gc-sections --entry foo
 #readelf: -g --wide
 #notarget: arc-*-* d30v-*-* dlx-*-* i960-*-* or32-*-* pj*-*-*
-#notarget: alpha-*-* hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
+#notarget: hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
 #xfail: cr16-*-* crx-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 # cr16 and crx use non-standard scripts with memory regions, which don't play
Index: ld/testsuite/ld-elf/group8b.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/group8b.d,v
retrieving revision 1.4
diff -u -p -r1.4 group8b.d
--- ld/testsuite/ld-elf/group8b.d	18 Sep 2010 02:30:41 -0000	1.4
+++ ld/testsuite/ld-elf/group8b.d	30 Mar 2011 17:39:14 -0000
@@ -2,7 +2,7 @@
 #ld: -r --gc-sections --entry bar
 #readelf: -g --wide
 #notarget: arc-*-* d30v-*-* dlx-*-* i960-*-* or32-*-* pj*-*-*
-#notarget: alpha-*-* hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
+#notarget: hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
 #xfail: cr16-*-* crx-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 # cr16 and crx use non-standard scripts with memory regions, which don't play
Index: ld/testsuite/ld-gc/start.s
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-gc/start.s,v
retrieving revision 1.1
diff -u -p -r1.1 start.s
--- ld/testsuite/ld-gc/start.s	8 Jan 2010 01:43:23 -0000	1.1
+++ ld/testsuite/ld-gc/start.s	30 Mar 2011 17:39:14 -0000
@@ -1,6 +1,6 @@
 .globl _start
 _start:
-	.long __start__foo
+	.dc.a	__start__foo
 	.section	_foo,"aw",%progbits
 foo:
 	.long	1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-30 17:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-29 21:19 [alpha] enable --gc-sections Richard Henderson
2011-03-29 21:35 ` [rfc] fixup ld testsuite for alpha " Richard Henderson
2011-03-30  5:16   ` Alan Modra
2011-03-30 17:43     ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).