x86: Fix kprobes build with non-gawk awk
PATCH 1/1 x86: Fix kprobes build with non-gawk awk
The instruction attribute table generator fails when run by mawk or original-awk:
$ mawk -f arch/x86/tools/gen-insn-attr-x86.awk \ arch/x86/lib/x86-opcode-map.txt > /dev/null Semantic error at 240: Second IMM error $ echo $? 1
Line 240 contains "c8: ENTER Iw,Ib", which indicates that this instruction has two immediate operands, the second of which is one byte. The script loops through the immediate operands using a for loop.
Unfortunately, there is no guarantee in awk that a for (variable in array) loop will return the indices in increasing order. Internally, both original-awk and mawk iterate over a hash table for this purpose, and both implementations happen to produce the index 2 before 1. The supposed second immediate operand is more than one byte wide, producing the error.
So loop over the indices in increasing order instead. As a side-effect, with mawk this means the silly two-entry hash table never has to be built.
--- arch/x86/tools/gen-insn-attr-x86.awk | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/tools/gen-insn-attr-x86.awk +5 -5
@@ -226,12 +226,12 @@ function add_flags(old,new) { } # convert operands to flags. -function convert_operands(opnd, i,imm,mod) +function convert_operands(count,opnd, i,j,imm,mod) { imm = null mod = null - for (i in opnd) { - i = opnd[i] + for (j = 1; j <= count; j++) { + i = opnd[j] if (match(i, imm_expr) == 1) { if (!imm_flag[i]) semantic_error("Unknown imm opnd: " i)
@@ -282,8 +282,8 @@ function convert_operands(opnd, i,imm,mod) # parse one opcode if (match($i, opnd_expr)) { opnd = $i - split($(i++), opnds, ",") - flags = convert_operands(opnds) + count = split($(i++), opnds, ",") + flags = convert_operands(count, opnds) } if (match($i, ext_expr)) ext = $(i++)
Signature · 1 line
1.6.5.4
Hi Jonathan,
Quoted 14 lines · Jonathan Nieder
The instruction attribute table generator fails when run by mawk or original-awk:
$ mawk -f arch/x86/tools/gen-insn-attr-x86.awk \ arch/x86/lib/x86-opcode-map.txt > /dev/null Semantic error at 240: Second IMM error $ echo $? 1Line 240 contains "c8: ENTER Iw,Ib", which indicates that this instruction has two immediate operands, the second of which is one byte. The script loops through the immediate operands using a for loop.
Quoted 6 lines
Unfortunately, there is no guarantee in awk that a for (variable in array) loop will return the indices in increasing order. Internally, both original-awk and mawk iterate over a hash table for this purpose, and both implementations happen to produce the index 2 before 1. The supposed second immediate operand is more than one byte wide, producing the error.
Oh, I see.
Quoted 4 lines
So loop over the indices in increasing order instead. As a side-effect, with mawk this means the silly two-entry hash table never has to be built.
Thank you for fixing it!
Quoted 41 lines
Cc Masami Hiramatsu <[email protected]>Cc Jim Keniston <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Jonathan Nieder <[email protected]>--- arch/x86/tools/gen-insn-attr-x86.awk | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)arch/x86/tools/gen-insn-attr-x86.awk +5
-5@@ -226,12 +226,12 @@ function add_flags(old,new) { } # convert operands to flags. -function convert_operands(opnd, i,imm,mod) +function convert_operands(count,opnd, i,j,imm,mod) { imm = null mod = null - for (i in opnd) { - i = opnd[i] + for (j = 1; j <= count; j++) { + i = opnd[j] if (match(i, imm_expr) == 1) { if (!imm_flag[i]) semantic_error("Unknown imm opnd: " i)@@ -282,8 +282,8 @@ function convert_operands(opnd, i,imm,mod) # parse one opcode if (match($i, opnd_expr)) { opnd = $i - split($(i++), opnds, ",") - flags = convert_operands(opnds) + count = split($(i++), opnds, ",") + flags = convert_operands(count, opnds) } if (match($i, ext_expr)) ext = $(i++)
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
Quoted 1 line · Masami Hiramatsu
Thank you for fixing it!
No problem. Thanks for looking it over.
Regards,
Jonathan
Commit-ID: 23637568ad0c9b5ab0ad27d2f2f26d1e9282c527 Gitweb: http://git.kernel.org/tip/23637568ad0c9b5ab0ad27d2f2f26d1e9282c527 Author: Jonathan Nieder <[email protected]> AuthorDate: Sun, 13 Dec 2009 16:04:38 -0600 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 15 Dec 2009 20:35:49 +0100
x86: Fix kprobes build with non-gawk awk
The instruction attribute table generator fails when run by mawk or original-awk:
$ mawk -f arch/x86/tools/gen-insn-attr-x86.awk \ arch/x86/lib/x86-opcode-map.txt > /dev/null Semantic error at 240: Second IMM error $ echo $? 1
Line 240 contains "c8: ENTER Iw,Ib", which indicates that this instruction has two immediate operands, the second of which is one byte. The script loops through the immediate operands using a for loop.
Unfortunately, there is no guarantee in awk that a for (variable in array) loop will return the indices in increasing order. Internally, both original-awk and mawk iterate over a hash table for this purpose, and both implementations happen to produce the index 2 before 1. The supposed second immediate operand is more than one byte wide, producing the error.
So loop over the indices in increasing order instead. As a side-effect, with mawk this means the silly two-entry hash table never has to be built.
Acked-by Masami Hiramatsu <[email protected]>
Cc: Jim Keniston <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
LKML-Reference: <[email protected]>
--- arch/x86/tools/gen-insn-attr-x86.awk | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/tools/gen-insn-attr-x86.awk +5 -5
@@ -226,12 +226,12 @@ function add_flags(old,new) { } # convert operands to flags. -function convert_operands(opnd, i,imm,mod) +function convert_operands(count,opnd, i,j,imm,mod) { imm = null mod = null - for (i in opnd) { - i = opnd[i] + for (j = 1; j <= count; j++) { + i = opnd[j] if (match(i, imm_expr) == 1) { if (!imm_flag[i]) semantic_error("Unknown imm opnd: " i)
@@ -282,8 +282,8 @@ function convert_operands(opnd, i,imm,mod) # parse one opcode if (match($i, opnd_expr)) { opnd = $i - split($(i++), opnds, ",") - flags = convert_operands(opnds) + count = split($(i++), opnds, ",") + flags = convert_operands(count, opnds) } if (match($i, ext_expr)) ext = $(i++)