paulgazz / kmax

A collection of analysis tools for Kconfig and Kbuild constraints.
42 stars 21 forks source link

C static analysis code fails to consider conditional directives without spaces #277

Closed lolrepeatlol closed 1 month ago

lolrepeatlol commented 2 months ago

Summary

Steps to reproduce

Steps followed

  1. Clone the Linux kernel and cd into the new directory.
  2. Checkout commit 4bea747f3fbec33c16d369b2f51e55981d7c78d0 with git checkout 4bea747f3fbec33c16d369b2f51e55981d7c78d0.
  3. Get the diff with git show > 4bea747f3fbec33c16d369b2f51e55981d7c78d0.diff.
  4. Get allnoconfig with make.cross ARCH=x86_64 allnoconfig.
  5. Repair the newly-created configuration with klocalizer --repair .config -a x86_64 --include-mutex 4bea747f3fbec33c16d369b2f51e55981d7c78d0.diff.

What I expected to happen

  1. I expected the klocalizer command to complete without any errors, creating a new repaired configuration file that applies constraints from the diff.

What actually happened

  1. I observed the following error:
    (kmaxtemp) alexei@turing:~/LinuxKernels/TesterKernels/linux$ klocalizer --repair .config -a x86_64 --include-mutex 4bea747f3fbec33c16d369b2f51e55981d7c78d0.diff
    klocalizer, kmax 4.8-rc4
    INFO: Diff file was given as input ("4bea747f3fbec33c16d369b2f51e55981d7c78d0.diff"): assuming it was applied to the Linux source.
    WARNING: No cached formulas for ae2d37861ddd available for download :(
    Traceback (most recent call last):
    File "/home/alexei/LinuxKernels/TesterKernels/kmaxtemp/bin/klocalizer", line 1726, in <module>
    klocalizerCLI()
    File "/home/alexei/LinuxKernels/TesterKernels/kmaxtemp/bin/klocalizer", line 813, in klocalizerCLI
    root_cb = SyntaxAnalysis.get_conditional_blocks_of_file(srcfile_fullpath)
    File "/home/alexei/LinuxKernels/TesterKernels/kmaxtemp/lib/python3.8/site-packages/kmax/superc.py", line 762, in get_conditional_blocks_of_file
    cb = SyntaxAnalysis.get_conditional_blocks(content, line_count)
    File "/home/alexei/LinuxKernels/TesterKernels/kmaxtemp/lib/python3.8/site-packages/kmax/superc.py", line 714, in get_conditional_blocks
    stack[-1].sub_block_groups.append([new_cb])
    IndexError: list index out of range

Additional information:

if(NUM_XMIT_BUFFS > 1) //line 1020

if(test_and_set_bit(0,(void *) &p->lock)) {
    printk("%s: Queue was locked\n",dev->name);
    return NETDEV_TX_BUSY;
}
else

endif

{
    len = skb->len;
    if (len < ETH_ZLEN) {
        memset((void *)p->xmit_cbuffs[p->xmit_count], 0,
               ETH_ZLEN);
        len = ETH_ZLEN;
    }
    skb_copy_from_linear_data(skb, (void *)p->xmit_cbuffs[p->xmit_count], skb->len);

if (NUM_XMIT_BUFFS == 1)


* When adding a space between `if` and `(NUM_XMIT_BUFFS > 1)`, the issue disappears and `klocalizer` attempts to compute line presence conditions:

... INFO: Trying the following architectures: x86_64 INFO: Trying "x86_64" INFO: Computing the line presence conditions under x86_64 for the following units: drivers/net/ethernet/i825xx/sun3_82586.o INFO: Computing line presence conditions for "drivers/net/ethernet/i825xx/sun3_82586.c" [STEP 1/3] reading kextract file [STEP 1/3] finished reading kextract file [STEP 2/3] translated 17299/17299 configuration option dependencies [STEP 3/3] converted 17273/17273 constraints to smtlib2 format [STEP 3/3] pickling the map [STEP 3/3] done WARNING: Failed to compute line presence conditions for "drivers/net/ethernet/i825xx/sun3_82586.c": SuperC config generation error INFO: Searching for a constraints model that cover all or part of the constraints ERROR: No satisfying configuration found. (venv) alexei@turing:~/LinuxKernels/TesterKernels/linux$