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]

[PATCH] ld: Check if GNU property note section exists


GNU property must be placed in .note.gnu.property section.  It is
an error if GNU property is placed in other note sections.

Any comments?

H.J.
----
bfd/

	PR ld/22450
	* elf-properties.c (_bfd_elf_link_setup_gnu_properties):  Call
	linker callback if GNU property note section doesn't exist.

ld/

	PR ld/22450
	* testsuite/ld-elf/elf.exp: Run PR ld/22450 test.
	* testsuite/ld-elf/pr22450.S: New file.
	* testsuite/ld-elf/pr22450.err: Likewise.
---
 bfd/elf-properties.c            |  4 ++++
 ld/testsuite/ld-elf/elf.exp     | 11 +++++++++++
 ld/testsuite/ld-elf/pr22450.S   | 23 +++++++++++++++++++++++
 ld/testsuite/ld-elf/pr22450.err |  2 ++
 4 files changed, 40 insertions(+)
 create mode 100644 ld/testsuite/ld-elf/pr22450.S
 create mode 100644 ld/testsuite/ld-elf/pr22450.err

diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c
index bfb106edc9..7d58f0cc14 100644
--- a/bfd/elf-properties.c
+++ b/bfd/elf-properties.c
@@ -394,6 +394,10 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
       sec = bfd_get_section_by_name (first_pbfd,
 				     NOTE_GNU_PROPERTY_SECTION_NAME);
 
+      if (sec == NULL)
+	info->callbacks->einfo (_("%P%F: failed to find GNU property section: %s\n"),
+				  NOTE_GNU_PROPERTY_SECTION_NAME);
+
       /* Update stack size in .note.gnu.property with -z stack-size=N
 	 if N > 0.  */
       if (info->stacksize > 0)
diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp
index acdad8db22..4ec7a3e151 100644
--- a/ld/testsuite/ld-elf/elf.exp
+++ b/ld/testsuite/ld-elf/elf.exp
@@ -352,6 +352,17 @@ if { [istarget *-*-linux*]
     ]
 }
 
+run_cc_link_tests [list \
+    [list \
+	"PR ld/22450" \
+	"-Wl,-r -nostdlib -nostartfiles" \
+	"" \
+	{ pr22450.S } \
+	{{error_output "pr22450.err"}} \
+	"pr22450" \
+    ] \
+]
+
 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
 switch -regexp $target_triplet {
diff --git a/ld/testsuite/ld-elf/pr22450.S b/ld/testsuite/ld-elf/pr22450.S
new file mode 100644
index 0000000000..b2593f25f0
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22450.S
@@ -0,0 +1,23 @@
+#ifdef __LP64__
+# define ALIGN 3
+#else
+# define ALIGN 2
+#endif
+	.section ".note.gnu", "a"
+	.p2align ALIGN
+	.long 1f - 0f		/* name length.  */
+	.long 3f - 1f		/* data length.  */
+	/* NT_GNU_PROPERTY_TYPE_0 */
+	.long 5			/* note type.  */
+0:
+	.asciz "GNU"		/* vendor name.  */
+1:
+	.p2align ALIGN
+	/* GNU_PROPERTY_STACK_SIZE */
+	.long 1			/* pr_type.  */
+	.long 5f - 4f		/* pr_datasz.  */
+4:
+	.dc.a 0x800000		/* Stack size.  */
+5:
+	.p2align ALIGN
+3:
diff --git a/ld/testsuite/ld-elf/pr22450.err b/ld/testsuite/ld-elf/pr22450.err
new file mode 100644
index 0000000000..387e1a3853
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22450.err
@@ -0,0 +1,2 @@
+.*: failed to find GNU property section: .note.gnu.property
+#...
-- 
2.14.3


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