Skip to content

First Binutils hack: missing initializer & excess elements #322

@Ahmed101Mohammed

Description

@Ahmed101Mohammed

In the First Binutils hack task, I need to write the following code in the path: submodules/binutils-gdb/opcodes/i386-tbl.h

  { "myinc", 1, 0xfe, 0x0, 1,
    { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
    { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0 },
    { { { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	  0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
	  1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },

Then I should rebuild the binutils with this command:

./build-buildroot -- host-binutils-rebuild

But I get in the logs the following warnings that later will affect the rest of the task:

make[5]: Entering directory '/root/lkmc/out.docker/buildroot/build/default/x86_64/build/host-binutils-custom/opcodes'
  CC       i386-opc.lo
In file included from i386-opc.c:24:
i386-tbl.h:1525:9: warning: missing initializer for field ‘cpuwbnoinvd’ of ‘struct <anonymous>’ [-Wmissing-field-initializers]
 1525 |         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
      |         ^
In file included from i386-opc.c:23:
i386-opc.h:357:20: note: ‘cpuwbnoinvd’ declared here
  357 |       unsigned int cpuwbnoinvd:1;
      |                    ^~~~~~~~~~~
In file included from i386-opc.c:24:
i386-tbl.h:1529:13: warning: excess elements in struct initializer
 1529 |       0, 0, 0, 0, 0, 0 },
      |             ^
i386-tbl.h:1529:13: note: (near initialization for ‘i386_optab[95].opcode_modifier’)
i386-tbl.h:1529:16: warning: excess elements in struct initializer
 1529 |       0, 0, 0, 0, 0, 0 },
      |                ^
i386-tbl.h:1529:16: note: (near initialization for ‘i386_optab[95].opcode_modifier’)
i386-tbl.h:1529:19: warning: excess elements in struct initializer
 1529 |       0, 0, 0, 0, 0, 0 },
      |                   ^
i386-tbl.h:1529:19: note: (near initialization for ‘i386_optab[95].opcode_modifier’)
i386-tbl.h:1529:22: warning: excess elements in struct initializer
 1529 |       0, 0, 0, 0, 0, 0 },
      |                      ^
i386-tbl.h:1529:22: note: (near initialization for ‘i386_optab[95].opcode_modifier’)
i386-tbl.h:1532:13: warning: excess elements in struct initializer
 1532 |    1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
      |             ^
i386-tbl.h:1532:13: note: (near initialization for ‘i386_optab[95].operand_types[0].bitfield’)
i386-tbl.h:1532:16: warning: excess elements in struct initializer
 1532 |    1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
      |                ^
i386-tbl.h:1532:16: note: (near initialization for ‘i386_optab[95].operand_types[0].bitfield’)
i386-tbl.h:1532:19: warning: excess elements in struct initializer
 1532 |    1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
      |                   ^
i386-tbl.h:1532:19: note: (near initialization for ‘i386_optab[95].operand_types[0].bitfield’)
i386-tbl.h:1532:22: warning: excess elements in struct initializer
 1532 |    1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
      |                      ^
i386-tbl.h:1532:22: note: (near initialization for ‘i386_optab[95].operand_types[0].bitfield’)
i386-tbl.h:1532:25: warning: excess elements in struct initializer
 1532 |    1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
      |                         ^
i386-tbl.h:1532:25: note: (near initialization for ‘i386_optab[95].operand_types[0].bitfield’)
i386-tbl.h:1532:28: warning: excess elements in struct initializer
 1532 |    1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
      |                            ^
i386-tbl.h:1532:28: note: (near initialization for ‘i386_optab[95].operand_types[0].bitfield’)
i386-tbl.h:1532:31: warning: excess elements in struct initializer
 1532 |    1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
      |                               ^
i386-tbl.h:1532:31: note: (near initialization for ‘i386_optab[95].operand_types[0].bitfield’)
i386-tbl.h:1532:34: warning: excess elements in struct initializer
 1532 |    1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
      |                                  ^
i386-tbl.h:1532:34: note: (near initialization for ‘i386_optab[95].operand_types[0].bitfield’)
  CCLD     libopcodes.la
libtooldir=`/bin/bash ./libtool --config | sed -n -e 's/^objdir=//p'`; \
if [ -f $libtooldir/libopcodes.a ]; then \
  cp $libtooldir/libopcodes.a libopcodes.tmp; \
  /usr/bin/ranlib libopcodes.tmp; \
  /bin/bash ./../move-if-change libopcodes.tmp libopcodes.a; \
else true; fi
touch stamp-lib

I tried to find the problem even I don't know how to deal with assembly to help this issue to solve faster, and I find the following:
When I look to other commands than myinc I find that they have a lower number of bits than mine:

{ "inc", 1, 0xfe, 0x0, 1,
    { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0 } },
    { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0 },
    { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
          0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0,
          0, 0, 0 } } } },
  { "myinc", 1, 0xfe, 0x0, 1,
    { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
    { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0 },
    { { { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
          1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },

But when I look to the task documentation I find that the parts of other commands that appear in the git diff is seems tell me that they equal to the myinc bits number:

diff --git a/opcodes/i386-tbl.h b/opcodes/i386-tbl.h
index af583ce578..3cc341f303 100644
--- a/opcodes/i386-tbl.h
+++ b/opcodes/i386-tbl.h
@@ -1502,6 +1502,19 @@ const insn_template i386_optab[] =
     { { { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	  0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
 	  1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
+  { "myinc", 1, 0xfe, 0x0, 1,
+    { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+    { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0 },
+    { { { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	  0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
+	  1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 } } } },
   { "sub", 2, 0x28, None, 1,
     { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

You can note the lower part of the myinc command in the task documentation is equal to the previous instruction, but in my local machine their is a difference, and I don't know why? and I don't know how can I create a version for myinc suitable with the size of bits that allowed for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions