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

[llvm-ranlib] crash when called on emscripten .a file produced by GHC's new JS backend #60949

Open
sternenseemann opened this issue Feb 23, 2023 · 6 comments
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] tools:llvm-ar/llvm-ranlib

Comments

@sternenseemann
Copy link
Contributor

sternenseemann commented Feb 23, 2023

When compiling just about any Haskell library using GHC's new JS backend which involves creating an ar file, llvm-ranlib is called (via Emscripten's emranlib), triggering the following crash:

LLVM ERROR: malformed uleb128, extends past end
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /nix/store/b4z1yykly634q6ric5d3w6162slxzrbf-emscripten-llvm-3.1.24/bin/llvm-ranlib test.a
 #0 0x00007f808df7afe4 PrintStackTraceSignalHandler(void*) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0xeaefe4)
 #1 0x00007f808df7866b SignalHandler(int) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0xeac66b)
 #2 0x00007f808cbe0bf0 __restore_rt (/nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libc.so.6+0x3dbf0)
 #3 0x00007f808cc2dbc7 __pthread_kill_implementation (/nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libc.so.6+0x8abc7)
 #4 0x00007f808cbe0b46 gsignal (/nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libc.so.6+0x3db46)
 #5 0x00007f808cbcb4b5 abort (/nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libc.so.6+0x284b5)
 #6 0x00007f808de80314 llvm::report_fatal_error(llvm::Twine const&, bool) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0xdb4314)
 #7 0x00007f808de8046a (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0xdb446a)
 #8 0x00007f808fc1ffd1 readULEB128(llvm::object::WasmObjectFile::ReadContext&) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0x2b53fd1)
 #9 0x00007f808fc2efd7 llvm::object::WasmObjectFile::WasmObjectFile(llvm::MemoryBufferRef, llvm::Error&) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0x2b62fd7)
#10 0x00007f808fc2f442 llvm::object::ObjectFile::createWasmObjectFile(llvm::MemoryBufferRef) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0x2b63442)
#11 0x00007f808fc13fbe llvm::object::ObjectFile::createObjectFile(llvm::MemoryBufferRef, llvm::file_magic, bool) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0x2b47fbe)
#12 0x00007f808fc17879 llvm::object::SymbolicFile::createSymbolicFile(llvm::MemoryBufferRef, llvm::file_magic, llvm::LLVMContext*, bool) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0x2b4b879)
#13 0x00007f808fb79066 llvm::writeArchiveToStream(llvm::raw_ostream&, llvm::ArrayRef<llvm::NewArchiveMember>, bool, llvm::object::Archive::Kind, bool, bool) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0x2aad066)
#14 0x00007f808fb7b29f llvm::writeArchive(llvm::StringRef, llvm::ArrayRef<llvm::NewArchiveMember>, bool, llvm::object::Archive::Kind, bool, bool, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >) (/nix/store/338k2wvhmwgkw3ipqd8f9rrym4sg1ipj-llvm-14.0.6-lib/lib/libLLVM-14.so+0x2aaf29f)
#15 0x000000000040c1bc performWriteOperation(ArchiveOperation, llvm::object::Archive*, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, std::vector<llvm::NewArchiveMember, std::allocator<llvm::NewArchiveMember> >*) (/nix/store/b4z1yykly634q6ric5d3w6162slxzrbf-emscripten-llvm-3.1.24/bin/llvm-ranlib+0x40c1bc)
#16 0x000000000040e96d performOperation(ArchiveOperation, llvm::object::Archive*, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, std::vector<llvm::NewArchiveMember, std::allocator<llvm::NewArchiveMember> >*) (/nix/store/b4z1yykly634q6ric5d3w6162slxzrbf-emscripten-llvm-3.1.24/bin/llvm-ranlib+0x40e96d)
#17 0x000000000040eb13 performOperation(ArchiveOperation, std::vector<llvm::NewArchiveMember, std::allocator<llvm::NewArchiveMember> >*) (/nix/store/b4z1yykly634q6ric5d3w6162slxzrbf-emscripten-llvm-3.1.24/bin/llvm-ranlib+0x40eb13)
#18 0x0000000000406a5c main (/nix/store/b4z1yykly634q6ric5d3w6162slxzrbf-emscripten-llvm-3.1.24/bin/llvm-ranlib+0x406a5c)
#19 0x00007f808cbcc24e __libc_start_call_main (/nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libc.so.6+0x2924e)
#20 0x00007f808cbcc309 __libc_start_main@GLIBC_2.2.5 (/nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libc.so.6+0x29309)
#21 0x0000000000407d75 _start (/nix/store/b4z1yykly634q6ric5d3w6162slxzrbf-emscripten-llvm-3.1.24/bin/llvm-ranlib+0x407d75)

emranlib is just a wrapper around llvm-ranlib that transparently passes through all arguments to llvm-ranlib. /nix/store/b4z1yykly634q6ric5d3w6162slxzrbf-emscripten-llvm-3.1.24/bin/llvm-ranlib is just a symlink to normal llvm-ranlib 14.0.6:

> realpath /nix/store/b4z1yykly634q6ric5d3w6162slxzrbf-emscripten-llvm-3.1.24/bin/llvm-ranlib
/nix/store/p8wpdbr2m12ydclalh33sf8mlygxgh11-llvm-14.0.6/bin/llvm-ar
> /nix/store/b4z1yykly634q6ric5d3w6162slxzrbf-emscripten-llvm-3.1.24/bin/llvm-ranlib --version
LLVM (http://llvm.org/):
  LLVM version 14.0.6
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: skylake

It should be easy to reproduce the crash by running on llvm-ranlib on the archive file produced by GHC (had to upload externally due to GitHub's file size limit) by just executing llvm-ranlib repro-ranlib-crash.a.

llvm-ranlib comes from nixpkgs, of course.

Reproducing this using just GHC
  1. You need to build GHC as a cross-compiler for javascript-unknown-ghcjs (for older revisions js-unknown-ghcjs) – using LLVM 14.0.6 of course. Build instructions are available upstream. I used GHC revision a203ad854ffee802e6bf0aca26e6c9a99bec3865.
    If you want to use Nix, you can checkout e23efa222d1d7af7fa4380a392afd359f9e5116c of my nixpkgs fork and build nix-build -A pkgsCross.ghcjs.buildPackages.haskell.compiler.ghcHEAD.
  2. Create the following Test.hs:
    module Test (test) where
     
    test x = x + 41
  3. Run javascript-unknown-ghcjs-ghc -outputdir build/ -v -o repro-ranlib-crash.a --make -staticlib Test.hs. You should see the crash already.
  4. You can reproduce the crash again by running llvm-ranlib repro-ranlib-crash.a.

Reproducible with:

@EugeneZelenko EugeneZelenko added tools:llvm-ar/llvm-ranlib crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Feb 23, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2023

@llvm/issue-subscribers-tools-llvm-ar-llvm-ranlib

@EugeneZelenko
Copy link
Contributor

Could you please try 16 or main branch?

@sternenseemann
Copy link
Contributor Author

The same crash happens with llvm-ranlib built from 85dbb3f.

@sternenseemann sternenseemann changed the title 14.0.6 llvm-ranlib: crash when called on emscripten .a file produced by GHC's new JS backend [llvm-ranlib] crash when called on emscripten .a file produced by GHC's new JS backend Feb 24, 2023
@sternenseemann
Copy link
Contributor Author

GHC ticket

@voidus
Copy link

voidus commented Apr 25, 2023

Another repro nix build 'github:nixos/nixpkgs?rev=6c43a3495a11e261e5f41e5d7eda2d71dae1b2fe#legacyPackages.x86_64-linux.pkgsCross.ghcjs.haskell.packages.ghc96.hashable'

@danwdart
Copy link

danwdart commented Aug 1, 2023

This is just because libraries can't be compiled by js backend yet without them being executables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] tools:llvm-ar/llvm-ranlib
Projects
None yet
Development

No branches or pull requests

5 participants