Skip to content

Implement DWARF modversions

Sami Tolvanen asahi linux-kbuild linux-modules lkml rust-for-linux 8 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest18 patches 1 replyIn review
  2. v718 patches 4 repliesSuperseded
  3. v618 patches 27 repliesSuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v519 patches16 repliesSuperseded
v419 patches20 repliesSuperseded
v320 patches14 repliesSuperseded
v219 patches85 repliesSuperseded
v115 patches21 repliesSuperseded

Changes in v8 from the cover letter

- Rebased on v6.13-rc5.

- Changed opts[] to static const and reformatted the array. (Patch 1)

- Moved a stray comment to patch 1. (Patch 2)

Patches in v8 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/18tools: Add gendwarfksymsMAINTAINERS kernel/module/Kconfig scripts/Makefile +6 more+513 -00 replies
2/18gendwarfksyms: Add address matchingscripts/gendwarfksyms/gendwarfksyms.c scripts/gendwarfksyms/gendwarfksyms.h scripts/gendwarfksyms/symbols.c+176 -00 replies
3/18gendwarfksyms: Expand base_typescripts/gendwarfksyms/dwarf.c+160 -00 replies
4/18gendwarfksyms: Add a cache for processed DIEsscripts/gendwarfksyms/Makefile scripts/gendwarfksyms/die.c scripts/gendwarfksyms/dwarf.c +2 more+308 -410 replies
5/18gendwarfksyms: Expand type modifiers and typedefsscripts/gendwarfksyms/die.c scripts/gendwarfksyms/dwarf.c scripts/gendwarfksyms/gendwarfksyms.h+84 -00 replies
6/18gendwarfksyms: Expand subroutine_typescripts/gendwarfksyms/dwarf.c scripts/gendwarfksyms/gendwarfksyms.h+85 -30 replies
7/18gendwarfksyms: Expand array_typescripts/gendwarfksyms/dwarf.c+30 -00 replies
8/18gendwarfksyms: Expand structure typesscripts/gendwarfksyms/dwarf.c scripts/gendwarfksyms/gendwarfksyms.h+141 -20 replies
9/18gendwarfksyms: Limit structure expansionscripts/gendwarfksyms/Makefile scripts/gendwarfksyms/cache.c scripts/gendwarfksyms/dwarf.c +1 more+215 -80 replies
10/18gendwarfksyms: Add die_map debuggingscripts/gendwarfksyms/dwarf.c scripts/gendwarfksyms/gendwarfksyms.c scripts/gendwarfksyms/gendwarfksyms.h+35 -00 replies
11/18gendwarfksyms: Add symtypes outputscripts/gendwarfksyms/Makefile scripts/gendwarfksyms/die.c scripts/gendwarfksyms/dwarf.c +4 more+429 -30 replies
12/18gendwarfksyms: Add symbol versioningscripts/gendwarfksyms/Makefile scripts/gendwarfksyms/dwarf.c scripts/gendwarfksyms/gendwarfksyms.c +3 more+216 -90 replies
13/18gendwarfksyms: Add support for kABI rulesscripts/gendwarfksyms/Makefile scripts/gendwarfksyms/dwarf.c scripts/gendwarfksyms/examples/kabi.h +5 more+531 -40 replies
14/18gendwarfksyms: Add support for reserved and ignored fieldsscripts/gendwarfksyms/dwarf.c scripts/gendwarfksyms/examples/kabi.h scripts/gendwarfksyms/examples/kabi_ex.c +2 more+558 -10 replies
15/18gendwarfksyms: Add support for symbol type pointersscripts/gendwarfksyms/dwarf.c scripts/gendwarfksyms/examples/symbolptr.c scripts/gendwarfksyms/gendwarfksyms.h +1 more+121 -10 replies
16/18export: Add __gendwarfksyms_ptr_ references to exported symbolsinclude/linux/export.h+15 -00 replies
17/18kbuild: Add gendwarfksyms as an alternative to genksymskernel/module/Kconfig scripts/Makefile scripts/Makefile.build+52 -70 replies
18/18Documentation/kbuild: Add DWARF module versioningDocumentation/kbuild/gendwarfksyms.rst Documentation/kbuild/index.rst+309 -00 replies

Reviews trailers per patch

14 of 18 patches have a Reviewed-by or Acked-by.

PatchPetr Pavlu
1/18R-b
2/18R-b
3/18R-b
4/18R-b
5/18R-b
6/18R-b
7/18R-b
8/18R-b
9/18R-b
10/18R-b
11/18R-b
12/18R-b
13/18
14/18R-b
15/18R-b
16/18
17/18
18/18

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v8 thread

Cover letter [PATCH v8 00/18] Implement DWARF modversions

Hi,

Here's v8 of the DWARF modversions series. The main motivation is modversions support for Rust, which is important for distributions like Android that are about to ship Rust kernel modules. Per Luis' request [1], v2 dropped the Rust specific bits from the series and instead added the feature as an option for the entire kernel to make it easier to evaluate the benefits of this approach, and to get better test coverage. Matt is addressing Rust modversion_info compatibility issues in a separate patch set [2] that depends on this series, and actually allows modversions to be enabled with Rust.

Short background: Unlike C, Rust source code doesn't have sufficient information about the final ABI, as the compiler has considerable freedom in adjusting structure layout, for example, which makes using a source code parser like genksyms a non-starter. Based on earlier feedback, this series uses DWARF debugging information for computing versions. DWARF is an established and a relatively stable format, which includes all the necessary ABI details, and adding a CONFIG_DEBUG_INFO dependency for Rust symbol versioning seems like a reasonable trade-off as most distributions already enable it.

The first 15 patches add gendwarfksyms, a tool for computing symbol versions from DWARF. When passed a list of exported symbols and object files, the tool generates an expanded type string for each symbol and computes symbol versions. gendwarfksyms is written in C, uses libdw to process DWARF, and zlib for CRC32. Patch 16 ensures that debugging information is present where we need it, patch 17 adds gendwarfksyms as an alternative to genksyms, and the last patch adds documentation.

v8 is based on 6.13-rc5, and for your convenience, the series is also available here:

https://github.com/samitolvanen/linux/commits/gendwarfksyms-v8

If you also want to test the series with actual Rust modules, this branch adds v13 of Matt's modversion_info series:

https://github.com/samitolvanen/linux/commits/rustmodversions-v8

Sami

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

---

v8:
- Rebased on v6.13-rc5.

- Changed opts[] to static const and reformatted the array. (Patch 1)

- Moved a stray comment to patch 1. (Patch 2)

v7: https://lore.kernel.org/lkml/[email protected]/
- Added a Kconfig description to actually allow build testing each patch. (Patch 1)

- Added a MAINTAINERS entry for gendwarfksyms. (Patch 1)

- Cleaned up includes and fixed a build issue with asprintf not always being present without _GNU_SOURCE. (Patches 1, 11, and 13)

- Adjusted hash table sizes for lower overhead as we're not right now concerned with processing vmlinux.o, and thus need to deal with a smaller number of symbols. (Patches 1, 4, 9, 11, and 13)

- Added error handling for gelf_getsymshndx failures. (Patch 2)

- Renamed the is_declaration function to is_kabi_definition for clarity and reversed the logic per Petr's suggestion. (Patch 9)

- Dropped the redundant default Kconfig tag. (Patch 17)

- Fixed a documentation typo. (Patch 18)

v6: https://lore.kernel.org/lkml/[email protected]/
- Dropped pointer expansion limits as this affects version
stability when exported symbols are removed. (Patch 9)

- Changed local type definitions (in .c files) that are opaque to external users to be treated as declarations even if a definition is available. (Patch 9)

- Switched to zlib's CRC32 implementation per Masahiro's suggestion. (Patch 12)

- Renamed struct_declonly kABI rule to simply declonly, as it applies also to unions and enums, added a new rule for overriding enumerator values, and refactored the examples. (Patch 13)

- Added --stable support for renamed structure members and also added examples. (Patch 14)

- Rebased on linux-kbuild/for-next for Masahiro's symtypes build rule clean-ups. (Patch 17)

- Updated the documentation reflect --stable changes. (Patch 18)

v5: https://lore.kernel.org/lkml/[email protected]/
- Rebased on v6.12-rc5.

- Fixed an issue with limiting structure expansion, and applied Petr's clean-up. (Patch 10)

- Dropped an unnecessary return statement in error path. (Patch
12)

- Addressed several other smaller issues Petr brought up. (Patches 13, 14, and 15)

- Added a KBUILD_GENDWARFKSYMS_STABLE flag to enable --stable for the entire kernel build. (Patch 18)

- Updated documentation to include KBUILD flags. (Patch 19)

- Picked up Reviewed-by tags from v4.

v4: https://lore.kernel.org/lkml/[email protected]/
- Rebased on v6.12-rc2, which now includes all the prerequisites.

- Dropped unnecessary name_only parameter for symbols.c::for_each and cleaned up error handling. (Patch 3)

- Fixed anonymous scope handling to ensure unnamed DIEs don't get names. (Patch 4)

- Added non-variant children to variant_type output, and included DW_AT_discr_value attributes for variants. (Patch 9)

- Added another symbol pointer test case. (Patch 16)

- Picked up (Acked|Reviewed)-by tags from v3.

v3: https://lore.kernel.org/lkml/[email protected]/
- Updated SPX license headers.

- Squashed the first two patches in v2 and tried to reduce churn as much as reasonable.

- Dropped patch 18 from v2 ("x86/asm-prototypes: Include <asm/ptrace.h>") as it's addressed by a separate patch.

- Changed the error handling code to immediately terminate instead of propagating the errors back to main, which cleaned up the code quite a bit.

- Switched to the list and hashtable implementations in scripts and dropped the remaining tools/include dependencies. Added a couple missing list macros. (patch 1)

- Moved the genksyms CRC32 implementation to scripts/include and dropped the duplicate code. (patches 2 and 14)

- Switched from ad-hoc command line parsing to getopt_long (patch 3).

- Added structure member and function parameter names to the DIE output to match genksyms behavior, and tweaked the symtypes format to be more parser-friendly in general based on Petr's suggestions.

- Replaced the declaration-only struct annotations with more generic kABI stability rules that allow source code annotations to be used where #ifndef __GENKSYMS__ was previously used. Added support for rules that can be used to exclude enumerators from versioning. (patch 16)

- Per Miroslav's suggestion, added an option to hide structure members from versioning when they're added to existing alignment holes, for example. (patch 16)

- Per Greg's request, added documentation and example macros for the --stable features, and a couple of test cases. (patches 15, 16, and
20)

- Fixed making symtypes files, which need to depend on .o files with gendwarfksyms. (patch 19)

- Addressed several other smaller issues that Petr and Masahiro kindly pointed out during the v2 review.

v2: https://lore.kernel.org/lkml/[email protected]/
- Per Luis' request, dropped Rust-specific patches and added gendwarfksyms as an alternative to genksyms for the entire
kernel.

- Added support for missing DWARF features needed to handle also non-Rust code.

- Changed symbol address matching to use the symbol table information instead of relying on addresses in DWARF.

- Added __gendwarfksyms_ptr patches to ensure the compiler emits the necessary type information in DWARF even for symbols that are defined in other TUs.

- Refactored debugging output and moved the more verbose output behind --dump* flags.

- Added a --symtypes flag for generating a genksyms-style symtypes output based on Petr's feedback, and refactored symbol version calculations to be based on symtypes instead of raw --dump-dies output.

- Based on feedback from Greg and Petr, added --stable flag and support for reserved data structure fields and declaration-onl structures. Also added examples for using these features.

- Added a GENDWARFKSYMS option and hooked up kbuild support for both C and assembly code. Note that with gendwarfksyms, we have to actually build a temporary .o file for calculating assembly modversions.

v1: https://lore.kernel.org/lkml/[email protected]/

---

Sami Tolvanen (18):
tools: Add gendwarfksyms
gendwarfksyms: Add address matching
gendwarfksyms: Expand base_type
gendwarfksyms: Add a cache for processed DIEs
gendwarfksyms: Expand type modifiers and typedefs
gendwarfksyms: Expand subroutine_type
gendwarfksyms: Expand array_type
gendwarfksyms: Expand structure types
gendwarfksyms: Limit structure expansion
gendwarfksyms: Add die_map debugging
gendwarfksyms: Add symtypes output
gendwarfksyms: Add symbol versioning
gendwarfksyms: Add support for kABI rules
gendwarfksyms: Add support for reserved and ignored fields
gendwarfksyms: Add support for symbol type pointers
export: Add __gendwarfksyms_ptr_ references to exported symbols
kbuild: Add gendwarfksyms as an alternative to genksyms Documentation/kbuild: Add DWARF module versioning

 Documentation/kbuild/gendwarfksyms.rst     |  308 ++++++
 Documentation/kbuild/index.rst             |    1 +
 MAINTAINERS                                |    7 +
 include/linux/export.h                     |   15 +
 kernel/module/Kconfig                      |   30 +
 scripts/Makefile                           |    3 +-
 scripts/Makefile.build                     |   35 +-
 scripts/gendwarfksyms/.gitignore           |    2 +
 scripts/gendwarfksyms/Makefile             |   12 +
 scripts/gendwarfksyms/cache.c              |   51 +
 scripts/gendwarfksyms/die.c                |  166 +++
 scripts/gendwarfksyms/dwarf.c              | 1159 ++++++++++++++++++++
 scripts/gendwarfksyms/examples/kabi.h      |  157 +++
 scripts/gendwarfksyms/examples/kabi_ex.c   |   30 +
 scripts/gendwarfksyms/examples/kabi_ex.h   |  263 +++++
 scripts/gendwarfksyms/examples/symbolptr.c |   33 +
 scripts/gendwarfksyms/gendwarfksyms.c      |  187 ++++
 scripts/gendwarfksyms/gendwarfksyms.h      |  296 +++++
 scripts/gendwarfksyms/kabi.c               |  336 ++++++
 scripts/gendwarfksyms/symbols.c            |  341 ++++++
 scripts/gendwarfksyms/types.c              |  481 ++++++++
 21 files changed, 3906 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/kbuild/gendwarfksyms.rst
 create mode 100644 scripts/gendwarfksyms/.gitignore
 create mode 100644 scripts/gendwarfksyms/Makefile
 create mode 100644 scripts/gendwarfksyms/cache.c
 create mode 100644 scripts/gendwarfksyms/die.c
 create mode 100644 scripts/gendwarfksyms/dwarf.c
 create mode 100644 scripts/gendwarfksyms/examples/kabi.h
 create mode 100644 scripts/gendwarfksyms/examples/kabi_ex.c
 create mode 100644 scripts/gendwarfksyms/examples/kabi_ex.h
 create mode 100644 scripts/gendwarfksyms/examples/symbolptr.c
 create mode 100644 scripts/gendwarfksyms/gendwarfksyms.c
 create mode 100644 scripts/gendwarfksyms/gendwarfksyms.h
 create mode 100644 scripts/gendwarfksyms/kabi.c
 create mode 100644 scripts/gendwarfksyms/symbols.c
 create mode 100644 scripts/gendwarfksyms/types.c

base-commit: fc033cf25e612e840e545f8d5ad2edd6ba613ed5

Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog