objtool's elf_write_insn() does extra checking when writing to
an instruction so use that rather than a plain memcpy().

Signed-off-by: Matt Helsley <mhels...@vmware.com>
---
 tools/objtool/mcount.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/tools/objtool/mcount.c b/tools/objtool/mcount.c
index 629eb7222ef3..029e6e72c972 100644
--- a/tools/objtool/mcount.c
+++ b/tools/objtool/mcount.c
@@ -66,9 +66,7 @@ static int make_nop_x86(struct section *txts, size_t const 
offset)
        if (memcmp(op, ip_relative_call_x86, 5) != 0)
                return -1;
 
-       /* convert to nop */
-       memcpy(op, ideal_nop, 5);
-       return 0;
+       return elf_write_insn(lf, txts, offset, 5, ideal_nop);
 }
 
 static const char ideal_nop4_arm_le[4] = { 0x00, 0x00, 0xa0, 0xe1 }; /* mov 
r0, r0 */
@@ -117,7 +115,8 @@ static int make_nop_arm(struct section *txts, size_t const 
offset)
 
        /* Convert to nop */
        do {
-               memcpy(map + off, ideal_nop, nop_size);
+               if (elf_write_insn(lf, txts, off, nop_size, ideal_nop))
+                       return -1;
                off += nop_size;
        } while (--cnt > 0);
 
@@ -136,8 +135,7 @@ static int make_nop_arm64(struct section *txts, size_t 
const offset)
                return -1;
 
        /* Convert to nop */
-       memcpy(map + offset, ideal_nop, 4);
-       return 0;
+       return elf_write_insn(lf, txts, offset, 4, ideal_nop);
 }
 
 /* Names of the sections that could contain calls to mcount. */
-- 
2.20.1

Reply via email to