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 5/6] mach-o: Handle LC_NOTE


This is a new command to describe a region of any data. Initially, it's
used in in MH_CORE files.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Signed-off-by: Saagar Jha <saagar@saagarjha.com>
Cc: Tristan Gingold <tgingold@free.fr>
---
 bfd/ChangeLog             |  4 +++-
 bfd/mach-o.c              | 19 +++++++++++++++++++
 bfd/mach-o.h              |  9 +++++++++
 binutils/ChangeLog        |  2 +-
 binutils/od-macho.c       | 13 +++++++++++++
 include/ChangeLog         |  4 +++-
 include/mach-o/external.h |  7 +++++++
 include/mach-o/loader.h   |  3 ++-
 8 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index b1df3af4ba..1f017f6fcd 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -3,9 +3,11 @@
 
 	* mach-o.h (bfd_mach_o_version_min_command): Don't split version into
 	a few fields. Rename reserved to sdk.
+	(struct bfd_mach_o_note_command): New.
 	* mach-o.c (bfd_mach_o_read_version_min): Don't split version into a
 	few fields. Rename reserved to sdk.
-	(bfd_mach_o_read_command): Handle LC_VERSION_MIN_TVOS.
+	(bfd_mach_o_read_command): Handle LC_VERSION_MIN_TVOS, LC_NOTE.
+	(bfd_mach_o_read_note): New.
 
 2018-11-02  Alan Modra  <amodra@gmail.com>
 
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index 57ca8fb169..c5d6277c54 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -4677,6 +4677,21 @@ bfd_mach_o_read_source_version (bfd *abfd, bfd_mach_o_load_command *command)
   return TRUE;
 }
 
+static bfd_boolean
+bfd_mach_o_read_note (bfd *abfd, bfd_mach_o_load_command *command)
+{
+  bfd_mach_o_note_command *cmd = &command->command.note;
+  struct mach_o_note_command_external raw;
+
+  if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+    return FALSE;
+
+  memcpy (cmd->data_owner, raw.data_owner, 16);
+  cmd->offset = bfd_get_64 (abfd, raw.offset);
+  cmd->size = bfd_get_64 (abfd, raw.size);
+  return TRUE;
+}
+
 static bfd_boolean
 bfd_mach_o_read_segment (bfd *abfd,
 			 bfd_mach_o_load_command *command,
@@ -4885,6 +4900,10 @@ bfd_mach_o_read_command (bfd *abfd, bfd_mach_o_load_command *command)
       if (!bfd_mach_o_read_source_version (abfd, command))
 	return FALSE;
       break;
+    case BFD_MACH_O_LC_NOTE:
+      if (!bfd_mach_o_read_note (abfd, command))
+        return FALSE;
+      break;
     default:
       command->len = 0;
       _bfd_error_handler (_("%pB: unknown load command %#x"),
diff --git a/bfd/mach-o.h b/bfd/mach-o.h
index 28ccb09c69..805c30e4e2 100644
--- a/bfd/mach-o.h
+++ b/bfd/mach-o.h
@@ -549,6 +549,14 @@ typedef struct bfd_mach_o_source_version_command
 }
 bfd_mach_o_source_version_command;
 
+typedef struct bfd_mach_o_note_command
+{
+  char data_owner[16];
+  bfd_uint64_t offset;
+  bfd_uint64_t size;
+}
+bfd_mach_o_note_command;
+
 typedef struct bfd_mach_o_load_command
 {
   /* Next command in the single linked list.  */
@@ -582,6 +590,7 @@ typedef struct bfd_mach_o_load_command
     bfd_mach_o_fvmlib_command fvmlib;
     bfd_mach_o_main_command main;
     bfd_mach_o_source_version_command source_version;
+    bfd_mach_o_note_command note;
   } command;
 }
 bfd_mach_o_load_command;
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 3db9bcdad8..266ce272d9 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -3,7 +3,7 @@
 
 	* od-macho.c (printf_version): New.
 	(dump_load_command): Use it to print version. Print sdk version. Print
-	version info for watchOS and tvOS.
+	version info for watchOS and tvOS. Print LC_NOTE.
 
 2018-11-03  H.J. Lu  <hongjiu.lu@intel.com>
 
diff --git a/binutils/od-macho.c b/binutils/od-macho.c
index 43a89bd68d..4f9bba1d55 100644
--- a/binutils/od-macho.c
+++ b/binutils/od-macho.c
@@ -211,6 +211,7 @@ static const bfd_mach_o_xlat_name bfd_mach_o_load_command_name[] =
   { "linker_optimization_hint", BFD_MACH_O_LC_LINKER_OPTIMIZATION_HINT},
   { "version_min_tvos", BFD_MACH_O_LC_VERSION_MIN_TVOS},
   { "version_min_watchos", BFD_MACH_O_LC_VERSION_MIN_WATCHOS},
+  { "note", BFD_MACH_O_LC_NOTE},
   { NULL, 0}
 };
 
@@ -1660,6 +1661,18 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
 	printf ("\n");
         break;
       }
+    case BFD_MACH_O_LC_NOTE:
+      {
+        bfd_mach_o_note_command *note = &cmd->command.note;
+        printf ("   data owner: %.16s\n", note->data_owner);
+        printf ("   offset:     ");
+	printf_uint64 (note->offset);
+        printf ("\n"
+                "   size:       ");
+	printf_uint64 (note->size);
+	printf ("\n");
+        break;
+      }
     default:
       break;
     }
diff --git a/include/ChangeLog b/include/ChangeLog
index 25a5826664..f86bbbf08c 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,9 +1,11 @@
 2018-11-06  Roman Bolshakov <r.bolshakov@yadro.com>
 	    Saagar Jha  <saagar@saagarjha.com>
 
-	* mach-o/external.h (mach_o_version_min_command_external): Rename
+	* mach-o/external.h (mach_o_nversion_min_command_external): Rename
 	reserved to sdk.
+	(mach_o_note_command_external): New
 	* mach-o/loader.h (BFD_MACH_O_LC_VERSION_MIN_TVOS): Define
+	(BFD_MACH_O_LC_NOTE): Define
 
 2018-11-06  Sudakshina Das  <sudi.das@arm.com>
 
diff --git a/include/mach-o/external.h b/include/mach-o/external.h
index aa7260a58a..7889b57794 100644
--- a/include/mach-o/external.h
+++ b/include/mach-o/external.h
@@ -345,6 +345,13 @@ struct mach_o_source_version_command_external
 				   and 24 bits for A.  */
 };
 
+struct mach_o_note_command_external
+{
+  unsigned char data_owner[16]; /* Owner name for this note. */
+  unsigned char offset[8];      /* File offset of the note. */
+  unsigned char size[8];        /* Length of the note. */
+};
+
 /* The LD_DATA_IN_CODE command use a linkedit_data_command that points to
    a table of entries.  */
 
diff --git a/include/mach-o/loader.h b/include/mach-o/loader.h
index 19c5e91d64..a3d20e04dc 100644
--- a/include/mach-o/loader.h
+++ b/include/mach-o/loader.h
@@ -186,7 +186,8 @@ typedef enum bfd_mach_o_load_command_type
   BFD_MACH_O_LC_LINKER_OPTIONS = 0x2d,	/* Linker options.  */
   BFD_MACH_O_LC_LINKER_OPTIMIZATION_HINT = 0x2e, /* Optimization hints.  */
   BFD_MACH_O_LC_VERSION_MIN_TVOS = 0x2f, /* Minimal tvOS version.  */
-  BFD_MACH_O_LC_VERSION_MIN_WATCHOS = 0x30 /* Minimal WatchOS version.  */
+  BFD_MACH_O_LC_VERSION_MIN_WATCHOS = 0x30, /* Minimal watchOS version.  */
+  BFD_MACH_O_LC_NOTE = 0x31, /* Region of arbitrary data. */
 }
 bfd_mach_o_load_command_type;
 
-- 
2.19.1


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