This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH v2 1/6] mach-o: Don't split version into a few fields
- From: Roman Bolshakov <r dot bolshakov at yadro dot com>
- To: <binutils at sourceware dot org>
- Cc: Roman Bolshakov <r dot bolshakov at yadro dot com>, Tristan Gingold <tgingold at free dot fr>
- Date: Wed, 7 Nov 2018 00:12:50 +0300
- Subject: [PATCH v2 1/6] mach-o: Don't split version into a few fields
- References: <20181106211254.57004-1-r.bolshakov@yadro.com>
X.Y.Z tuple is used for minos version and sdk version fields in a number of
load commands:
LC_VERSION_MIN_MACOSX
LC_VERSION_MIN_IOS
LC_VERSION_MIN_WATCHOS
LC_VERSION_MIN_TVOS
LC_BUILD_VERSION
We could use a macro to avoid code duplication for reading and setting
the X/Y/Z fields in all the load commands. But since there're no users
of the fields except od, we can just add a function that properly prints
all version components out of 4-byte unsigned integer and remove the
version subfields until they're really needed.
This also fixes incorrect length of the first version subfield as it
should be two bytes long instead of one:
X.Y.Z is encoded in nibbles xxxx.yy.zz
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: Tristan Gingold <tgingold@free.fr>
---
bfd/ChangeLog | 7 +++++++
bfd/mach-o.c | 6 +-----
bfd/mach-o.h | 6 ++----
binutils/ChangeLog | 5 +++++
binutils/od-macho.c | 14 +++++++++++++-
5 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 155251d3d4..d90e4576f1 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2018-11-06 Roman Bolshakov <r.bolshakov@yadro.com>
+
+ * mach-o.h (bfd_mach_o_version_min_command): Don't split version into
+ a few fields.
+ * mach-o.c (bfd_mach_o_read_version_min): Don't split version into a
+ few fields.
+
2018-11-06 Romain Margheriti <lilrom13@gmail.com>
PR 23742
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index 1d0ade3a02..e3d5dbe0d5 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -4598,15 +4598,11 @@ bfd_mach_o_read_version_min (bfd *abfd, bfd_mach_o_load_command *command)
{
bfd_mach_o_version_min_command *cmd = &command->command.version_min;
struct mach_o_version_min_command_external raw;
- unsigned int ver;
if (bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
return FALSE;
- ver = bfd_get_32 (abfd, raw.version);
- cmd->rel = ver >> 16;
- cmd->maj = ver >> 8;
- cmd->min = ver;
+ cmd->version = bfd_get_32 (abfd, raw.version);
cmd->reserved = bfd_get_32 (abfd, raw.reserved);
return TRUE;
}
diff --git a/bfd/mach-o.h b/bfd/mach-o.h
index d80d43991e..4fd229f352 100644
--- a/bfd/mach-o.h
+++ b/bfd/mach-o.h
@@ -519,10 +519,8 @@ bfd_mach_o_dyld_info_command;
typedef struct bfd_mach_o_version_min_command
{
- unsigned char rel;
- unsigned char maj;
- unsigned char min;
- unsigned int reserved;
+ uint32_t version;
+ uint32_t reserved;
}
bfd_mach_o_version_min_command;
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index f484f92294..089d7a61b6 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-06 Roman Bolshakov <r.bolshakov@yadro.com>
+
+ * od-macho.c (printf_version): New.
+ (dump_load_command): Use it to print version.
+
2018-11-06 H.J. Lu <hongjiu.lu@intel.com>
* doc/binutils.texi: Document --enable-x86-feature and
diff --git a/binutils/od-macho.c b/binutils/od-macho.c
index 8153adae92..9b10f2d654 100644
--- a/binutils/od-macho.c
+++ b/binutils/od-macho.c
@@ -1438,6 +1438,16 @@ dump_twolevel_hints (bfd *abfd, bfd_mach_o_twolevel_hints_command *cmd)
free (buf);
}
+static void
+printf_version (uint32_t version)
+{
+ uint32_t maj, min, upd;
+ maj = (version >> 16) & 0xffff;
+ min = (version >> 8) & 0xff;
+ upd = version & 0xff;
+ printf ("%u.%u.%u", maj, min, upd);
+}
+
static void
dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
unsigned int idx, bfd_boolean verbose)
@@ -1585,7 +1595,9 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
{
bfd_mach_o_version_min_command *ver = &cmd->command.version_min;
- printf (" %u.%u.%u\n", ver->rel, ver->maj, ver->min);
+ printf (" os: ");
+ printf_version (ver->version);
+ printf ("\n");
}
break;
case BFD_MACH_O_LC_SOURCE_VERSION:
--
2.19.1