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

Call to --add-needed fails on .dbg files #580

Open
GGG-KILLER opened this issue Dec 5, 2024 · 0 comments
Open

Call to --add-needed fails on .dbg files #580

GGG-KILLER opened this issue Dec 5, 2024 · 0 comments
Labels

Comments

@GGG-KILLER
Copy link

GGG-KILLER commented Dec 5, 2024

Describe the bug

An assertion is hit on a call to --add-needed on a .dbg file.

The file has no .interp section so I assume that might be related (or not).

Steps To Reproduce

  1. Download the binary either from nuget (https://azfunc.pkgs.visualstudio.com/e6a70c92-4128-439f-8012-382fe78d6396/_packaging/eb652719-f36a-4e78-8541-e13a3cd655f9/nuget/v3/flat2/microsoft.azure.functions.dotnetisolatednativehost/1.0.11/microsoft.azure.functions.dotnetisolatednativehost.1.0.11.nupkg) and unzip it, or get only the failing .dbg file from my mirror (https://dl.ggg.dev/FunctionsNetHost.dbg).
  2. Attempt to patchelf the file to --add-needed libicui18n.so --add-needed libicuuc.so --add-needed libz.so --add-needed libssl.so (full command: /nix/store/0bm0ay014jqqa818pqpp6rcd6a91jjc5-patchelf-0.18.0-unstable-2024-06-15/bin/patchelf --add-needed libicui18n.so --add-needed libicuuc.so --add-needed libz.so --add-needed libssl.so microsoft.azure.functions.dotnetisolatednativehost/1.0.11/contentFiles/any/any/workers/dotnet-isolated/bin/FunctionsNetHost.dbg).
  3. Failed assertion: patchelf: patchelf.cc:1095: void setSubstr(std::string&, unsigned int, const std::string&): Assertion `pos + t.size() <= s.size()' failed.

Expected behavior

A more descriptive error should be added and, hopefully, a way to detect when we can actually patchelf a file to add a dependency to it without needing to resort to parsing the ELF on the caller side.

patchelf --version output

patchelf 0.18.0

Additional context

This actually originated from NixOS/nixpkgs#361077 as in the dotnet infra, we patch binaries in NuGet packages used in buildDotnetModule so that they use the correct interpreter, have the required .NET dependencies that are dynamically loaded and more.

The file is accompanied by an actual binary called FunctionsNetHost, and they both only differ through their Type and lack of interpreter name on the .dbg file:

$ nix-shell -p binutils --run 'readelf --file-header contentFiles/any/any/workers/dotnet-isolated/bin/FunctionsNetHost.dbg'
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:               0x161c0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          34132072 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         12
  Size of section headers:           64 (bytes)
  Number of section headers:         49
  Section header string table index: 48
readelf: Error: Unable to find program interpreter name
$ nix-shell -p binutils --run 'readelf --file-header contentFiles/any/any/workers/dotnet-isolated/bin/FunctionsNetHost'    
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 (Position-Independent Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x161c0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          12158360 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         12
  Size of section headers:           64 (bytes)
  Number of section headers:         37
  Section header string table index: 36
@GGG-KILLER GGG-KILLER added the bug label Dec 5, 2024
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

1 participant