public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hongjiu.lu@intel.com>
To: binutils@sourceware.org
Subject: PATCH: PR ld/14156: -sort-section=alignment trashes init/fini sections, and anything similar
Date: Wed, 27 Jun 2012 17:32:00 -0000	[thread overview]
Message-ID: <20120627173011.GA10021@intel.com> (raw)

Hi,

We shouldn't sort .init/.fini sections since they are concatenated into
one function.  OK to install?

Thanks.


H.J.
---
ld/

	PR ld/14156
	* ldlang.c (update_wild_statements): Don't sort .init/.fini
	sections.

ld/testsuite/

	PR ld/14156
	* ld-elf/fini0.s: New file.
	* ld-elf/fini1.s: Likewise.
	* ld-elf/fini2.s: Likewise.
	* ld-elf/fini3.s: Likewise.
	* ld-elf/finin.s: Likewise.
	* ld-elf/init0.s: Likewise.
	* ld-elf/init1.s: Likewise.
	* ld-elf/init2.s: Likewise.
	* ld-elf/init3.s: Likewise.
	* ld-elf/initn.s: Likewise.
	* ld-elf/pr14156a.d: Likewise.
	* ld-elf/pr14156b.d: Likewise.

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 7dd2fa4..a5e91db 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -3495,8 +3495,12 @@ update_wild_statements (lang_statement_union_type *s)
 
 	    case lang_wild_statement_enum:
 	      sec = s->wild_statement.section_list;
-	      for (sec = s->wild_statement.section_list; sec != NULL;
-		   sec = sec->next)
+	      /* Don't sort .init/.fini sections.  */
+	      if (sec == NULL
+		  || strcmp (sec->spec.name, ".init") == 0
+		  || strcmp (sec->spec.name, ".fini") == 0)
+		break;
+	      for (; sec != NULL; sec = sec->next)
 		{
 		  switch (sec->spec.sorted)
 		    {
diff --git a/ld/testsuite/ld-elf/fini0.s b/ld/testsuite/ld-elf/fini0.s
new file mode 100644
index 0000000..f2ccfb7
--- /dev/null
+++ b/ld/testsuite/ld-elf/fini0.s
@@ -0,0 +1,16 @@
+	.text
+	.global start	/* Used by SH targets.  */
+start:
+	.global _start
+_start:
+	.global __start
+__start:
+	.global main	/* Used by HPPA targets.  */
+main:
+	.dc.a 0
+
+	.section .fini
+	.p2align 2
+.globl foo
+	.type	foo,%function
+foo:
diff --git a/ld/testsuite/ld-elf/fini1.s b/ld/testsuite/ld-elf/fini1.s
new file mode 100644
index 0000000..b65d18d
--- /dev/null
+++ b/ld/testsuite/ld-elf/fini1.s
@@ -0,0 +1,6 @@
+	.section .fini
+	.p2align 2
+	.type	foo1,%function
+foo1:
+	.dc.a	0x0
+	.size	foo1,.-foo1
diff --git a/ld/testsuite/ld-elf/fini2.s b/ld/testsuite/ld-elf/fini2.s
new file mode 100644
index 0000000..b8d7457
--- /dev/null
+++ b/ld/testsuite/ld-elf/fini2.s
@@ -0,0 +1,6 @@
+	.section .fini
+	.p2align 6
+	.type	foo2,%function
+foo2:
+	.dc.a	0x0
+	.size	foo2,.-foo2
diff --git a/ld/testsuite/ld-elf/fini3.s b/ld/testsuite/ld-elf/fini3.s
new file mode 100644
index 0000000..7f797c5
--- /dev/null
+++ b/ld/testsuite/ld-elf/fini3.s
@@ -0,0 +1,6 @@
+	.section .fini
+	.p2align 4
+	.type	foo3,%function
+foo3:
+	.dc.a	0x0
+	.size	foo3,.-foo3
diff --git a/ld/testsuite/ld-elf/finin.s b/ld/testsuite/ld-elf/finin.s
new file mode 100644
index 0000000..9085080
--- /dev/null
+++ b/ld/testsuite/ld-elf/finin.s
@@ -0,0 +1,6 @@
+	.section .fini
+	.p2align 8
+	.type	last,%function
+last:
+	.dc.a	0x0
+	.size	last,.-last
diff --git a/ld/testsuite/ld-elf/init0.s b/ld/testsuite/ld-elf/init0.s
new file mode 100644
index 0000000..3c8cf8c
--- /dev/null
+++ b/ld/testsuite/ld-elf/init0.s
@@ -0,0 +1,16 @@
+	.text
+	.global start	/* Used by SH targets.  */
+start:
+	.global _start
+_start:
+	.global __start
+__start:
+	.global main	/* Used by HPPA targets.  */
+main:
+	.dc.a 0
+
+	.section .init
+	.p2align 2
+.globl foo
+	.type	foo,%function
+foo:
diff --git a/ld/testsuite/ld-elf/init1.s b/ld/testsuite/ld-elf/init1.s
new file mode 100644
index 0000000..5d24ec2
--- /dev/null
+++ b/ld/testsuite/ld-elf/init1.s
@@ -0,0 +1,6 @@
+	.section .init
+	.p2align 2
+	.type	foo1,%function
+foo1:
+	.dc.a	0x0
+	.size	foo1,.-foo1
diff --git a/ld/testsuite/ld-elf/init2.s b/ld/testsuite/ld-elf/init2.s
new file mode 100644
index 0000000..2c5c353
--- /dev/null
+++ b/ld/testsuite/ld-elf/init2.s
@@ -0,0 +1,6 @@
+	.section .init
+	.p2align 6
+	.type	foo2,%function
+foo2:
+	.dc.a	0x0
+	.size	foo2,.-foo2
diff --git a/ld/testsuite/ld-elf/init3.s b/ld/testsuite/ld-elf/init3.s
new file mode 100644
index 0000000..d6639ce
--- /dev/null
+++ b/ld/testsuite/ld-elf/init3.s
@@ -0,0 +1,6 @@
+	.section .init
+	.p2align 4
+	.type	foo3,%function
+foo3:
+	.dc.a	0x0
+	.size	foo3,.-foo3
diff --git a/ld/testsuite/ld-elf/initn.s b/ld/testsuite/ld-elf/initn.s
new file mode 100644
index 0000000..8931e52
--- /dev/null
+++ b/ld/testsuite/ld-elf/initn.s
@@ -0,0 +1,6 @@
+	.section .init
+	.p2align 8
+	.type	last,%function
+last:
+	.dc.a	0x0
+	.size	last,.-last
diff --git a/ld/testsuite/ld-elf/pr14156a.d b/ld/testsuite/ld-elf/pr14156a.d
new file mode 100644
index 0000000..6476857
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr14156a.d
@@ -0,0 +1,15 @@
+#source: init0.s
+#source: init1.s
+#source: init2.s
+#source: init3.s
+#source: initn.s
+#ld: --sort-section=alignment
+#nm: -n
+
+#...
+[0-9a-f]+ T foo
+[0-9a-f]+ t foo1
+[0-9a-f]+ t foo2
+[0-9a-f]+ t foo3
+[0-9a-f]+ t last
+#pass
diff --git a/ld/testsuite/ld-elf/pr14156b.d b/ld/testsuite/ld-elf/pr14156b.d
new file mode 100644
index 0000000..ae9fa05
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr14156b.d
@@ -0,0 +1,15 @@
+#source: fini0.s
+#source: fini1.s
+#source: fini2.s
+#source: fini3.s
+#source: finin.s
+#ld: --sort-section=alignment
+#nm: -n
+
+#...
+[0-9a-f]+ T foo
+[0-9a-f]+ t foo1
+[0-9a-f]+ t foo2
+[0-9a-f]+ t foo3
+[0-9a-f]+ t last
+#pass

             reply	other threads:[~2012-06-27 17:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-27 17:32 H.J. Lu [this message]
2012-06-28  1:26 ` Alan Modra
2012-06-28  2:13   ` H.J. Lu
2012-06-28  6:47     ` Alan Modra
2012-06-28 13:57       ` H.J. Lu
2012-07-05 15:49         ` H.J. Lu
2012-07-10  5:12           ` H.J. Lu
2012-07-10  6:13             ` Alan Modra
2012-07-10  6:24               ` H.J. Lu
2012-07-10  6:30                 ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120627173011.GA10021@intel.com \
    --to=hongjiu.lu@intel.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).