llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.66k stars 11.85k forks source link

llvm-strip fails on the mongod binary #60790

Open 0xced opened 1 year ago

0xced commented 1 year ago

LLVM 15.0.7 installed with Homebrew:

llvm-strip, compatible with GNU strip
Homebrew LLVM version 15.0.7
  Optimized build.
  Default target: x86_64-apple-darwin19.6.0
  Host CPU: skylake

Reproduction steps:

curl https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-6.0.4.tgz | tar -zx
llvm-strip mongodb-macos-x86_64-6.0.4/bin/mongod

Crashes with the following stack trace:

Stack dump:
0.  Program arguments: llvm-strip mongodb-macos-x86_64-6.0.4/bin/mongod
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM.dylib            0x000000010b2e0e3d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43
1  libLLVM.dylib            0x000000010b2e1228 SignalHandler(int) + 168
2  libsystem_platform.dylib 0x00007fff70fda5fd _sigtramp + 29
3  libsystem_platform.dylib 0x00007f9cd0490018 _sigtramp + 18446743650106563128
4  libLLVM.dylib            0x000000010c3c8d9e llvm::objcopy::executeObjcopyOnBinary(llvm::objcopy::MultiFormatConfig const&, llvm::object::Binary&, llvm::raw_ostream&) + 286
5  llvm-strip               0x0000000105695d89 std::__1::__function::__func<executeObjcopy(llvm::objcopy::ConfigManager&)::$_2, std::__1::allocator<executeObjcopy(llvm::objcopy::ConfigManager&)::$_2>, llvm::Error (llvm::raw_ostream&)>::operator()(llvm::raw_ostream&) + 31
6  libLLVM.dylib            0x000000010b2c7a3a llvm::writeToOutput(llvm::StringRef, std::__1::function<llvm::Error (llvm::raw_ostream&)>) + 244
7  llvm-strip               0x00000001056948ec llvm_objcopy_main(int, char**) + 1740
8  libdyld.dylib            0x00007fff70de1cc9 start + 1
[1]    69970 segmentation fault  llvm-strip mongodb-macos-x86_64-6.0.4/bin/mongod
llvmbot commented 1 year ago

@llvm/issue-subscribers-tools-llvm-objcopy-strip

alexander-shaposhnikov commented 1 year ago

The input binary appears to be invalid:

$ llvm-readobj --macho-indirect-symbols mongodb-macos-x86_64-6.0.4/bin/mongod | tail -n 20
      Symbol Index: 0x4A7A5
    }
    Entry {
      Entry Index: 12348
      Symbol Index: 0x4A7A6
    }
    Entry {
      Entry Index: 12349
      Symbol Index: 0x10A1CF
    }
    Entry {
      Entry Index: 12350
      Symbol Index: 0x11C4B9
    }
    Entry {
      Entry Index: 12351
      Symbol Index: 0x11C62D
    }
  ]
}

At the same time:

$ nm mongodb-macos-x86_64-6.0.4/bin/mongod | wc -l
  305064

0x10A1CF = 1089999 > 305064

P.S. The tool shouldn't crash on invalid object files, but this is a quite old issue. In this particular case it's probably not hard to fix - patches are always welcome.

0xced commented 1 year ago

I'm not sure how much invalid this executable is but the strip tool that comes with the Xcode toolchain is able to strip it from 132 MB to 95 MB without any issues.

$ ls -ks mongod
132096 mongod
$ xcrun strip mongod
$ ls -ks mongod     
 95328 mongod

The executable still runs after being stripped.

$ ./mongod --version
db version v6.0.4
Build Info: {
    "version": "6.0.4",
    "gitVersion": "44ff59461c1353638a71e710f385a566bcd2f547",
    "modules": [],
    "allocator": "system",
    "environment": {
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

What do you mean by this is a quite old issue? Is there a duplicate issue that I failed to find?