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

An option to adjust shared library mapped alignment? #577

Open
tesuji opened this issue Nov 27, 2024 · 0 comments
Open

An option to adjust shared library mapped alignment? #577

tesuji opened this issue Nov 27, 2024 · 0 comments

Comments

@tesuji
Copy link

tesuji commented Nov 27, 2024

Is your feature request related to a problem? Please describe.

The unmodified binary loads libc at 0x1000 boundary. However after patching with patchelf,
the map alignment of libc changed to 0x10_0000.

> ldd wall
        linux-vdso.so.1 (0x00007f548c69c000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f548c486000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f548c69e000)
> patchelf --set-interpreter ld-linux-x86-64.so.2 --set-rpath ./ wall
> ldd wall
        linux-vdso.so.1 (0x00007ff3cd78c000)
        libc.so.6 => lib/x86_64-linux-gnu/libc.so.6 (0x00007ff3cd400000)
        lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007ff3cd78e000)

Would you mind letting me know how to keep libc mapped alignment (not sure terminology) be the same as the old one?

Edit:
Running the same unmodified binary with ld.so --list --library-path,
libc also loaded at 0x10_000 alignment?

        linux-vdso.so.1 (0x00007f9654ce7000)
        libc.so.6 => ./lib/x86_64-linux-gnu/libc.so.6 (0x00007f9654a00000)
        /lib64/ld-linux-x86-64.so.2 => lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 (0x00007f9654ce9000)

Describe the solution you'd like

I don't know whether this is a problem with ld.so or patchelf.
I cannot tell.

Describe alternatives you've considered

N/A.

Additional context

wall.zip

Log of patchelf --debug

patching ELF file 'wall/wall'

replacing section '.interp' with size 42
this is an executable
using replaced section '.interp'
last replaced is 1
looking at section '.interp'
first reserved offset/addr is 0x338/0x400338
first page is 0x400000
needed space is 840
needed space is 896
needed pages is 2
clearing first 8168 bytes
rewriting section '.interp' from offset 0x318 (size 28) to offset 0x350 (size 42)
rewriting symbol table section 6
rewriting symbol table section 28
new rpath is 'lib/x86_64-linux-gnu/'
rpath is too long or shared, resizing...
DT_NULL index is 23
replacing section '.dynamic' with size 480
replacing section '.dynstr' with size 148
this is an executable
using replaced section '.dynstr'
using replaced section '.dynamic'
last replaced is 22
looking at section '.interp'
replacing section '.interp' which is in the way
looking at section '.note.gnu.property'
replacing section '.note.gnu.property' which is in the way
looking at section '.note.gnu.build-id'
replacing section '.note.gnu.build-id' which is in the way
looking at section '.note.ABI-tag'
replacing section '.note.ABI-tag' which is in the way
looking at section '.gnu.hash'
replacing section '.gnu.hash' which is in the way
looking at section '.dynsym'
replacing section '.dynsym' which is in the way
looking at section '.dynstr'
looking at section '.gnu.version'
first reserved offset/addr is 0x2536/0x400536
first page is 0x3fe000
needed space is 1968
clearing first 8622 bytes
rewriting section '.interp' from offset 0x350 (size 42) to offset 0x388 (size 42)
rewriting section '.note.gnu.property' from offset 0x2338 (size 48) to offset 0x3b8 (size 48)
rewriting section '.note.gnu.build-id' from offset 0x2368 (size 36) to offset 0x3e8 (size 36)
rewriting section '.note.ABI-tag' from offset 0x238c (size 32) to offset 0x410 (size 32)
rewriting section '.gnu.hash' from offset 0x23b0 (size 48) to offset 0x430 (size 48)
rewriting section '.dynsym' from offset 0x23e0 (size 216) to offset 0x460 (size 216)
rewriting section '.dynstr' from offset 0x24b8 (size 126) to offset 0x538 (size 148)
rewriting section '.dynamic' from offset 0x4e08 (size 464) to offset 0x5d0 (size 480)
rewriting symbol table section 6
rewriting symbol table section 28
writing wall/wall

@tesuji tesuji changed the title An option to adjust shared lib base address An option to adjust shared library mapped alignment? Nov 27, 2024
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

1 participant