module: use hidden visibility for weak symbol references
Subsystems (2)
PATCH 1/1 module: use hidden visibility for weak symbol references
Geert reports that commit be2881824ae9eb92 ("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that have CONFIG_MODULES disabled.
The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when CONFIG_RELOCATABLE is enabled, which is on by default).
What happens is that code such as
struct device *(*fn)(struct device *dev);
struct device *iommu_device;
fn = symbol_get(mdev_get_iommu_device);
if (fn) {
iommu_device = fn(dev);essentially gets converted into the following when CONFIG_MODULES is off:
struct device *iommu_device;
if (&mdev_get_iommu_device) {
iommu_device = mdev_get_iommu_device(dev);where mdev_get_iommu_device is emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields 0x0 if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by a R_AARCH64_CALL26 relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry.
Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via R_AARCH64_CALL26 can simply remain unsatisfied.
--- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/module.h +1 -1
@@ -740,7 +740,7 @@ static inline bool within_module(unsigned long addr, const struct module *mod) }/* Get/put a kernel symbol (calls should be symmetric) */ -#define symbol_get (x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) +#define symbol_get (x) ({ extern typeof(x) x __attribute__((weak,visibility("hidden"))); &(x); })#define symbol_put (x) do { } while (0)#define symbol_put_addr (x) do { } while (0)
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 42 lines · Ard Biesheuvel
Geert reports that commit
be2881824ae9eb92("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that haveCONFIG_MODULESdisabled.The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when
CONFIG_RELOCATABLEis enabled, which is on by default).What happens is that code such as
struct device *(*fn)(struct device *dev); struct device *iommu_device; fn = symbol_get(mdev_get_iommu_device); if (fn) { iommu_device = fn(dev);essentially gets converted into the following when
CONFIG_MODULESis off:struct device *iommu_device; if (&mdev_get_iommu_device) { iommu_device = mdev_get_iommu_device(dev);where
mdev_get_iommu_deviceis emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields0x0if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by aR_AARCH64_CALL26relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry.Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via
R_AARCH64_CALL26can simply remain unsatisfied.
Quoted 5 lines
Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>
Thanks, this get rids of
aarch64-linux-gnu-ld: Unexpected GOT/PLT entries detected!
aarch64-linux-gnu-ld: Unexpected run-time procedure linkages detected!
which you may want to mention in the patch description, to make it easier to be found.
Gr{oetje,eeting}s,
Geert
Signature · 10 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
+ Fangrui
Quoted 68 lines · Ard Biesheuvel
Geert reports that commit
be2881824ae9eb92("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that haveCONFIG_MODULESdisabled.The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when
CONFIG_RELOCATABLEis enabled, which is on by default).What happens is that code such as
struct device *(*fn)(struct device *dev); struct device *iommu_device; fn = symbol_get(mdev_get_iommu_device); if (fn) { iommu_device = fn(dev);essentially gets converted into the following when
CONFIG_MODULESis off:struct device *iommu_device; if (&mdev_get_iommu_device) { iommu_device = mdev_get_iommu_device(dev);where
mdev_get_iommu_deviceis emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields0x0if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by aR_AARCH64_CALL26relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry.Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via
R_AARCH64_CALL26can simply remain unsatisfied.Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>--- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/module.h +1
-2@@ -740,7 +740,7 @@ static inline bool within_module(unsigned long addr, const struct module *mod) }/* Get/put a kernel symbol (calls should be symmetric) */ -#define symbol_get (x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) +#define symbol_get (x) ({ extern typeof(x) x __attribute__((weak,visibility("hidden"))); &(x); })#define symbol_put (x) do { } while (0)#define symbol_put_addr (x) do { } while (0) --2.17.1
Signature · 2 lines
Thanks, ~Nick Desaulniers
Fangrui Song
Reviewed-byOne nit about ".got" in the message:
Quoted 10 lines · Nick Desaulniers
+ Fangrui
Quoted 7 lines · Ard Biesheuvel
Geert reports that commit
be2881824ae9eb92("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that haveCONFIG_MODULESdisabled.The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty,
.got -> .got.plt
be2881824ae9eb92 does not ASSERT on .got (it can).
Strangely *(.got) is placed in .text in arch/arm64/kernel/vmlinux.lds.S I think that line can be removed. On x86, aarch64 and many other archs, the start of .got.plt is the GOT base. .got is not needed (ppc/arm/riscv use .got instead of .got.plt as the GOT base anchor).
Quoted 6 lines
Quoted 6 lines
but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when
CONFIG_RELOCATABLEis enabled, which is on by default).
Confirmed.
Quoted 16 lines
Quoted 16 lines
What happens is that code such as
struct device *(*fn)(struct device *dev); struct device *iommu_device; fn = symbol_get(mdev_get_iommu_device); if (fn) { iommu_device = fn(dev);essentially gets converted into the following when
CONFIG_MODULESis off:struct device *iommu_device; if (&mdev_get_iommu_device) { iommu_device = mdev_get_iommu_device(dev);
Quoted 7 lines
Quoted 7 lines
where
mdev_get_iommu_deviceis emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields0x0if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by aR_AARCH64_CALL26relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry.
Yes, the R_AARCH64_CALL26 relocation referencing an undefined weak symbol causes one .plt entry and one .got.plt entry.
Quoted 35 lines
Quoted 30 lines
Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via
R_AARCH64_CALL26can simply remain unsatisfied.Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>--- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/module.h +1
-2@@ -740,7 +740,7 @@ static inline bool within_module(unsigned long addr, const struct module *mod) }/* Get/put a kernel symbol (calls should be symmetric) */ -#define symbol_get (x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) +#define symbol_get (x) ({ extern typeof(x) x __attribute__((weak,visibility("hidden"))); &(x); })#define symbol_put (x) do { } while (0)#define symbol_put_addr (x) do { } while (0) --2.17.1
Signature · 2 lines
Thanks, ~Nick Desaulniers
Will Deacon
maintainerHi Ard,
Quoted 42 lines · Ard Biesheuvel
Geert reports that commit
be2881824ae9eb92("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that haveCONFIG_MODULESdisabled.The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when
CONFIG_RELOCATABLEis enabled, which is on by default).What happens is that code such as
struct device *(*fn)(struct device *dev); struct device *iommu_device; fn = symbol_get(mdev_get_iommu_device); if (fn) { iommu_device = fn(dev);essentially gets converted into the following when
CONFIG_MODULESis off:struct device *iommu_device; if (&mdev_get_iommu_device) { iommu_device = mdev_get_iommu_device(dev);where
mdev_get_iommu_deviceis emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields0x0if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by aR_AARCH64_CALL26relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry.Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via
R_AARCH64_CALL26can simply remain unsatisfied.
Quoted 8 lines
Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>--- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Cheers. I gave this a spin, but I unfortunately still see the following linker warning with allnoconfig:
aarch64-linux-gnu-ld: warning: orphan section .igot.plt' from arch/arm64/kernel/head.o' being placed in section `.igot.plt'
which looks unrelated to symbol_get(), but maybe it's worth knocking these things on the head (no pun intended) at the same time?
Cheers,
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 55 lines · Will Deacon
Hi Ard,
Quoted 42 lines · Ard Biesheuvel
Geert reports that commit
be2881824ae9eb92("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that haveCONFIG_MODULESdisabled.The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when
CONFIG_RELOCATABLEis enabled, which is on by default).What happens is that code such as
struct device *(*fn)(struct device *dev); struct device *iommu_device; fn = symbol_get(mdev_get_iommu_device); if (fn) { iommu_device = fn(dev);essentially gets converted into the following when
CONFIG_MODULESis off:struct device *iommu_device; if (&mdev_get_iommu_device) { iommu_device = mdev_get_iommu_device(dev);where
mdev_get_iommu_deviceis emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields0x0if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by aR_AARCH64_CALL26relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry.Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via
R_AARCH64_CALL26can simply remain unsatisfied.Quoted 8 lines
Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>--- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 8 lines
Cheers. I gave this a spin, but I unfortunately still see the following linker warning with allnoconfig:
aarch64-linux-gnu-ld: warning: orphan section
.igot.plt' fromarch/arm64/kernel/head.o' being placed in section `.igot.plt'which looks unrelated to
symbol_get(), but maybe it's worth knocking these things on the head (no pun intended) at the same time?
Yeah, that is just one of those spurious sections that turns up empty anyway. The head.o is a red herring, it is simply the first file appearing in the link.
This should fix it
arch/arm64/kernel/vmlinux.lds.S +1 -1
@@ -278,7 +278,7 @@ SECTIONS * explicitly check instead of blindly discarding. */ .plt : { - *(.plt) *(.plt.*) *(.iplt) *(.igot) + *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) } ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure
linkages detected!")
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerQuoted 73 lines · Ard Biesheuvel
Quoted 52 lines · Will Deacon
Quoted 42 lines · Ard Biesheuvel
Geert reports that commit
be2881824ae9eb92("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that haveCONFIG_MODULESdisabled.The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when
CONFIG_RELOCATABLEis enabled, which is on by default).What happens is that code such as
struct device *(*fn)(struct device *dev); struct device *iommu_device; fn = symbol_get(mdev_get_iommu_device); if (fn) { iommu_device = fn(dev);essentially gets converted into the following when
CONFIG_MODULESis off:struct device *iommu_device; if (&mdev_get_iommu_device) { iommu_device = mdev_get_iommu_device(dev);where
mdev_get_iommu_deviceis emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields0x0if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by aR_AARCH64_CALL26relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry.Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via
R_AARCH64_CALL26can simply remain unsatisfied.Quoted 8 lines
Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>--- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 8 lines
Cheers. I gave this a spin, but I unfortunately still see the following linker warning with allnoconfig:
aarch64-linux-gnu-ld: warning: orphan section
.igot.plt' fromarch/arm64/kernel/head.o' being placed in section `.igot.plt'which looks unrelated to
symbol_get(), but maybe it's worth knocking these things on the head (no pun intended) at the same time?Yeah, that is just one of those spurious sections that turns up empty anyway. The head.o is a red herring, it is simply the first file appearing in the link.
This should fix it
arch/arm64/kernel/vmlinux.lds.S +0
-0
arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 284
Quoted 8 lines
arch/arm64/kernel/vmlinux.lds.S +1
-1@@ -278,7 +278,7 @@ SECTIONS * explicitly check instead of blindly discarding. */ .plt : { - *(.plt) *(.plt.*) *(.iplt) *(.igot) + *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) } ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
Cheers, that fixes the extra warning for me. If you could send a proper patch, I'm happy to queue as an arm64 fix! (I'm assuming the former is going via Jessica, but I can also take that with her Ack).
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Jessica Yu
Acked-by+++ Will Deacon [28/10/20 13:24 +0000]:
Quoted 78 lines · Ard Biesheuvel
Quoted 77 lines · Will Deacon
Quoted 52 lines · Ard Biesheuvel
Quoted 42 lines
Geert reports that commit
be2881824ae9eb92("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that haveCONFIG_MODULESdisabled.The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when
CONFIG_RELOCATABLEis enabled, which is on by default).What happens is that code such as
struct device *(*fn)(struct device *dev); struct device *iommu_device; fn = symbol_get(mdev_get_iommu_device); if (fn) { iommu_device = fn(dev);essentially gets converted into the following when
CONFIG_MODULESis off:struct device *iommu_device; if (&mdev_get_iommu_device) { iommu_device = mdev_get_iommu_device(dev);where
mdev_get_iommu_deviceis emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields0x0if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by aR_AARCH64_CALL26relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry.Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via
R_AARCH64_CALL26can simply remain unsatisfied.Quoted 8 lines
Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>--- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 8 lines
Cheers. I gave this a spin, but I unfortunately still see the following linker warning with allnoconfig:
aarch64-linux-gnu-ld: warning: orphan section
.igot.plt' fromarch/arm64/kernel/head.o' being placed in section `.igot.plt'which looks unrelated to
symbol_get(), but maybe it's worth knocking these things on the head (no pun intended) at the same time?Yeah, that is just one of those spurious sections that turns up empty anyway. The head.o is a red herring, it is simply the first file appearing in the link.
This should fix it
arch/arm64/kernel/vmlinux.lds.S +0
-1@@ -278,7 +278,7 @@ SECTIONS * explicitly check instead of blindly discarding. */ .plt : { - *(.plt) *(.plt.*) *(.iplt) *(.igot)
Quoted 8 lines
arch/arm64/kernel/vmlinux.lds.S SECTIONS
Quoted 4 lines
arch/arm64/kernel/vmlinux.lds.S +1
-0+ *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) } ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")Cheers, that fixes the extra warning for me. If you could send a proper patch, I'm happy to queue as an arm64 fix! (I'm assuming the former is going via Jessica, but I can also take that with her Ack).
Hi! Yes, please feel free to take this patch along with the other fix:
Thanks,
Jessica
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerQuoted 88 lines · Jessica Yu
+++ Will Deacon [28/10/20 13:24 +0000]:
Quoted 78 lines · Ard Biesheuvel
Quoted 77 lines · Will Deacon
Quoted 52 lines · Ard Biesheuvel
Quoted 42 lines
Geert reports that commit
be2881824ae9eb92("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that haveCONFIG_MODULESdisabled.The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when
CONFIG_RELOCATABLEis enabled, which is on by default).What happens is that code such as
struct device *(*fn)(struct device *dev); struct device *iommu_device; fn = symbol_get(mdev_get_iommu_device); if (fn) { iommu_device = fn(dev);essentially gets converted into the following when
CONFIG_MODULESis off:struct device *iommu_device; if (&mdev_get_iommu_device) { iommu_device = mdev_get_iommu_device(dev);where
mdev_get_iommu_deviceis emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields0x0if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by aR_AARCH64_CALL26relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry.Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via
R_AARCH64_CALL26can simply remain unsatisfied.Quoted 8 lines
Cc Jessica Yu <[email protected]>Cc Kees Cook <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>--- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 8 lines
Cheers. I gave this a spin, but I unfortunately still see the following linker warning with allnoconfig:
aarch64-linux-gnu-ld: warning: orphan section
.igot.plt' fromarch/arm64/kernel/head.o' being placed in section `.igot.plt'which looks unrelated to
symbol_get(), but maybe it's worth knocking these things on the head (no pun intended) at the same time?Yeah, that is just one of those spurious sections that turns up empty anyway. The head.o is a red herring, it is simply the first file appearing in the link.
This should fix it
arch/arm64/kernel/vmlinux.lds.S +0
-1@@ -278,7 +278,7 @@ SECTIONS * explicitly check instead of blindly discarding. */ .plt : { - *(.plt) *(.plt.*) *(.iplt) *(.igot)Quoted 8 lines
arch/arm64/kernel/vmlinux.lds.S SECTIONS
Quoted 4 lines
arch/arm64/kernel/vmlinux.lds.S +1
-0+ *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) } ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")Cheers, that fixes the extra warning for me. If you could send a proper patch, I'm happy to queue as an arm64 fix! (I'm assuming the former is going via Jessica, but I can also take that with her Ack).
Quoted 3 lines
Hi! Yes, please feel free to take this patch along with the other fix:
Acked-by Jessica Yu <[email protected]>
Cheers, Jessica -- I'll queue them in a sec!
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 13 lines · Ard Biesheuvel
Geert reports that commit
be2881824ae9eb92("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that haveCONFIG_MODULESdisabled.The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when
CONFIG_RELOCATABLEis enabled, which is on by default).
Quoted 1 line
[...]
Applied to arm64 (for-next/fixes), thanks!
[1/1] module: use hidden visibility for weak symbol references
https://git.kernel.org/arm64/c/13150bc5416f
Cheers,
Signature · 10 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel