paulgazz / kmax

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

Add support for kmax directory rewrites #192

Closed paulgazz closed 2 years ago

paulgazz commented 2 years ago

In Kbuild, to specify a compilation unit, there are cases where the path and the realpath do not achieve the same result, for instance, in commit 1fc31638eb79eff8b1fb0e1bfcd5f9dbddbf16e2

drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.o

will not be built, but a file that has the same realpath, but with some included relative paths, will be built

drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn30/display_mode_vba_30.o 

This affects krepair in two ways:

  1. kmax will not find the Makefile build constraints for the realpath, because the Makefile in amdgpu is what has the constraints for ../display, unlike most (but not all) paths in kbuild where the realpath has the Makefiles in each subdirectory in the path
  2. klocalizer/koverage cannot compile the unit, because make requires having the relative paths and will not find the object file in the Makefiles

These have the same root cause: the Makefiles reference compilation units in non-descendant directories by looking into parent directories with ../.

Right now, there is support for solving (2) above, the --build-paths, but this works per-compilation unit (see #189) and does nothing to help (1).

Let's instead have a general solution that helps with both. If we instead rewrite any incoming compilation unit paths according to a mapping, then this should help solve both (1) and (2) at once. There can be a built-in mapping (that can be disabled) and user-specific mappings to replace the build-targets.

A test of whether this is working can use

klocalizer --repair defconfig --include-mutex 1fc31638eb79eff8b1fb0e1bfcd5f9dbddbf16e2.patch

where defconfig is from make defconfig after checking out 1fc31638eb79eff8b1fb0e1bfcd5f9dbddbf16e2 and doing git show > 1fc31638eb79eff8b1fb0e1bfcd5f9dbddbf16e2.patch