Skip to content

Unable to run patchelf on some Ubuntu binaries #62

Closed

Description

@n3rdopolis

Namely on the dynamically linked qemu-user (non-static) binaries. I'm not sure how Ubuntu compiles them

With the newest version of patchelf compiled:
I try
./patchelf --set-interpreter /path/to/ld-linux.so.2 /path/to/qemu-arm
and get
warning: working around a Linux kernel bug by creating a hole of 33796096 bytes in ‘/path/to/qemu-arm’
maximum file size exceeded

I get the same error with --set-rpath as well on the same binary

Activity

  1. n3rdopolis commented on Aug 17, 2015

    @n3rdopolis
    Author

    I found that there is debug flag

    patching ELF file `/tmp/qemu_user_server/arm/qemu-user'
    Kernel page size is 4096 bytes
    new rpath is `/tmp/qemu_user_server/arm/'
    rpath is too long, resizing...
    DT_NULL index is 33
    replacing section `.dynamic' with size 312
    replacing section `.dynstr' with size 16703
    this is a dynamic library
    last page is 0x21d9000
    needed space is 17368
    warning: working around a Linux kernel bug by creating a hole of 33796096 bytes in ‘/tmp/qemu_user_server/arm/qemu-user’
    maximum file size exceeded
    
  2. DoomHammer commented on Oct 15, 2015

    @DoomHammer

    Had exactly the same issue, but worked around (this work around) by increasing the maxSize to 64 * 1024 * 1024 in patchelf.cc:245 which was just about right.

    The questions that arise are:

    1. @edolstra why is maxSize set to 32M (previously 64M)? Why not 512M or even 42G?
    2. @edolstra again: you mention Linux kernel bug in your commit message but don't exactly reference it. Has it been, perchance, already fixed and thus rendered the workaround unnecessary (for newer kernels)?
  3. n3rdopolis commented on Oct 17, 2015

    @n3rdopolis
    Author

    That workaround works, but it creates a huge 34 MB executable...

    I should post some readelf info
    readelf -d -e /usr/bin/qemu-i386
    ELF Header:
    Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
    Class: ELF32
    Data: 2's complement, little endian
    Version: 1 (current)
    OS/ABI: UNIX - System V
    ABI Version: 0
    Type: DYN (Shared object file)
    Machine: Intel 80386
    Version: 0x1
    Entry point address: 0x30f9c
    Start of program headers: 52 (bytes into file)
    Start of section headers: 1597220 (bytes into file)
    Flags: 0x0
    Size of this header: 52 (bytes)
    Size of program headers: 32 (bytes)
    Number of program headers: 10
    Size of section headers: 40 (bytes)
    Number of section headers: 29
    Section header string table index: 28

    Section Headers:
    [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
    [ 0] NULL 00000000 000000 000000 00 0 0 0
    [ 1] .interp PROGBITS 00000174 000174 000013 00 A 0 0 1
    [ 2] .note.ABI-tag NOTE 00000188 000188 000020 00 A 0 0 4
    [ 3] .note.gnu.build-i NOTE 000001a8 0001a8 000024 00 A 0 0 4
    [ 4] .gnu.hash GNU_HASH 000001cc 0001cc 004de0 04 A 5 0 4
    [ 5] .dynsym DYNSYM 00004fac 004fac 00b120 10 A 6 1 4
    [ 6] .dynstr STRTAB 000100cc 0100cc 00d40d 00 A 0 0 1
    [ 7] .gnu.version VERSYM 0001d4da 01d4da 001624 02 A 5 0 2
    [ 8] .gnu.version_r VERNEED 0001eb00 01eb00 000220 00 A 6 5 4
    [ 9] .rel.dyn REL 0001ed20 01ed20 00e938 08 A 5 0 4
    [10] .rel.plt REL 0002d658 02d658 000cb8 08 AI 5 12 4
    [11] .init PROGBITS 0002e310 02e310 000023 00 AX 0 0 4
    [12] .plt PROGBITS 0002e340 02e340 001980 04 AX 0 0 16
    [13] .text PROGBITS 0002fcc0 02fcc0 0cb2c4 00 AX 0 0 16
    [14] .fini PROGBITS 000faf84 0faf84 000014 00 AX 0 0 4
    [15] .rodata PROGBITS 000fafa0 0fafa0 019ecc 00 A 0 0 32
    [16] .eh_frame_hdr PROGBITS 00114e6c 114e6c 0065f4 00 A 0 0 4
    [17] .eh_frame PROGBITS 0011b460 11b460 04bd68 00 A 0 0 4
    [18] .tbss NOBITS 00168204 167204 000020 00 WAT 0 0 4
    [19] .init_array INIT_ARRAY 00168204 167204 000034 00 WA 0 0 4
    [20] .fini_array FINI_ARRAY 00168238 167238 000004 00 WA 0 0 4
    [21] .jcr PROGBITS 0016823c 16723c 000004 00 WA 0 0 4
    [22] .data.rel.ro PROGBITS 00168240 167240 017ce0 00 WA 0 0 32
    [23] .dynamic DYNAMIC 0017ff20 17ef20 000128 08 WA 6 0 4
    [24] .got PROGBITS 00180048 17f048 000fb8 04 WA 0 0 4
    [25] .data PROGBITS 00181000 180000 005de8 00 WA 0 0 32
    [26] .bss NOBITS 00186e00 185de8 2039470 00 WA 0 0 32
    [27] .gnu_debuglink PROGBITS 00000000 185de8 000034 00 0 0 1
    [28] .shstrtab STRTAB 00000000 185e1c 000106 00 0 0 1
    Key to Flags:
    W (write), A (alloc), X (execute), M (merge), S (strings)
    I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
    O (extra OS processing required) o (OS specific), p (processor specific)

    Program Headers:
    Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
    PHDR 0x000034 0x00000034 0x00000034 0x00140 0x00140 R E 0x4
    INTERP 0x000174 0x00000174 0x00000174 0x00013 0x00013 R 0x1
    [Requesting program interpreter: /lib/ld-linux.so.2]
    LOAD 0x000000 0x00000000 0x00000000 0x1671c8 0x1671c8 R E 0x1000
    LOAD 0x167204 0x00168204 0x00168204 0x1ebe4 0x205806c RW 0x1000
    DYNAMIC 0x17ef20 0x0017ff20 0x0017ff20 0x00128 0x00128 RW 0x4
    NOTE 0x000188 0x00000188 0x00000188 0x00044 0x00044 R 0x4
    TLS 0x167204 0x00168204 0x00168204 0x00000 0x00020 R 0x4
    GNU_EH_FRAME 0x114e6c 0x00114e6c 0x00114e6c 0x065f4 0x065f4 R 0x4
    GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10
    GNU_RELRO 0x167204 0x00168204 0x00168204 0x18dfc 0x18dfc R 0x1

    Section to Segment mapping:
    Segment Sections...
    00
    01 .interp
    02 .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame
    03 .init_array .fini_array .jcr .data.rel.ro .dynamic .got .data .bss
    04 .dynamic
    05 .note.ABI-tag .note.gnu.build-id
    06 .tbss
    07 .eh_frame_hdr
    08
    09 .init_array .fini_array .jcr .data.rel.ro .dynamic .got

    Dynamic section at offset 0x17ef20 contains 33 entries:
    Tag Type Name/Value
    0x00000001 (NEEDED) Shared library: [libgmodule-2.0.so.0]
    0x00000001 (NEEDED) Shared library: [libglib-2.0.so.0]
    0x00000001 (NEEDED) Shared library: [librt.so.1]
    0x00000001 (NEEDED) Shared library: [libm.so.6]
    0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
    0x00000001 (NEEDED) Shared library: [libpthread.so.0]
    0x00000001 (NEEDED) Shared library: [libc.so.6]
    0x0000000c (INIT) 0x2e310
    0x0000000d (FINI) 0xfaf84
    0x00000019 (INIT_ARRAY) 0x168204
    0x0000001b (INIT_ARRAYSZ) 52 (bytes)
    0x0000001a (FINI_ARRAY) 0x168238
    0x0000001c (FINI_ARRAYSZ) 4 (bytes)
    0x6ffffef5 (GNU_HASH) 0x1cc
    0x00000005 (STRTAB) 0x100cc
    0x00000006 (SYMTAB) 0x4fac
    0x0000000a (STRSZ) 54285 (bytes)
    0x0000000b (SYMENT) 16 (bytes)
    0x00000015 (DEBUG) 0x0
    0x00000003 (PLTGOT) 0x180048
    0x00000002 (PLTRELSZ) 3256 (bytes)
    0x00000014 (PLTREL) REL
    0x00000017 (JMPREL) 0x2d658
    0x00000011 (REL) 0x1ed20
    0x00000012 (RELSZ) 59704 (bytes)
    0x00000013 (RELENT) 8 (bytes)
    0x00000018 (BIND_NOW)
    0x6ffffffb (FLAGS_1) Flags: NOW
    0x6ffffffe (VERNEED) 0x1eb00
    0x6fffffff (VERNEEDNUM) 5
    0x6ffffff0 (VERSYM) 0x1d4da
    0x6ffffffa (RELCOUNT) 7438
    0x00000000 (NULL) 0x0
    ne

  4. tobiasBora commented on Oct 19, 2020

    @tobiasBora

    I'm having exactly the same issue here, on a file libcudnn_cnn_infer.so.8... Is it possible, at least, to increase the maximum file size on a per-built basis? In my case, I don't care to have a bigger file for this particular derivation, but I do want to be able to write a working derivation for the program :'(

    searching for dependencies of /nix/store/xc8glxqx4r6lvhm9yq3fjqvlcja5q17r-DaVinci_Resolve_16.2.7/libs/libcudnn_cnn_infer.so.8
      libcudnn_ops_infer.so.8 -> found: /nix/store/xc8glxqx4r6lvhm9yq3fjqvlcja5q17r-DaVinci_Resolve_16.2.7/libs/libcudnn_ops_infer.so.8
      libstdc++.so.6 -> found: /nix/store/danv012gh0aakh8xnk2b35vahklz72mk-gcc-9.2.0-lib/lib/../lib64/libstdc++.so.6
    setting RPATH to: /nix/store/xc8glxqx4r6lvhm9yq3fjqvlcja5q17r-DaVinci_Resolve_16.2.7/libs:/nix/store/danv012gh0aakh8xnk2b35vahklz72mk-gcc-9.2.0-lib/lib/../lib64
    maximum file size exceeded
    
  5. domenkozar commented on Sep 13, 2021

    @domenkozar
    Member

    Fixed on master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions