bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/28858] New: Some relative relocations are missing when linking w


From: dani at danielbertalan dot dev
Subject: [Bug ld/28858] New: Some relative relocations are missing when linking with -z pack-relative-relocs
Date: Thu, 03 Feb 2022 16:01:13 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=28858

            Bug ID: 28858
           Summary: Some relative relocations are missing when linking
                    with -z pack-relative-relocs
           Product: binutils
           Version: 2.38
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: dani at danielbertalan dot dev
  Target Milestone: ---

I'm working on adding RELR relocation support to an x86_64 kernel (we have
dynamic relocations in the kernel because of UBSAN and vtables). While it boots
correctly when I use the LLD linker with --pack-dyn-relocs=relr, the kernel
immediately triple faults when I link it with ld's pack-relative-relocs option.
The issue seems to be that we're trying to read from an address that needs to
be relocated but has not been.

Without pack-relative-relocs, the kernel binary has 6012 R_X86_64_RELATIVE
relocations:

$ LD=path/to/ld.bfd ./good.sh
$ llvm-readelf --relocs good
    Relocation section '.rela.dyn' at offset 0x44b3f0 contains 6012 entries:
    00000000007b0000  0000000000000008 R_X86_64_RELATIVE                 74a020
    00000000007b0008  0000000000000008 R_X86_64_RELATIVE                 431990
    00000000007b0010  0000000000000008 R_X86_64_RELATIVE                 47c380
    ...

When I enable pack-relative-relocs, the total number of relocations stays the
same, but instead of the expected R_X86_64_RELATIVE, the entries in .rela.dyn
contain R_X86_64_NONE. This might explain the un-relocated address I was
seeing.

$ LD=path/to/ld.bfd ./bad.sh
$ llvm-readelf --relocs bad
    Relocation section '.rela.dyn' at offset 0x44b3c0 contains 895 entries:
    0000000000000000  0000000000000000 R_X86_64_NONE                     0
    0000000000000000  0000000000000000 R_X86_64_NONE                     0
    0000000000000000  0000000000000000 R_X86_64_NONE                     0
    0000000000000000  0000000000000000 R_X86_64_NONE                     0
    ...

    Relocation section '.relr.dyn' at offset 0x4507a8 contains 5117 entries:
    00000000007b0000  0000000000000008 R_X86_64_RELATIVE
    00000000007b0008  0000000000000008 R_X86_64_RELATIVE
    ....

The attached tarball contains all inputs to the linker and the command line
arguments. I'm using ld.bfd built from commit
2405fc4016feadea33cb747d5654514f62b74ff4 (2.38.50.20220129).

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]