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

Support for .relr.dyn #1058

Open
junghee opened this issue May 15, 2024 · 2 comments
Open

Support for .relr.dyn #1058

junghee opened this issue May 15, 2024 · 2 comments
Assignees

Comments

@junghee
Copy link
Contributor

junghee commented May 15, 2024

Describe the bug
The latest version of LIEF doesn't seem to support .relr.dyn (an array of relocation entries that encode relative relocations that do not require explicit addends or other information), which seems to be a relatively new feature that enables to reduce file sizes.

To Reproduce
librt.so.1.zip

Expected behavior
The readelf on ubuntu22 shows:

Relocation section '.relr.dyn' at offset 0x890 contains 3 entries:
   3 offsets
0000000000003d78
0000000000003d80
0000000000004010

The addresses are the entries in .init_array and fini_array, and the first entry of the section .data, respectively.

The LIEF version 0.14.1 fails to provide relocation information for those entries.

Environment (please complete the following information):

  • System and Version : Ubuntu 20.04
  • Target format: ELF
  • LIEF commit version: 0.14.1-bae887e0

Additional context
https://maskray.me/blog/2021-10-31-relative-relocations-and-relr

@TheDauntless
Copy link

TheDauntless commented May 15, 2024

Edit: Looks like my issue is #626


I think I'm struggling with the same issue. On the attached binaries, lief gives the correct output for an x86 version, while giving empty values for x64 / arm64 versions:
libs.zip

import lief

# Load the binary
binary = lief.parse("libnativestaticinit.so")

init_array =  binary.get_section(".init_array")
print(init_array.content.tobytes()) 
print("Virtual address", init_array.virtual_address)
init_array = binary.get_content_from_virtual_address(
        init_array.virtual_address, 
        init_array.size
    )
print(init_array.tobytes())
> python3 run.py
b'\x00\x00\x00\x00\x00\x00\x00\x00'
Virtual address 6904
b'\x00\x00\x00\x00\x00\x00\x00\x00'
Relocation section '.rela.dyn' at offset 0x550 contains 4 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000001b10  000000000403 R_AARCH64_RELATIV                    1b10
000000001b18  000000000403 R_AARCH64_RELATIV                    894
000000001b20  000000000403 R_AARCH64_RELATIV                    87c
000000001b28  000000000403 R_AARCH64_RELATIV                    8dc

The last item (0x8dc) should be the first entry of INIT_ARRAY.

@romainthomas
Copy link
Member

@junghee .relr.dyn relocations are not in the 0.14.x release but they are implemented in the main branch.

@TheDauntless LIEF is not applying any relocation in the binary so even if the relocation are supported, you will still observe the 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants