Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for MIPS binaries #180

Merged
merged 2 commits into from
Aug 11, 2021
Merged

Fixes for MIPS binaries #180

merged 2 commits into from
Aug 11, 2021

Commits on Aug 11, 2021

  1. Adjust DT_MIPS_RLD_MAP_REL dynamic section entry if present

    `patchelf --set-rpath` corrupted executables on mips32el: the dynamic
    liker crushed with Segmentation fault when loading any executable with
    RPATH added that way.
    
    The problem was around the MIPS-specific mechanism of setting up the
    debug map pointer. When DT_MIPS_RLD_MAP_REL entry in the dynamic section
    is present, it holds the relative address of __RLD_MAP -- an offset
    relative to this dynamic section entry. Dynamic linker puts the
    pointer to the `r_debug` structure there.
    
    When patchelf updates the executable RPATH, it moves the .dynamic
    section both in the binary and in memory, while __RLD_MAP is not moved
    in memory, since it belongs to special .rld_map section that has type
    PROGBITS. So, the offset stored in DT_MIPS_RLD_MAP_REL entry is not
    valid anymore and should be updated.
    
    This commit adds the necessary update.
    
    In the corner case when DT_MIPS_RLD_MAP_REL is present, but
    .rld_map section is not, the dynamic loader writes the debug
    pointer to some arbitrary bytes in memory. To avoid crushes
    on otherwise "working" binaries, we set offset to zero
    so that the dynamic loader would just overwrite the dynamic
    section.
    
    Here we also import DT_MIPS_RLD_MAP_REL definition in elf.h form
    glibc commit a2057c984e4314c3740f04cf54e36c824e4c8f32.
    
    Refs: NixOS#82
    Signed-off-by: Ivan A. Melnikov <[email protected]>
    iv-m committed Aug 11, 2021
    Configuration menu
    Copy the full SHA
    b240bb8 View commit details
    Browse the repository at this point in the history
  2. Adjust PT_MIPS_ABIFLAGS segment if present

    When loading the executable on MIPS, the dynamic loader looks for MIPS
    ABI flags using PT_MIPS_ABIFLAGS header. The flags themselves are stored
    in the .MIPS.abiflags section, so the header must be updated when the
    section is moved.
    
    Here we also import PT_MIPS_ABIFLAGS definition from glibc commit
    0bd956720c457ff054325b48f26ac7c91cb060e8.
    
    Closes: NixOS#82
    Signed-off-by: Ivan A. Melnikov <[email protected]>
    iv-m committed Aug 11, 2021
    Configuration menu
    Copy the full SHA
    bf73d6e View commit details
    Browse the repository at this point in the history