Skip to content

Commit

Permalink
x86: Fix kprobes build with non-gawk awk
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Acked-by Masami Hiramatsu <mhiramat@redhat.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091213220437.GA27718@progeny.tock>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
jrn authored and Ingo Molnar committed Dec 15, 2009
1 parent bf08b3b commit 2363756
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions arch/x86/tools/gen-insn-attr-x86.awk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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++)
Expand Down

0 comments on commit 2363756

Please sign in to comment.