Closed xry111 closed 1 week ago
The BFD source code is much more difficult to understand than GCC or LLVM...
Absolutely!
The PowerPC64 implementation may be useful: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=1657026ccd8aa05a97cb35f1d9bff646937a244e
There are a few follow-up commits to remove redundant R_PPC64_NONE
.
It seems we are too different from PPC or x86...
Is there some doc for BFD analogous to GCC Internal? "info bfd" seems too outdated.
AArch64 implementation https://sourceware.org/pipermail/binutils/2024-May/134368.html can be a reference and its commit message explains some BFD mess.
A very simple PoC has been linked successfully, but still not ready for review:
Relocation section '.relr.dyn' at offset 0x190 contains 2 entries which relocate 3 locations:
Index: Entry Address Symbolic Address
0000: 0000000000008018 0000000000008018 p
0001: 0000000000000007 0000000000008020 p + 0x8
0000000000008028 p + 0x10
Now libc.so is linked successfully:
Relocation section '.relr.dyn' at offset 0x206a8 contains 31 entries which relocate 958 locations:
Index: Entry Address Symbolic Address
0000: 00000000001a94b0 00000000001a94b0 .tdata
0001: b23c00000fefc0dd 00000000001a94c0 .tbss
00000000001a94c8 .tbss + 0x8
00000000001a94d0 .tbss + 0x10
00000000001a94e0 __dso_handle
00000000001a94e8 _nl_C_LC_ADDRESS
00000000001a9520 _nl_C_LC_ADDRESS + 0x38
00000000001a9528 _nl_C_LC_ADDRESS + 0x40
00000000001a9530 _nl_C_LC_ADDRESS + 0x48
00000000001a9538 _nl_C_LC_ADDRESS + 0x50
00000000001a9540 _nl_C_LC_ADDRESS + 0x58
... ...
and Glibc test suite passes. But there are 8 R_LARCH_NONE
in it, indicating some over-allocation...
Oops the binutils trunk is already generating R_LARCH_NONE even without my changes.
A modified Linux kernel boots fine with CONFIG_RELR=y
. But there are some unpacked R_LARCH_RELATIVE
against the .la.abs
section of vmlinux. Need some investigation...
BTW there are many R_LARCH_NONE
in vmlinux with Binutils-2.42. Not sure why. IIRC this is also happening with RISC-V vmlinux.
A modified Linux kernel boots fine with
CONFIG_RELR=y
. But there are some unpackedR_LARCH_RELATIVE
against the.la.abs
section of vmlinux. Need some investigation...
By adding .align 8
into the .la.abs
section these relative relocs are packed.
Background: https://maskray.me/blog/2021-10-31-relative-relocations-and-relr
I've tried to implement this for LoongArch but the attempt miserably failed. The BFD source code is much more difficult to understand than GCC or LLVM...