public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: binutils@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>,
	Alan Modra <amodra@gmail.com>, Nick Clifton <nickc@redhat.com>,
	Richard Earnshaw <rearnsha@arm.com>
Subject: [PATCH v3 1/2] elf: Add GNU_PROPERTY_1_NEEDED
Date: Thu, 24 Jun 2021 06:24:10 -0700	[thread overview]
Message-ID: <20210624132411.1993105-2-hjl.tools@gmail.com> (raw)
In-Reply-To: <20210624132411.1993105-1-hjl.tools@gmail.com>

Add GNU_PROPERTY_1_NEEDED:

 #define GNU_PROPERTY_1_NEEDED      GNU_PROPERTY_UINT32_OR_LO

to indicate the needed properties by the object file.

Add GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS:

 #define GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS  (1U << 0)

to indicate that the object file requires canonical function pointers and
cannot be used with copy relocation.

binutils/

	* readelf.c (decode_1_needed): New.
	(print_gnu_property_note): Handle GNU_PROPERTY_1_NEEDED.

include/

	* elf/common.h (GNU_PROPERTY_1_NEEDED): New.
	(GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS): Likewise.

ld/

	* testsuite/ld-elf/property-1_needed-1a.d: New file.
	* testsuite/ld-elf/property-1_needed-1.s: Likewise.
---
 binutils/readelf.c                         | 39 ++++++++++++++++++++++
 include/elf/common.h                       |  7 ++++
 ld/testsuite/ld-elf/property-1_needed-1.s  | 15 +++++++++
 ld/testsuite/ld-elf/property-1_needed-1a.d | 17 ++++++++++
 4 files changed, 78 insertions(+)
 create mode 100644 ld/testsuite/ld-elf/property-1_needed-1.s
 create mode 100644 ld/testsuite/ld-elf/property-1_needed-1a.d

diff --git a/binutils/readelf.c b/binutils/readelf.c
index f7c64329f37..0c564a75248 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -19319,6 +19319,28 @@ decode_aarch64_feature_1_and (unsigned int bitmask)
     }
 }
 
+static void
+decode_1_needed (unsigned int bitmask)
+{
+  while (bitmask)
+    {
+      unsigned int bit = bitmask & (- bitmask);
+
+      bitmask &= ~ bit;
+      switch (bit)
+	{
+	case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS:
+	  printf ("indirect external access");
+	  break;
+	default:
+	  printf (_("<unknown: %x>"), bit);
+	  break;
+	}
+      if (bitmask)
+	printf (", ");
+    }
+}
+
 static void
 print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
 {
@@ -19512,6 +19534,23 @@ print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
 		  || (type >= GNU_PROPERTY_UINT32_OR_LO
 		      && type <= GNU_PROPERTY_UINT32_OR_HI))
 		{
+		  switch (type)
+		    {
+		    case GNU_PROPERTY_1_NEEDED:
+		      if (datasz != 4)
+			printf (_("1_needed: <corrupt length: %#x> "),
+				datasz);
+		      else
+			{
+			  unsigned int bitmask = byte_get (ptr, 4);
+			  printf ("1_needed: ");
+			  decode_1_needed (bitmask);
+			}
+		      goto next;
+
+		    default:
+		      break;
+		    }
 		  if (type <= GNU_PROPERTY_UINT32_AND_HI)
 		    printf (_("UINT32_AND (%#x): "), type);
 		  else
diff --git a/include/elf/common.h b/include/elf/common.h
index 0cca28673dd..0d381f0d27b 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -792,6 +792,13 @@
 #define GNU_PROPERTY_UINT32_OR_LO	0xb0008000
 #define GNU_PROPERTY_UINT32_OR_HI	0xb000ffff
 
+/* The needed properties by the object file.  */
+#define GNU_PROPERTY_1_NEEDED		GNU_PROPERTY_UINT32_OR_LO
+
+/* Set if the object file requires canonical function pointers and
+   cannot be used with copy relocation.  */
+#define GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS	(1U << 0)
+
 /* Processor-specific semantics, lo */
 #define GNU_PROPERTY_LOPROC  0xc0000000
 /* Processor-specific semantics, hi */
diff --git a/ld/testsuite/ld-elf/property-1_needed-1.s b/ld/testsuite/ld-elf/property-1_needed-1.s
new file mode 100644
index 00000000000..5d5cdc87744
--- /dev/null
+++ b/ld/testsuite/ld-elf/property-1_needed-1.s
@@ -0,0 +1,15 @@
+	.section ".note.gnu.property", "a"
+	.p2align ALIGN
+	.long 1f - 0f		/* name length */
+	.long 5f - 2f		/* data length */
+	.long 5			/* note type */
+0:	.asciz "GNU"		/* vendor name */
+1:
+	.p2align ALIGN
+2:	.long 0xb0008000	/* pr_type.  */
+	.long 4f - 3f		/* pr_datasz.  */
+3:
+	.long 0x3
+4:
+	.p2align ALIGN
+5:
diff --git a/ld/testsuite/ld-elf/property-1_needed-1a.d b/ld/testsuite/ld-elf/property-1_needed-1a.d
new file mode 100644
index 00000000000..d994e6edece
--- /dev/null
+++ b/ld/testsuite/ld-elf/property-1_needed-1a.d
@@ -0,0 +1,17 @@
+#source: empty.s
+#source: property-1_needed-1.s
+#as:
+#ld: -shared
+#readelf: -n
+#xfail: ![check_shared_lib_support]
+#notarget: am33_2.0-*-* hppa*-*-hpux* mn10300-*-*
+# Assembly source file for the HPPA assembler is renamed and modifed by
+# sed.  mn10300 has relocations in .note.gnu.property section which
+# elf_parse_notes doesn't support.
+
+#...
+Displaying notes found in: .note.gnu.property
+[ 	]+Owner[ 	]+Data size[ 	]+Description
+  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
+      Properties: 1_needed: indirect external access, <unknown: 2>
+#pass
-- 
2.31.1


  reply	other threads:[~2021-06-24 13:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-24 13:24 [PATCH v3 0/2] elf: Implement indirect external access marker H.J. Lu
2021-06-24 13:24 ` H.J. Lu [this message]
2021-06-24 13:24 ` [PATCH v3 2/2] elf: Add GNU_PROPERTY_1_NEEDED check H.J. Lu
2021-06-25 14:10   ` Florian Weimer
2021-06-25 18:52     ` H.J. Lu
2021-06-28  8:46       ` Florian Weimer
2021-06-28 11:55         ` H.J. Lu
2021-07-08  7:27           ` Florian Weimer
2021-07-08 12:26             ` H.J. Lu

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=20210624132411.1993105-2-hjl.tools@gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=fweimer@redhat.com \
    --cc=nickc@redhat.com \
    --cc=rearnsha@arm.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).