2
2
DWARF module versioning
3
3
=======================
4
4
5
- 1. Introduction
6
- ===============
5
+ Introduction
6
+ ============
7
7
8
8
When CONFIG_MODVERSIONS is enabled, symbol versions for modules
9
9
are typically calculated from preprocessed source code using the
@@ -14,8 +14,8 @@ selected, **gendwarfksyms** is used instead to calculate symbol versions
14
14
from the DWARF debugging information, which contains the necessary
15
15
details about the final module ABI.
16
16
17
- 1.1. Usage
18
- ==========
17
+ Usage
18
+ -----
19
19
20
20
gendwarfksyms accepts a list of object files on the command line, and a
21
21
list of symbol names (one per line) in standard input::
@@ -33,8 +33,8 @@ list of symbol names (one per line) in standard input::
33
33
-h, --help Print this message
34
34
35
35
36
- 2. Type information availability
37
- ================================
36
+ Type information availability
37
+ =============================
38
38
39
39
While symbols are typically exported in the same translation unit (TU)
40
40
where they're defined, it's also perfectly fine for a TU to export
@@ -56,8 +56,8 @@ type for calculating symbol versions even if the symbol is defined
56
56
elsewhere. The name of the symbol pointer is expected to start with
57
57
`__gendwarfksyms_ptr_ `, followed by the name of the exported symbol.
58
58
59
- 3. Symtypes output format
60
- =========================
59
+ Symtypes output format
60
+ ======================
61
61
62
62
Similarly to genksyms, gendwarfksyms supports writing a symtypes
63
63
file for each processed object that contain types for exported
@@ -85,8 +85,8 @@ produces C-style type strings, gendwarfksyms uses the same simple parsed
85
85
DWARF format produced by **--dump-dies **, but with type references
86
86
instead of fully expanded strings.
87
87
88
- 4. Maintaining a stable kABI
89
- ============================
88
+ Maintaining a stable kABI
89
+ =========================
90
90
91
91
Distribution maintainers often need the ability to make ABI compatible
92
92
changes to kernel data structures due to LTS updates or backports. Using
@@ -104,8 +104,8 @@ for source code annotation. Note that as these features are only used to
104
104
transform the inputs for symbol versioning, the user is responsible for
105
105
ensuring that their changes actually won't break the ABI.
106
106
107
- 4.1. kABI rules
108
- ===============
107
+ kABI rules
108
+ ----------
109
109
110
110
kABI rules allow distributions to fine-tune certain parts
111
111
of gendwarfksyms output and thus control how symbol
@@ -125,22 +125,25 @@ the rules. The fields are as follows:
125
125
qualified name of the DWARF Debugging Information Entry (DIE).
126
126
- `value `: Provides rule-specific data.
127
127
128
- The following helper macro , for example, can be used to specify rules
128
+ The following helper macros , for example, can be used to specify rules
129
129
in the source code::
130
130
131
- #define __KABI_RULE (hint, target, value) \
132
- static const char __PASTE(__gendwarfksyms_rule_, \
131
+ #define ___KABI_RULE (hint, target, value) \
132
+ static const char __PASTE(__gendwarfksyms_rule_, \
133
133
__COUNTER__)[] __used __aligned(1) \
134
134
__section(".discard.gendwarfksyms.kabi_rules") = \
135
- "1\0" #hint "\0" #target "\0" #value
135
+ "1\0" #hint "\0" target "\0" value
136
+
137
+ #define __KABI_RULE(hint, target, value) \
138
+ ___KABI_RULE(hint, #target, #value)
136
139
137
140
138
141
Currently, only the rules discussed in this section are supported, but
139
142
the format is extensible enough to allow further rules to be added as
140
143
need arises.
141
144
142
- 4.1.1. Managing definition visibility
143
- =====================================
145
+ Managing definition visibility
146
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144
147
145
148
A declaration can change into a full definition when additional includes
146
149
are pulled into the translation unit. This changes the versions of any
@@ -168,8 +171,8 @@ Example usage::
168
171
169
172
KABI_DECLONLY(s);
170
173
171
- 4.1.2. Adding enumerators
172
- =========================
174
+ Adding enumerators
175
+ ~~~~~~~~~~~~~~~~~~
173
176
174
177
For enums, all enumerators and their values are included in calculating
175
178
symbol versions, which becomes a problem if we later need to add more
@@ -223,8 +226,89 @@ Example usage::
223
226
KABI_ENUMERATOR_IGNORE(e, C);
224
227
KABI_ENUMERATOR_VALUE(e, LAST, 2);
225
228
226
- 4.3. Adding structure members
227
- =============================
229
+ Managing structure size changes
230
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231
+
232
+ A data structure can be partially opaque to modules if its allocation is
233
+ handled by the core kernel, and modules only need to access some of its
234
+ members. In this situation, it's possible to append new members to the
235
+ structure without breaking the ABI, as long as the layout for the original
236
+ members remains unchanged.
237
+
238
+ To append new members, we can hide them from symbol versioning as
239
+ described in section :ref: `Hiding members <hiding_members >`, but we can't
240
+ hide the increase in structure size. The `byte_size ` rule allows us to
241
+ override the structure size used for symbol versioning.
242
+
243
+ The rule fields are expected to be as follows:
244
+
245
+ - `type `: "byte_size"
246
+ - `target `: The fully qualified name of the target data structure
247
+ (as shown in **--dump-dies ** output).
248
+ - `value `: A positive decimal number indicating the structure size
249
+ in bytes.
250
+
251
+ Using the `__KABI_RULE ` macro, this rule can be defined as::
252
+
253
+ #define KABI_BYTE_SIZE(fqn, value) \
254
+ __KABI_RULE(byte_size, fqn, value)
255
+
256
+ Example usage::
257
+
258
+ struct s {
259
+ /* Unchanged original members */
260
+ unsigned long a;
261
+ void *p;
262
+
263
+ /* Appended new members */
264
+ KABI_IGNORE(0, unsigned long n);
265
+ };
266
+
267
+ KABI_BYTE_SIZE(s, 16);
268
+
269
+ Overriding type strings
270
+ ~~~~~~~~~~~~~~~~~~~~~~~
271
+
272
+ In rare situations where distributions must make significant changes to
273
+ otherwise opaque data structures that have inadvertently been included
274
+ in the published ABI, keeping symbol versions stable using the more
275
+ targeted kABI rules can become tedious. The `type_string ` rule allows us
276
+ to override the full type string for a type or a symbol, and even add
277
+ types for versioning that no longer exist in the kernel.
278
+
279
+ The rule fields are expected to be as follows:
280
+
281
+ - `type `: "type_string"
282
+ - `target `: The fully qualified name of the target data structure
283
+ (as shown in **--dump-dies ** output) or symbol.
284
+ - `value `: A valid type string (as shown in **--symtypes **) output)
285
+ to use instead of the real type.
286
+
287
+ Using the `__KABI_RULE ` macro, this rule can be defined as::
288
+
289
+ #define KABI_TYPE_STRING(type, str) \
290
+ ___KABI_RULE("type_string", type, str)
291
+
292
+ Example usage::
293
+
294
+ /* Override type for a structure */
295
+ KABI_TYPE_STRING("s#s",
296
+ "structure_type s { "
297
+ "member base_type int byte_size(4) "
298
+ "encoding(5) n "
299
+ "data_member_location(0) "
300
+ "} byte_size(8)");
301
+
302
+ /* Override type for a symbol */
303
+ KABI_TYPE_STRING("my_symbol", "variable s#s");
304
+
305
+ The `type_string ` rule should be used only as a last resort if maintaining
306
+ a stable symbol versions cannot be reasonably achieved using other
307
+ means. Overriding a type string increases the risk of actual ABI breakages
308
+ going unnoticed as it hides all changes to the type.
309
+
310
+ Adding structure members
311
+ ------------------------
228
312
229
313
Perhaps the most common ABI compatible change is adding a member to a
230
314
kernel data structure. When changes to a structure are anticipated,
@@ -237,8 +321,8 @@ natural method. This section describes gendwarfksyms support for using
237
321
reserved space in data structures and hiding members that don't change
238
322
the ABI when calculating symbol versions.
239
323
240
- 4.3.1. Reserving space and replacing members
241
- ============================================
324
+ Reserving space and replacing members
325
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
242
326
243
327
Space is typically reserved for later use by appending integer types, or
244
328
arrays, to the end of the data structure, but any type can be used. Each
@@ -276,8 +360,10 @@ The examples include `KABI_(RESERVE|USE|REPLACE)*` macros that help
276
360
simplify the process and also ensure the replacement member is correctly
277
361
aligned and its size won't exceed the reserved space.
278
362
279
- 4.3.2. Hiding members
280
- =====================
363
+ .. _hiding_members :
364
+
365
+ Hiding members
366
+ ~~~~~~~~~~~~~~
281
367
282
368
Predicting which structures will require changes during the support
283
369
timeframe isn't always possible, in which case one might have to resort
@@ -305,4 +391,5 @@ member to a union where one of the fields has a name starting with
305
391
unsigned long b;
306
392
};
307
393
308
- With **--stable **, both versions produce the same symbol version.
394
+ With **--stable **, both versions produce the same symbol version. The
395
+ examples include a `KABI_IGNORE ` macro to simplify the code.
0 commit comments