[PATCH] D118840: [ELF] Support (TYPE=<value>) to customize the output section type

Ard Biesheuvel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 18 01:14:19 PST 2022


ardb added a comment.

In D118840#3331178 <https://reviews.llvm.org/D118840#3331178>, @MaskRay wrote:

> In D118840#3331173 <https://reviews.llvm.org/D118840#3331173>, @nathanchance wrote:
>
>> I have not done a bisect but it seems likely that this change breaks linking modules for the arm64 Linux kernel, is this expected?
>>
>>   $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 mrproper defconfig all
>>   ...
>>   ld.lld: error: section type mismatch for .plt
>>   >>> <internal>:(.plt): SHT_PROGBITS
>>   >>> output section .plt: SHT_NOBITS
>>   ...
>>
>> I believe the `.plt` handling in the linker script comes from https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/include/asm/module.lds.h?h=v5.17-rc4.
>
> I do not know whether we want to remove the error for `NOLOAD`.
>
> `.plt 0 (NOLOAD) : { BYTE(0) }` looks questionable to me.
>
> Seems that it needs `/DISCARD/ : { *(.plt) }` if it just wants to leave a one-byte `.plt` but ignoring the regular `.plt`.
>
> Alternatively/preferably, drop `(NOLOAD)`. @ardb for kernel fd045f6cd98ec4953147b318418bd45e441e52a3
>
> edit: sent https://lore.kernel.org/linux-arm-kernel/20220218081209.354383-1-maskray@google.com/T/#u
> sent one for riscv as well.

These .plt sections have nothing to do with linker emitted PLTs, so perhaps the name should be improved.

These sections are instantiated by the module loader at runtime, but in order for the module loader to be able to create a section of arbitrary size, it needs to be present in the object file to begin with. This is why the dummy byte is inserted, as otherwise, the section is dropped.

The purpose of these sections is to carry veneers that may or may not be needed to fix up out-of-range direct branches from the module code into the kernel itself or other modules. Whether such veneers are necessary depends on the actual load address of the module. (Veneers are also emitted to work around the Cortex-A53 ADRP erratum #843419, if needed)

If the section name '.plt' is special in some way, I'd be happy to prepare a kernel patch that renames these into something more suitable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118840/new/

https://reviews.llvm.org/D118840



More information about the llvm-commits mailing list