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

unsupported overlap of SHT_NOTE and PT_NOTE with Rust ELF files #255

Closed
sjackman opened this issue Nov 24, 2020 · 18 comments
Closed

unsupported overlap of SHT_NOTE and PT_NOTE with Rust ELF files #255

sjackman opened this issue Nov 24, 2020 · 18 comments
Labels

Comments

@sjackman
Copy link

Describe the bug

Patching a Rust ELF file yields the error unsupported overlap of SHT_NOTE and PT_NOTE

Steps To Reproduce

Without Homebrew or Docker

$ curl -fsL https://linuxbrew.bintray.com/bottles/fd-8.1.1.x86_64_linux.bottle.tar.gz | tar x fd/8.1.1/bin/fd
$ patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 fd/8.1.1/bin/fd
patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections
$ patchelf --version
patchelf 0.12.20200827.8d3a16e

With Homebrew in Docker

$ docker run -it --rm homebrew/brew:2.5.9
$ export HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK=1
$ brew install fd

patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections
Error: Failure while executing; `/home/linuxbrew/.linuxbrew/bin/patchelf --set-interpreter /home/linuxbrew/.linuxbrew/lib/ld.so --force-rpath --set-rpath /home/linuxbrew/.linuxbrew/Cellar/fd/8.1.1/lib:/home/linuxbrew/.linuxbrew/lib /home/linuxbrew/.linuxbrew/Cellar/fd/8.1.1/bin/fd` exited with 1.
$ patchelf --version
patchelf 0.12.20200827.8d3a16e

Expected behavior

I expected the ELF file to be patched without error. It works with patchelf 0.11.

patchelf --version output

patchelf 0.12.20200827.8d3a16e

Additional context

These ELF files were originally created using patchelf 0.11. They are being patched a second time with patchelf 0.12.

@sjackman sjackman added the bug label Nov 24, 2020
@sjackman
Copy link
Author

sjackman commented Nov 24, 2020

This bug prevents Homebrew on Linux from using its binary bottles of Rust executables.
The downstream Homebrew bug report is https://github.com/Homebrew/linuxbrew-core/issues/21601.

@sjackman
Copy link
Author

@rmNULL @delroth @Mic92 @edolstra Any thoughts on this regression?

@Mic92
Copy link
Member

Mic92 commented Nov 24, 2020

git bisect might give a better idea when this regression was introduced. Also the output of readelf -a for the binary in question might be interesting.

@sjackman
Copy link
Author

@Mic92 I would suspect PR #225 Better support relocating NOTE sections/segments + tests!

@sjackman
Copy link
Author

$ curl -fsL https://linuxbrew.bintray.com/bottles/fd-8.1.1.x86_64_linux.bottle.tar.gz | tar x fd/8.1.1/bin/fd
$ readelf -hlSd fd/8.1.1/bin/fd
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x334c0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          3207328 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         13
  Size of section headers:           64 (bytes)
  Number of section headers:         40
  Section header string table index: 37

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .note.ABI-tag     NOTE             000000000000032c  0000032c
       0000000000000020  0000000000000000   A       0     0     4
  [ 2] .gnu.hash         GNU_HASH         0000000000000350  00000350
       00000000000001a4  0000000000000000   A       3     0     8
  [ 3] .dynsym           DYNSYM           00000000000004f8  000004f8
       0000000000000ee8  0000000000000018   A       4     1     8
  [ 4] .dynstr           STRTAB           00000000000013e0  000013e0
       00000000000009ad  0000000000000000   A       0     0     1
  [ 5] .gnu.version      VERSYM           0000000000001d8e  00001d8e
       000000000000013e  0000000000000002   A       3     0     2
  [ 6] .gnu.version_r    VERNEED          0000000000001ed0  00001ed0
       00000000000001d0  0000000000000000   A       4     7     8
  [ 7] .rela.dyn         RELA             00000000000020a0  000020a0
       000000000002fd30  0000000000000018   A       3     0     8
  [ 8] .rela.plt         RELA             0000000000031dd0  00031dd0
       0000000000000360  0000000000000018  AI       3    25     8
  [ 9] .init             PROGBITS         0000000000033000  00033000
       000000000000001a  0000000000000000  AX       0     0     4
  [10] .plt              PROGBITS         0000000000033020  00033020
       0000000000000250  0000000000000010  AX       0     0     16
  [11] .plt.got          PROGBITS         0000000000033270  00033270
       0000000000000108  0000000000000008  AX       0     0     8
  [12] .text             PROGBITS         0000000000033380  00033380
       00000000001e7650  0000000000000000  AX       0     0     16
  [13] .fini             PROGBITS         000000000021a9d0  0021a9d0
       0000000000000009  0000000000000000  AX       0     0     4
  [14] .rodata           PROGBITS         000000000021b000  0021b000
       0000000000055afd  0000000000000000   A       0     0     64
  [15] .eh_frame_hdr     PROGBITS         0000000000270b00  00270b00
       0000000000004f54  0000000000000000   A       0     0     4
  [16] .eh_frame         PROGBITS         0000000000275a58  00275a58
       0000000000022b08  0000000000000000   A       0     0     8
  [17] .gcc_except_table PROGBITS         0000000000298560  00298560
       000000000000b4ac  0000000000000000   A       0     0     4
  [18] .tdata            PROGBITS         00000000002a4fa0  002a3fa0
       0000000000001800  0000000000000000 WAT       0     0     32
  [19] .tbss             NOBITS           00000000002a67a0  002a57a0
       00000000000000d8  0000000000000000 WAT       0     0     32
  [20] .init_array       INIT_ARRAY       00000000002a67a0  002a57a0
       0000000000000018  0000000000000008  WA       0     0     8
  [21] .fini_array       FINI_ARRAY       00000000002a67b8  002a57b8
       0000000000000008  0000000000000008  WA       0     0     8
  [22] .jcr              PROGBITS         00000000002a67c0  002a57c0
       0000000000000008  0000000000000000  WA       0     0     8
  [23] .data.rel.ro      PROGBITS         00000000002a67e0  002a57e0
       0000000000025058  0000000000000000  WA       0     0     32
  [24] .dynamic          DYNAMIC          00000000002cb838  002ca838
       0000000000000260  0000000000000010  WA       4     0     8
  [25] .got              PROGBITS         00000000002cba98  002caa98
       0000000000000558  0000000000000008  WA       0     0     8
  [26] .data             PROGBITS         00000000002cc000  002cb000
       0000000000000231  0000000000000000  WA       0     0     32
  [27] .bss              NOBITS           00000000002cc240  002cb231
       000000000020f010  0000000000000000  WA       0     0     64
  [28] .comment          PROGBITS         0000000000000000  002cb231
       000000000000006a  0000000000000001  MS       0     0     1
  [29] .debug_aranges    PROGBITS         0000000000000000  002cb29b
       0000000000000030  0000000000000000           0     0     1
  [30] .debug_info       PROGBITS         0000000000000000  002cb2cb
       00000000000004e2  0000000000000000           0     0     1
  [31] .debug_abbrev     PROGBITS         0000000000000000  002cb7ad
       000000000000013a  0000000000000000           0     0     1
  [32] .debug_line       PROGBITS         0000000000000000  002cb8e7
       0000000000000100  0000000000000000           0     0     1
  [33] .debug_str        PROGBITS         0000000000000000  002cb9e7
       0000000000000381  0000000000000001  MS       0     0     1
  [34] .debug_loc        PROGBITS         0000000000000000  002cbd68
       0000000000000126  0000000000000000           0     0     1
  [35] .symtab           SYMTAB           0000000000000000  002cbe90
       00000000000162a8  0000000000000018          36   3529     8
  [36] .strtab           STRTAB           0000000000000000  002e2138
       000000000002cded  0000000000000000           0     0     1
  [37] .shstrtab         STRTAB           0000000000000000  0030ef25
       000000000000017a  0000000000000000           0     0     1
  [38] .interp           PROGBITS         0000000000310000  00310000
       000000000000001e  0000000000000000   A       0     0     8
  [39] .note.gnu.bu[...] NOTE             0000000000310020  00310020
       0000000000000024  0000000000000000   A       0     0     8
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  l (large), p (processor specific)

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040
                 0x00000000000002d8 0x00000000000002d8  R      0x8
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000032130 0x0000000000032130  R      0x1000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x10
  NOTE           0x0000000000000308 0x0000000000000308 0x0000000000000308
                 0x0000000000000044 0x0000000000000044  R      0x4
  LOAD           0x0000000000033000 0x0000000000033000 0x0000000000033000
                 0x00000000001e79d9 0x00000000001e79d9  R E    0x1000
  LOAD           0x000000000021b000 0x000000000021b000 0x000000000021b000
                 0x0000000000088a0c 0x0000000000088a0c  R      0x1000
  GNU_EH_FRAME   0x0000000000270b00 0x0000000000270b00 0x0000000000270b00
                 0x0000000000004f54 0x0000000000004f54  R      0x4
  LOAD           0x00000000002a3fa0 0x00000000002a4fa0 0x00000000002a4fa0
                 0x0000000000027291 0x00000000002362b0  RW     0x1000
  TLS            0x00000000002a3fa0 0x00000000002a4fa0 0x00000000002a4fa0
                 0x0000000000001800 0x00000000000018d8  R      0x20
  GNU_RELRO      0x00000000002a3fa0 0x00000000002a4fa0 0x00000000002a4fa0
                 0x0000000000027060 0x0000000000027060  R      0x1
  DYNAMIC        0x00000000002ca838 0x00000000002cb838 0x00000000002cb838
                 0x0000000000000260 0x0000000000000260  RW     0x8
  INTERP         0x0000000000310000 0x0000000000310000 0x0000000000310000
                 0x000000000000001e 0x000000000000001e  R      0x1
      [Requesting program interpreter: @@HOMEBREW_PREFIX@@/lib/ld.so]
  LOAD           0x0000000000310000 0x0000000000310000 0x0000000000310000
                 0x0000000000000048 0x0000000000000048  RW     0x1000

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

Dynamic section at offset 0x2ca838 contains 34 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x000000000000000f (RPATH)              Library rpath: [@@HOMEBREW_PREFIX@@/Cellar/fd/8.1.1/lib:@@HOMEBREW_PREFIX@@/lib]
 0x000000000000000c (INIT)               0x33000
 0x000000000000000d (FINI)               0x21a9d0
 0x0000000000000019 (INIT_ARRAY)         0x2a67a0
 0x000000000000001b (INIT_ARRAYSZ)       24 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x2a67b8
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x350
 0x0000000000000005 (STRTAB)             0x13e0
 0x0000000000000006 (SYMTAB)             0x4f8
 0x000000000000000a (STRSZ)              2477 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x2cba98
 0x0000000000000002 (PLTRELSZ)           864 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x31dd0
 0x0000000000000007 (RELA)               0x20a0
 0x0000000000000008 (RELASZ)             195888 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x0000000000000018 (BIND_NOW)           
 0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE
 0x000000006ffffffe (VERNEED)            0x1ed0
 0x000000006fffffff (VERNEEDNUM)         7
 0x000000006ffffff0 (VERSYM)             0x1d8e
 0x000000006ffffff9 (RELACOUNT)          8042
 0x0000000000000000 (NULL)               0x0

@Mic92
Copy link
Member

Mic92 commented Nov 26, 2020

Ok. I don't know about NOTE section yet well enough. You might be able to revert this commit however for us it fixed patching mesa drivers in NixOS, so there are cases where it fixes runtime crashes. So in longterm it might be better to understand the actual bug happening here.

@florianjacob
Copy link

I get a conforming error when building pkgs.tsm-client, a C/Java (to the best of my knowledge) IBM tape backup client: NixOS/nixpkgs#106257

Not sure if this is the same root issue like with the rust ELFs or separate… 🤔

@domenkozar
Copy link
Member

See #230

@domenkozar
Copy link
Member

@sjackman could you try master branch?

@domenkozar
Copy link
Member

Nevermind, still errors out.

@haampie
Copy link
Contributor

haampie commented Apr 17, 2021

I'm hitting this issue when using patchelf 0.12 on libexpat

@rpurdie
Copy link
Contributor

rpurdie commented May 1, 2021

I ran into this issue in the Yocto Project. I think I found a fix to my issue which looked like an alignment issue: #274

@rpurdie
Copy link
Contributor

rpurdie commented May 2, 2021

#274 had an issue but replaced it with #275 which fixed that problem.

@haampie
Copy link
Contributor

haampie commented May 2, 2021

@rpurdie your issue was not solved on master already?

@rpurdie
Copy link
Contributor

rpurdie commented May 2, 2021

@rpurdie your issue was not solved on master already?

No, master wouldn't work on this binary where the note section alignment was different for different note sections.

@dragon512
Copy link

Just want to add I am seeing this issue with c++ binaries built with the intel icc/icpc compiler as well.

@domenkozar
Copy link
Member

Could you try v0.13?

@r-burns
Copy link

r-burns commented Aug 28, 2021

Encountered this issue causing nixpkgs#kythe to fail (https://hydra.nixos.org/build/126755389), bisected to the patchelf 0.11 -> 0.12 bump (NixOS/nixpkgs@f38ed04). Can confirm that v0.13 fixes the issue.

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

No branches or pull requests

8 participants