]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
modules: Ensure 64-bit alignment on __ksymtab_* sections
authorHelge Deller <deller@gmx.de>
Wed, 22 Nov 2023 22:18:12 +0000 (23:18 +0100)
committerLuis Chamberlain <mcgrof@kernel.org>
Sat, 19 Oct 2024 20:35:24 +0000 (13:35 -0700)
On 64-bit architectures without CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
(e.g. ppc64, ppc64le, parisc, s390x,...) the __KSYM_REF() macro stores
64-bit pointers into the __ksymtab* sections.
Make sure that those sections will be correctly aligned at module link time,
otherwise unaligned memory accesses may happen at runtime.

As per unaligned-memory-access [0] "unaligned memory accesses [...]
will not work correctly on certain platforms and will cause performance
problems on others", so fix this.

The __kcrctab* sections store 32-bit entities, so use ALIGN(4) for those.

Signed-off-by: Helge Deller <deller@gmx.de>
[mcgrof: added unaligned-memory-access justification]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/core-api/unaligned-memory-access.rst
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
scripts/module.lds.S

index 3f43edef813cb9b5f2f1514dae7a7325ed8cbda3..23f9912179ceee909a3143d05aba0c30362a8ac9 100644 (file)
@@ -18,10 +18,10 @@ SECTIONS {
                *(.export_symbol)
        }
 
-       __ksymtab               0 : { *(SORT(___ksymtab+*)) }
-       __ksymtab_gpl           0 : { *(SORT(___ksymtab_gpl+*)) }
-       __kcrctab               0 : { *(SORT(___kcrctab+*)) }
-       __kcrctab_gpl           0 : { *(SORT(___kcrctab_gpl+*)) }
+       __ksymtab               0 : ALIGN(8) { *(SORT(___ksymtab+*)) }
+       __ksymtab_gpl           0 : ALIGN(8) { *(SORT(___ksymtab_gpl+*)) }
+       __kcrctab               0 : ALIGN(4) { *(SORT(___kcrctab+*)) }
+       __kcrctab_gpl           0 : ALIGN(4) { *(SORT(___kcrctab_gpl+*)) }
 
        .ctors                  0 : ALIGN(8) { *(SORT(.ctors.*)) *(.ctors) }
        .init_array             0 : ALIGN(8) { *(SORT(.init_array.*)) *(.init_array) }