mold icon indicating copy to clipboard operation
mold copied to clipboard

mold run fails on x86_64 when mold-wrapper.so is in lib64

Open satmandu opened this issue 3 years ago • 3 comments

Tried building current ccache on x86_64:

Dir.chdir 'build' do
      system "env CFLAGS="-O2 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto" CXXFLAGS="-O2 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto" FCFLAGS="-O2 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto" FFLAGS="-O2 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto" LDFLAGS="-flto " \
      cmake -G Ninja \
      -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_LIBRARY_PATH=/usr/local/lib64 -DCMAKE_C_FLAGS='-O2 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto' -DCMAKE_CXX_FLAGS='-O2 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto' -DCMAKE_EXE_LINKER_FLAGS='-flto ' -DCMAKE_SHARED_LINKER_FLAGS='-flto ' -DCMAKE_STATIC_LINKER_FLAGS='-flto ' -DCMAKE_MODULE_LINKER_FLAGS='-flto ' -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=TRUE -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_SYSCONFDIR=/usr/local/etc \
      -DZSTD_FROM_INTERNET=ON \
      -DHIREDIS_FROM_INTERNET=ON \
      .."
      system 'mold -run ninja'
    end

This is the message I get though:

-- Build files have been written to: /usr/local/tmp/crew/ccache.20220907210753.dir/ccache-4.6.3/build
mold: fatal: mold-wrapper.so is missing

I think this is because mold-wrapper is in the lib64 folder on this system:

crew files mold
Ignoring debug-1.4.0 because its extensions are not built. Try: gem pristine debug --version 1.4.0
mold: A Modern Linker
/usr/local/bin/ld64.mold
/usr/local/bin/ld.mold
/usr/local/bin/mold
/usr/local/lib64/mold/mold-wrapper.so
/usr/local/libexec/mold/ld
/usr/local/share/doc/mold/LICENSE
/usr/local/share/man/man1/ld.mold.1.gz
/usr/local/share/man/man1/mold.1.gz
Total found: 8

(I don't have any issues on armv7l or i686, where mold wrapper is in /usr/local/lib )

satmandu avatar Sep 07 '22 21:09 satmandu

This fixes the issue:

mkdir -p /usr/local/lib/mold
cp -l /usr/local/lib64/mold/mold-wrapper.so /usr/local/lib/mold/

satmandu avatar Sep 07 '22 21:09 satmandu

The simplest solution would be for mold-wrapper.so to be always installed in lib/mold/ - I guess that should just require a tweak to the cmake installs...

satmandu avatar Sep 08 '22 14:09 satmandu

The issue appears to be here: https://github.com/rui314/mold/blob/9fd831365738b58c4e5d5b3593aedc940941315b/elf/subprocess.cc#L65

#ifdef LIBDIR
  // If not found, search $(LIBDIR)/mold, which is /usr/local/lib/mold
  // by default.
  path = LIBDIR "/mold/mold-wrapper.so";
  if (std::filesystem::is_regular_file(path, ec) && !ec)
    return path;
#endif

  // Look for ../lib/mold/mold-wrapper.so
  path = self.parent_path() / "../lib/mold/mold-wrapper.so";
  if (std::filesystem::is_regular_file(path, ec) && !ec)
    return path;

  Fatal(ctx) << "mold-wrapper.so is missing";

When built using cmake, and LIBDIR = /usr/local/lib64, path = LIBDIR "/mold/mold-wrapper.so" appears to never get checked.

satmandu avatar Sep 13 '22 15:09 satmandu

Thank you for your report! I believe the above commit should fix the issue.

rui314 avatar Sep 14 '22 06:09 rui314