Skip to content

Commit cf9d692

Browse files
samitolvanenmasahir0y
authored andcommitted
Documentation/kbuild: Add new gendwarfksyms kABI rules
Document the "byte_size" and "type_string" kABI stability rules. Signed-off-by: Sami Tolvanen <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 881bf90 commit cf9d692

File tree

1 file changed

+92
-5
lines changed

1 file changed

+92
-5
lines changed

Documentation/kbuild/gendwarfksyms.rst

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,17 @@ the rules. The fields are as follows:
125125
qualified name of the DWARF Debugging Information Entry (DIE).
126126
- `value`: Provides rule-specific data.
127127

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
129129
in the source code::
130130

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_, \
133133
__COUNTER__)[] __used __aligned(1) \
134134
__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)
136139

137140

138141
Currently, only the rules discussed in this section are supported, but
@@ -223,6 +226,87 @@ Example usage::
223226
KABI_ENUMERATOR_IGNORE(e, C);
224227
KABI_ENUMERATOR_VALUE(e, LAST, 2);
225228

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+
226310
Adding structure members
227311
------------------------
228312

@@ -276,6 +360,8 @@ The examples include `KABI_(RESERVE|USE|REPLACE)*` macros that help
276360
simplify the process and also ensure the replacement member is correctly
277361
aligned and its size won't exceed the reserved space.
278362

363+
.. _hiding_members:
364+
279365
Hiding members
280366
~~~~~~~~~~~~~~
281367

@@ -305,4 +391,5 @@ member to a union where one of the fields has a name starting with
305391
unsigned long b;
306392
};
307393

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

Comments
 (0)