kconfig-language.rst 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. ================
  2. Kconfig Language
  3. ================
  4. Introduction
  5. ------------
  6. The configuration database is a collection of configuration options
  7. organized in a tree structure::
  8. +- Code maturity level options
  9. | +- Prompt for development and/or incomplete code/drivers
  10. +- General setup
  11. | +- Networking support
  12. | +- System V IPC
  13. | +- BSD Process Accounting
  14. | +- Sysctl support
  15. +- Loadable module support
  16. | +- Enable loadable module support
  17. | +- Set version information on all module symbols
  18. | +- Kernel module loader
  19. +- ...
  20. Every entry has its own dependencies. These dependencies are used
  21. to determine the visibility of an entry. Any child entry is only
  22. visible if its parent entry is also visible.
  23. Menu entries
  24. ------------
  25. Most entries define a config option; all other entries help to organize
  26. them. A single configuration option is defined like this::
  27. config MODVERSIONS
  28. bool "Set version information on all module symbols"
  29. depends on MODULES
  30. help
  31. Usually, modules have to be recompiled whenever you switch to a new
  32. kernel. ...
  33. Every line starts with a key word and can be followed by multiple
  34. arguments. "config" starts a new config entry. The following lines
  35. define attributes for this config option. Attributes can be the type of
  36. the config option, input prompt, dependencies, help text and default
  37. values. A config option can be defined multiple times with the same
  38. name, but every definition can have only a single input prompt and the
  39. type must not conflict.
  40. Menu attributes
  41. ---------------
  42. A menu entry can have a number of attributes. Not all of them are
  43. applicable everywhere (see syntax).
  44. - type definition: "bool"/"tristate"/"string"/"hex"/"int"
  45. Every config option must have a type. There are only two basic types:
  46. tristate and string; the other types are based on these two. The type
  47. definition optionally accepts an input prompt, so these two examples
  48. are equivalent::
  49. bool "Networking support"
  50. and::
  51. bool
  52. prompt "Networking support"
  53. - input prompt: "prompt" <prompt> ["if" <expr>]
  54. Every menu entry can have at most one prompt, which is used to display
  55. to the user. Optionally dependencies only for this prompt can be added
  56. with "if". If a prompt is not present, the config option is a non-visible
  57. symbol, meaning its value cannot be directly changed by the user (such as
  58. altering the value in ``.config``) and the option will not appear in any
  59. config menus. Its value can only be set via "default" and "select" (see
  60. below).
  61. - default value: "default" <expr> ["if" <expr>]
  62. A config option can have any number of default values. If multiple
  63. default values are visible, only the first defined one is active.
  64. Default values are not limited to the menu entry where they are
  65. defined. This means the default can be defined somewhere else or be
  66. overridden by an earlier definition.
  67. The default value is only assigned to the config symbol if no other
  68. value was set by the user (via the input prompt above). If an input
  69. prompt is visible the default value is presented to the user and can
  70. be overridden by him.
  71. Optionally, dependencies only for this default value can be added with
  72. "if".
  73. The default value deliberately defaults to 'n' in order to avoid bloating the
  74. build. With few exceptions, new config options should not change this. The
  75. intent is for "make oldconfig" to add as little as possible to the config from
  76. release to release.
  77. Note:
  78. Things that merit "default y/m" include:
  79. a) A new Kconfig option for something that used to always be built
  80. should be "default y".
  81. b) A new gatekeeping Kconfig option that hides/shows other Kconfig
  82. options (but does not generate any code of its own), should be
  83. "default y" so people will see those other options.
  84. c) Sub-driver behavior or similar options for a driver that is
  85. "default n". This allows you to provide sane defaults.
  86. d) Hardware or infrastructure that everybody expects, such as CONFIG_NET
  87. or CONFIG_BLOCK. These are rare exceptions.
  88. - type definition + default value::
  89. "def_bool"/"def_tristate" <expr> ["if" <expr>]
  90. This is a shorthand notation for a type definition plus a value.
  91. Optionally dependencies for this default value can be added with "if".
  92. - dependencies: "depends on" <expr> ["if" <expr>]
  93. This defines a dependency for this menu entry. If multiple
  94. dependencies are defined, they are connected with '&&'. Dependencies
  95. are applied to all other options within this menu entry (which also
  96. accept an "if" expression), so these two examples are equivalent::
  97. bool "foo" if BAR
  98. default y if BAR
  99. and::
  100. depends on BAR
  101. bool "foo"
  102. default y
  103. The dependency definition itself may be conditional by appending "if"
  104. followed by an expression. For example::
  105. config FOO
  106. tristate
  107. depends on BAR if BAZ
  108. meaning that FOO is constrained by the value of BAR only if BAZ is
  109. also set.
  110. - reverse dependencies: "select" <symbol> ["if" <expr>]
  111. While normal dependencies reduce the upper limit of a symbol (see
  112. below), reverse dependencies can be used to force a lower limit of
  113. another symbol. The value of the current menu symbol is used as the
  114. minimal value <symbol> can be set to. If <symbol> is selected multiple
  115. times, the limit is set to the largest selection.
  116. Reverse dependencies can only be used with boolean or tristate
  117. symbols.
  118. Note:
  119. select should be used with care. select will force
  120. a symbol to a value without visiting the dependencies.
  121. By abusing select you are able to select a symbol FOO even
  122. if FOO depends on BAR that is not set.
  123. In general use select only for non-visible symbols
  124. (no prompts anywhere) and for symbols with no dependencies.
  125. That will limit the usefulness but on the other hand avoid
  126. the illegal configurations all over.
  127. If "select" <symbol> is followed by "if" <expr>, <symbol> will be
  128. selected by the logical AND of the value of the current menu symbol
  129. and <expr>. This means, the lower limit can be downgraded due to the
  130. presence of "if" <expr>. This behavior may seem weird, but we rely on
  131. it. (The future of this behavior is undecided.)
  132. - weak reverse dependencies: "imply" <symbol> ["if" <expr>]
  133. This is similar to "select" as it enforces a lower limit on another
  134. symbol except that the "implied" symbol's value may still be set to n
  135. from a direct dependency or with a visible prompt.
  136. Given the following example::
  137. config FOO
  138. tristate "foo"
  139. imply BAZ
  140. config BAZ
  141. tristate "baz"
  142. depends on BAR
  143. The following values are possible:
  144. === === ============= ==============
  145. FOO BAR BAZ's default choice for BAZ
  146. === === ============= ==============
  147. n y n N/m/y
  148. m y m M/y/n
  149. y y y Y/m/n
  150. n m n N/m
  151. m m m M/n
  152. y m m M/n
  153. y n * N
  154. === === ============= ==============
  155. This is useful e.g. with multiple drivers that want to indicate their
  156. ability to hook into a secondary subsystem while allowing the user to
  157. configure that subsystem out without also having to unset these drivers.
  158. Note: If the feature provided by BAZ is highly desirable for FOO,
  159. FOO should imply not only BAZ, but also its dependency BAR::
  160. config FOO
  161. tristate "foo"
  162. imply BAR
  163. imply BAZ
  164. Note: If "imply" <symbol> is followed by "if" <expr>, the default of <symbol>
  165. will be the logical AND of the value of the current menu symbol and <expr>.
  166. (The future of this behavior is undecided.)
  167. - limiting menu display: "visible if" <expr>
  168. This attribute is only applicable to menu blocks, if the condition is
  169. false, the menu block is not displayed to the user (the symbols
  170. contained there can still be selected by other symbols, though). It is
  171. similar to a conditional "prompt" attribute for individual menu
  172. entries. Default value of "visible" is true.
  173. - numerical ranges: "range" <symbol> <symbol> ["if" <expr>]
  174. This allows limiting the range of possible input values for int
  175. and hex symbols. The user can only input a value which is larger than
  176. or equal to the first symbol and smaller than or equal to the second
  177. symbol.
  178. - help text: "help"
  179. This defines a help text. The end of the help text is determined by
  180. the indentation level, this means it ends at the first line which has
  181. a smaller indentation than the first line of the help text.
  182. - module attribute: "modules"
  183. This declares the symbol to be used as the MODULES symbol, which
  184. enables the third modular state for all config symbols.
  185. At most one symbol may have the "modules" option set.
  186. - transitional attribute: "transitional"
  187. This declares the symbol as transitional, meaning it should be processed
  188. during configuration but omitted from newly written .config files.
  189. Transitional symbols are useful for backward compatibility during config
  190. option migrations - they allow olddefconfig to process existing .config
  191. files while ensuring the old option doesn't appear in new configurations.
  192. A transitional symbol:
  193. - Has no prompt (is not visible to users in menus)
  194. - Is processed normally during configuration (values are read and used)
  195. - Can be referenced in default expressions of other symbols
  196. - Is not written to new .config files
  197. - Cannot have any other properties (it is a pass-through option)
  198. Example migration from OLD_NAME to NEW_NAME::
  199. config NEW_NAME
  200. bool "New option name"
  201. default OLD_NAME
  202. help
  203. This replaces the old CONFIG_OLD_NAME option.
  204. config OLD_NAME
  205. bool
  206. transitional
  207. help
  208. Transitional config for OLD_NAME to NEW_NAME migration.
  209. With this setup, existing .config files with "CONFIG_OLD_NAME=y" will
  210. result in "CONFIG_NEW_NAME=y" being set, while CONFIG_OLD_NAME will be
  211. omitted from newly written .config files.
  212. Menu dependencies
  213. -----------------
  214. Dependencies define the visibility of a menu entry and can also reduce
  215. the input range of tristate symbols. The tristate logic used in the
  216. expressions uses one more state than normal boolean logic to express the
  217. module state. Dependency expressions have the following syntax::
  218. <expr> ::= <symbol> (1)
  219. <symbol> '=' <symbol> (2)
  220. <symbol> '!=' <symbol> (3)
  221. <symbol1> '<' <symbol2> (4)
  222. <symbol1> '>' <symbol2> (4)
  223. <symbol1> '<=' <symbol2> (4)
  224. <symbol1> '>=' <symbol2> (4)
  225. '(' <expr> ')' (5)
  226. '!' <expr> (6)
  227. <expr> '&&' <expr> (7)
  228. <expr> '||' <expr> (8)
  229. Expressions are listed in decreasing order of precedence.
  230. (1) Convert the symbol into an expression. Boolean and tristate symbols
  231. are simply converted into the respective expression values. All
  232. other symbol types result in 'n'.
  233. (2) If the values of both symbols are equal, it returns 'y',
  234. otherwise 'n'.
  235. (3) If the values of both symbols are equal, it returns 'n',
  236. otherwise 'y'.
  237. (4) If value of <symbol1> is respectively lower, greater, lower-or-equal,
  238. or greater-or-equal than value of <symbol2>, it returns 'y',
  239. otherwise 'n'.
  240. (5) Returns the value of the expression. Used to override precedence.
  241. (6) Returns the result of (2-/expr/).
  242. (7) Returns the result of min(/expr/, /expr/).
  243. (8) Returns the result of max(/expr/, /expr/).
  244. An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2
  245. respectively for calculations). A menu entry becomes visible when its
  246. expression evaluates to 'm' or 'y'.
  247. There are two types of symbols: constant and non-constant symbols.
  248. Non-constant symbols are the most common ones and are defined with the
  249. 'config' statement. Non-constant symbols consist entirely of alphanumeric
  250. characters or underscores.
  251. Constant symbols are only part of expressions. Constant symbols are
  252. always surrounded by single or double quotes. Within the quote, any
  253. other character is allowed and the quotes can be escaped using '\'.
  254. Menu structure
  255. --------------
  256. The position of a menu entry in the tree is determined in two ways. First
  257. it can be specified explicitly::
  258. menu "Network device support"
  259. depends on NET
  260. config NETDEVICES
  261. ...
  262. endmenu
  263. All entries within the "menu" ... "endmenu" block become a submenu of
  264. "Network device support". All subentries inherit the dependencies from
  265. the menu entry, e.g. this means the dependency "NET" is added to the
  266. dependency list of the config option NETDEVICES.
  267. The other way to generate the menu structure is done by analyzing the
  268. dependencies. If a menu entry somehow depends on the previous entry, it
  269. can be made a submenu of it. First, the previous (parent) symbol must
  270. be part of the dependency list and then one of these two conditions
  271. must be true:
  272. - the child entry must become invisible, if the parent is set to 'n'
  273. - the child entry must only be visible, if the parent is visible::
  274. config MODULES
  275. bool "Enable loadable module support"
  276. config MODVERSIONS
  277. bool "Set version information on all module symbols"
  278. depends on MODULES
  279. comment "module support disabled"
  280. depends on !MODULES
  281. MODVERSIONS directly depends on MODULES, this means it's only visible if
  282. MODULES is different from 'n'. The comment on the other hand is only
  283. visible when MODULES is set to 'n'.
  284. Kconfig syntax
  285. --------------
  286. The configuration file describes a series of menu entries, where every
  287. line starts with a keyword (except help texts). The following keywords
  288. end a menu entry:
  289. - config
  290. - menuconfig
  291. - choice/endchoice
  292. - comment
  293. - menu/endmenu
  294. - if/endif
  295. - source
  296. The first five also start the definition of a menu entry.
  297. config::
  298. "config" <symbol>
  299. <config options>
  300. This defines a config symbol <symbol> and accepts any of above
  301. attributes as options.
  302. menuconfig::
  303. "menuconfig" <symbol>
  304. <config options>
  305. This is similar to the simple config entry above, but it also gives a
  306. hint to front ends, that all suboptions should be displayed as a
  307. separate list of options. To make sure all the suboptions will really
  308. show up under the menuconfig entry and not outside of it, every item
  309. from the <config options> list must depend on the menuconfig symbol.
  310. In practice, this is achieved by using one of the next two constructs::
  311. (1):
  312. menuconfig M
  313. if M
  314. config C1
  315. config C2
  316. endif
  317. (2):
  318. menuconfig M
  319. config C1
  320. depends on M
  321. config C2
  322. depends on M
  323. In the following examples (3) and (4), C1 and C2 still have the M
  324. dependency, but will not appear under menuconfig M anymore, because
  325. of C0, which doesn't depend on M::
  326. (3):
  327. menuconfig M
  328. config C0
  329. if M
  330. config C1
  331. config C2
  332. endif
  333. (4):
  334. menuconfig M
  335. config C0
  336. config C1
  337. depends on M
  338. config C2
  339. depends on M
  340. choices::
  341. "choice"
  342. <choice options>
  343. <choice block>
  344. "endchoice"
  345. This defines a choice group and accepts "prompt", "default", "depends on", and
  346. "help" attributes as options.
  347. A choice only allows a single config entry to be selected.
  348. comment::
  349. "comment" <prompt>
  350. <comment options>
  351. This defines a comment which is displayed to the user during the
  352. configuration process and is also echoed to the output files. The only
  353. possible options are dependencies.
  354. menu::
  355. "menu" <prompt>
  356. <menu options>
  357. <menu block>
  358. "endmenu"
  359. This defines a menu block, see "Menu structure" above for more
  360. information. The only possible options are dependencies and "visible"
  361. attributes.
  362. if::
  363. "if" <expr>
  364. <if block>
  365. "endif"
  366. This defines an if block. The dependency expression <expr> is appended
  367. to all enclosed menu entries.
  368. source::
  369. "source" <prompt>
  370. This reads the specified configuration file. This file is always parsed.
  371. mainmenu::
  372. "mainmenu" <prompt>
  373. This sets the config program's title bar if the config program chooses
  374. to use it. It should be placed at the top of the configuration, before any
  375. other statement.
  376. '#' Kconfig source file comment:
  377. An unquoted '#' character anywhere in a source file line indicates
  378. the beginning of a source file comment. The remainder of that line
  379. is a comment.
  380. Kconfig hints
  381. -------------
  382. This is a collection of Kconfig tips, most of which aren't obvious at
  383. first glance and most of which have become idioms in several Kconfig
  384. files.
  385. Adding common features and make the usage configurable
  386. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  387. It is a common idiom to implement a feature/functionality that are
  388. relevant for some architectures but not all.
  389. The recommended way to do so is to use a config variable named HAVE_*
  390. that is defined in a common Kconfig file and selected by the relevant
  391. architectures.
  392. An example is the generic IOMAP functionality.
  393. We would in lib/Kconfig see::
  394. # Generic IOMAP is used to ...
  395. config HAVE_GENERIC_IOMAP
  396. config GENERIC_IOMAP
  397. depends on HAVE_GENERIC_IOMAP && FOO
  398. And in lib/Makefile we would see::
  399. obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
  400. For each architecture using the generic IOMAP functionality we would see::
  401. config X86
  402. select ...
  403. select HAVE_GENERIC_IOMAP
  404. select ...
  405. Note: we use the existing config option and avoid creating a new
  406. config variable to select HAVE_GENERIC_IOMAP.
  407. Note: the use of the internal config variable HAVE_GENERIC_IOMAP, it is
  408. introduced to overcome the limitation of select which will force a
  409. config option to 'y' no matter the dependencies.
  410. The dependencies are moved to the symbol GENERIC_IOMAP and we avoid the
  411. situation where select forces a symbol equals to 'y'.
  412. Adding features that need compiler support
  413. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  414. There are several features that need compiler support. The recommended way
  415. to describe the dependency on the compiler feature is to use "depends on"
  416. followed by a test macro::
  417. config STACKPROTECTOR
  418. bool "Stack Protector buffer overflow detection"
  419. depends on $(cc-option,-fstack-protector)
  420. ...
  421. If you need to expose a compiler capability to makefiles and/or C source files,
  422. `CC_HAS_` is the recommended prefix for the config option::
  423. config CC_HAS_FOO
  424. def_bool $(success,$(srctree)/scripts/cc-check-foo.sh $(CC))
  425. Build as module only
  426. ~~~~~~~~~~~~~~~~~~~~
  427. To restrict a component build to module-only, qualify its config symbol
  428. with "depends on m". E.g.::
  429. config FOO
  430. depends on BAR && m
  431. limits FOO to module (=m) or disabled (=n).
  432. Compile-testing
  433. ~~~~~~~~~~~~~~~
  434. If a config symbol has a dependency, but the code controlled by the config
  435. symbol can still be compiled if the dependency is not met, it is encouraged to
  436. increase build coverage by adding an "|| COMPILE_TEST" clause to the
  437. dependency. This is especially useful for drivers for more exotic hardware, as
  438. it allows continuous-integration systems to compile-test the code on a more
  439. common system, and detect bugs that way.
  440. Note that compile-tested code should avoid crashing when run on a system where
  441. the dependency is not met.
  442. Architecture and platform dependencies
  443. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  444. Due to the presence of stubs, most drivers can now be compiled on most
  445. architectures. However, this does not mean it makes sense to have all drivers
  446. available everywhere, as the actual hardware may only exist on specific
  447. architectures and platforms. This is especially true for on-SoC IP cores,
  448. which may be limited to a specific vendor or SoC family.
  449. To prevent asking the user about drivers that cannot be used on the system(s)
  450. the user is compiling a kernel for, and if it makes sense, config symbols
  451. controlling the compilation of a driver should contain proper dependencies,
  452. limiting the visibility of the symbol to (a superset of) the platform(s) the
  453. driver can be used on. The dependency can be an architecture (e.g. ARM) or
  454. platform (e.g. ARCH_OMAP4) dependency. This makes life simpler not only for
  455. distro config owners, but also for every single developer or user who
  456. configures a kernel.
  457. Such a dependency can be relaxed by combining it with the compile-testing rule
  458. above, leading to:
  459. config FOO
  460. bool "Support for foo hardware"
  461. depends on ARCH_FOO_VENDOR || COMPILE_TEST
  462. Optional dependencies
  463. ~~~~~~~~~~~~~~~~~~~~~
  464. Some drivers are able to optionally use a feature from another module
  465. or build cleanly with that module disabled, but cause a link failure
  466. when trying to use that loadable module from a built-in driver.
  467. The recommended way to express this optional dependency in Kconfig logic
  468. uses the conditional form::
  469. config FOO
  470. tristate "Support for foo hardware"
  471. depends on BAR if BAR
  472. This slightly counterintuitive style is also widely used::
  473. config FOO
  474. tristate "Support for foo hardware"
  475. depends on BAR || !BAR
  476. This means that there is either a dependency on BAR that disallows
  477. the combination of FOO=y with BAR=m, or BAR is completely disabled. The BAR
  478. module must provide all the stubs for !BAR case.
  479. For a more formalized approach if there are multiple drivers that have
  480. the same dependency, a helper symbol can be used, like::
  481. config FOO
  482. tristate "Support for foo hardware"
  483. depends on BAR_OPTIONAL
  484. config BAR_OPTIONAL
  485. def_tristate BAR || !BAR
  486. Much less favorable way to express optional dependency is IS_REACHABLE() within
  487. the module code, useful for example when the module BAR does not provide
  488. !BAR stubs::
  489. foo_init()
  490. {
  491. if (IS_REACHABLE(CONFIG_BAR))
  492. bar_register(&foo);
  493. ...
  494. }
  495. IS_REACHABLE() is generally discouraged, because the code will be silently
  496. discarded, when CONFIG_BAR=m and this code is built-in. This is not what users
  497. usually expect when enabling BAR as module.
  498. Kconfig recursive dependency limitations
  499. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  500. If you've hit the Kconfig error: "recursive dependency detected" you've run
  501. into a recursive dependency issue with Kconfig, a recursive dependency can be
  502. summarized as a circular dependency. The kconfig tools need to ensure that
  503. Kconfig files comply with specified configuration requirements. In order to do
  504. that kconfig must determine the values that are possible for all Kconfig
  505. symbols, this is currently not possible if there is a circular relation
  506. between two or more Kconfig symbols. For more details refer to the "Simple
  507. Kconfig recursive issue" subsection below. Kconfig does not do recursive
  508. dependency resolution; this has a few implications for Kconfig file writers.
  509. We'll first explain why this issues exists and then provide an example
  510. technical limitation which this brings upon Kconfig developers. Eager
  511. developers wishing to try to address this limitation should read the next
  512. subsections.
  513. Simple Kconfig recursive issue
  514. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  515. Read: Documentation/kbuild/Kconfig.recursion-issue-01
  516. Test with::
  517. make KBUILD_KCONFIG=Documentation/kbuild/Kconfig.recursion-issue-01 allnoconfig
  518. Cumulative Kconfig recursive issue
  519. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  520. Read: Documentation/kbuild/Kconfig.recursion-issue-02
  521. Test with::
  522. make KBUILD_KCONFIG=Documentation/kbuild/Kconfig.recursion-issue-02 allnoconfig
  523. Practical solutions to kconfig recursive issue
  524. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  525. Developers who run into the recursive Kconfig issue have two options
  526. at their disposal. We document them below and also provide a list of
  527. historical issues resolved through these different solutions.
  528. a) Remove any superfluous "select FOO" or "depends on FOO"
  529. b) Match dependency semantics:
  530. b1) Swap all "select FOO" to "depends on FOO" or,
  531. b2) Swap all "depends on FOO" to "select FOO"
  532. The resolution to a) can be tested with the sample Kconfig file
  533. Documentation/kbuild/Kconfig.recursion-issue-01 through the removal
  534. of the "select CORE" from CORE_BELL_A_ADVANCED as that is implicit already
  535. since CORE_BELL_A depends on CORE. At times it may not be possible to remove
  536. some dependency criteria, for such cases you can work with solution b).
  537. The two different resolutions for b) can be tested in the sample Kconfig file
  538. Documentation/kbuild/Kconfig.recursion-issue-02.
  539. Below is a list of examples of prior fixes for these types of recursive issues;
  540. all errors appear to involve one or more "select" statements and one or more
  541. "depends on".
  542. ============ ===================================
  543. commit fix
  544. ============ ===================================
  545. 06b718c01208 select A -> depends on A
  546. c22eacfe82f9 depends on A -> depends on B
  547. 6a91e854442c select A -> depends on A
  548. 118c565a8f2e select A -> select B
  549. f004e5594705 select A -> depends on A
  550. c7861f37b4c6 depends on A -> (null)
  551. 80c69915e5fb select A -> (null) (1)
  552. c2218e26c0d0 select A -> depends on A (1)
  553. d6ae99d04e1c select A -> depends on A
  554. 95ca19cf8cbf select A -> depends on A
  555. 8f057d7bca54 depends on A -> (null)
  556. 8f057d7bca54 depends on A -> select A
  557. a0701f04846e select A -> depends on A
  558. 0c8b92f7f259 depends on A -> (null)
  559. e4e9e0540928 select A -> depends on A (2)
  560. 7453ea886e87 depends on A > (null) (1)
  561. 7b1fff7e4fdf select A -> depends on A
  562. 86c747d2a4f0 select A -> depends on A
  563. d9f9ab51e55e select A -> depends on A
  564. 0c51a4d8abd6 depends on A -> select A (3)
  565. e98062ed6dc4 select A -> depends on A (3)
  566. 91e5d284a7f1 select A -> (null)
  567. ============ ===================================
  568. (1) Partial (or no) quote of error.
  569. (2) That seems to be the gist of that fix.
  570. (3) Same error.
  571. Future kconfig work
  572. ~~~~~~~~~~~~~~~~~~~
  573. Work on kconfig is welcomed on both areas of clarifying semantics and on
  574. evaluating the use of a full SAT solver for it. A full SAT solver can be
  575. desirable to enable more complex dependency mappings and / or queries,
  576. for instance one possible use case for a SAT solver could be that of handling
  577. the current known recursive dependency issues. It is not known if this would
  578. address such issues but such evaluation is desirable. If support for a full SAT
  579. solver proves too complex or that it cannot address recursive dependency issues
  580. Kconfig should have at least clear and well defined semantics which also
  581. addresses and documents limitations or requirements such as the ones dealing
  582. with recursive dependencies.
  583. Further work on both of these areas is welcomed on Kconfig. We elaborate
  584. on both of these in the next two subsections.
  585. Semantics of Kconfig
  586. ~~~~~~~~~~~~~~~~~~~~
  587. The use of Kconfig is broad, Linux is now only one of Kconfig's users:
  588. one study has completed a broad analysis of Kconfig use in 12 projects [0]_.
  589. Despite its widespread use, and although this document does a reasonable job
  590. in documenting basic Kconfig syntax a more precise definition of Kconfig
  591. semantics is welcomed. One project deduced Kconfig semantics through
  592. the use of the xconfig configurator [1]_. Work should be done to confirm if
  593. the deduced semantics matches our intended Kconfig design goals.
  594. Another project formalized a denotational semantics of a core subset of
  595. the Kconfig language [10]_.
  596. Having well defined semantics can be useful for tools for practical
  597. evaluation of dependencies, for instance one such case was work to
  598. express in boolean abstraction of the inferred semantics of Kconfig to
  599. translate Kconfig logic into boolean formulas and run a SAT solver on this to
  600. find dead code / features (always inactive), 114 dead features were found in
  601. Linux using this methodology [1]_ (Section 8: Threats to validity).
  602. The kismet tool, based on the semantics in [10]_, finds abuses of reverse
  603. dependencies and has led to dozens of committed fixes to Linux Kconfig files [11]_.
  604. Confirming this could prove useful as Kconfig stands as one of the leading
  605. industrial variability modeling languages [1]_ [2]_. Its study would help
  606. evaluate practical uses of such languages, their use was only theoretical
  607. and real world requirements were not well understood. As it stands though
  608. only reverse engineering techniques have been used to deduce semantics from
  609. variability modeling languages such as Kconfig [3]_.
  610. .. [0] https://www.eng.uwaterloo.ca/~shshe/kconfig_semantics.pdf
  611. .. [1] https://gsd.uwaterloo.ca/sites/default/files/vm-2013-berger.pdf
  612. .. [2] https://gsd.uwaterloo.ca/sites/default/files/ase241-berger_0.pdf
  613. .. [3] https://gsd.uwaterloo.ca/sites/default/files/icse2011.pdf
  614. Full SAT solver for Kconfig
  615. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  616. Although SAT solvers [4]_ haven't yet been used by Kconfig directly, as noted
  617. in the previous subsection, work has been done however to express in boolean
  618. abstraction the inferred semantics of Kconfig to translate Kconfig logic into
  619. boolean formulas and run a SAT solver on it [5]_. Another known related project
  620. is CADOS [6]_ (former VAMOS [7]_) and the tools, mainly undertaker [8]_, which
  621. has been introduced first with [9]_. The basic concept of undertaker is to
  622. extract variability models from Kconfig and put them together with a
  623. propositional formula extracted from CPP #ifdefs and build-rules into a SAT
  624. solver in order to find dead code, dead files, and dead symbols. If using a SAT
  625. solver is desirable on Kconfig one approach would be to evaluate repurposing
  626. such efforts somehow on Kconfig. There is enough interest from mentors of
  627. existing projects to not only help advise how to integrate this work upstream
  628. but also help maintain it long term. Interested developers should visit:
  629. https://kernelnewbies.org/KernelProjects/kconfig-sat
  630. .. [4] https://www.cs.cornell.edu/~sabhar/chapters/SATSolvers-KR-Handbook.pdf
  631. .. [5] https://gsd.uwaterloo.ca/sites/default/files/vm-2013-berger.pdf
  632. .. [6] https://cados.cs.fau.de
  633. .. [7] https://vamos.cs.fau.de
  634. .. [8] https://undertaker.cs.fau.de
  635. .. [9] https://www4.cs.fau.de/Publications/2011/tartler_11_eurosys.pdf
  636. .. [10] https://paulgazzillo.com/papers/esecfse21.pdf
  637. .. [11] https://github.com/paulgazz/kmax