Skip to content

Commit abcb1e0

Browse files
nickdesaulniersJonathan Corbet
authored andcommitted
Documentation: x86: exception-tables: document CONFIG_BUILDTIME_TABLE_SORT
Provide more information about __ex_table sorting post link. The exception tables and fixup tables use a commonly recurring pattern in the kernel of storing the address of labels as date in custom ELF sections, then finding these sections, iterating elements within them, and possibly revisiting them or modifying the data at these addresses. Sorting readonly arrays to minimize runtime penalties is quite clever. Suggested-by: H. Peter Anvin <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Corbet <[email protected]>
1 parent 19e91e5 commit abcb1e0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Documentation/x86/exception-tables.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ the fault, in our case the actual value is c0199ff5:
257257
the original assembly code: > 3: movl $-14,%eax
258258
and linked in vmlinux : > c0199ff5 <.fixup+10b5> movl $0xfffffff2,%eax
259259

260+
If the fixup was able to handle the exception, control flow may be returned
261+
to the instruction after the one that triggered the fault, ie. local label 2b.
262+
260263
The assembly code::
261264

262265
> .section __ex_table,"a"
@@ -344,3 +347,14 @@ pointer which points to one of:
344347
it as special.
345348

346349
More functions can easily be added.
350+
351+
CONFIG_BUILDTIME_TABLE_SORT allows the __ex_table section to be sorted post
352+
link of the kernel image, via a host utility scripts/sorttable. It will set the
353+
symbol main_extable_sort_needed to 0, avoiding sorting the __ex_table section
354+
at boot time. With the exception table sorted, at runtime when an exception
355+
occurs we can quickly lookup the __ex_table entry via binary search.
356+
357+
This is not just a boot time optimization, some architectures require this
358+
table to be sorted in order to handle exceptions relatively early in the boot
359+
process. For example, i386 makes use of this form of exception handling before
360+
paging support is even enabled!

0 commit comments

Comments
 (0)