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

2.0.9 build hits "unexpected relocation type" in llvm #12934

Closed
rsielken opened this issue Dec 1, 2020 · 9 comments
Closed

2.0.9 build hits "unexpected relocation type" in llvm #12934

rsielken opened this issue Dec 1, 2020 · 9 comments

Comments

@rsielken
Copy link

rsielken commented Dec 1, 2020

We are currently building and running cleanly on 2.0.3. I am testing out 2.0.9 to see if we can move up to that version. The first part of that is making sure we can build and right now we cannot:

em++ -DEMSDK -DMOBILE -DOPENGL -DNO_DYNAMIC_LOADING -DNO_EM -g2 -s USE_PTHREADS=1 -s PROXY_TO_PTHREAD=1 -s PTHREAD_POOL_SIZE=8 -s FETCH=1 -s FETCH_SUPPORT_INDEXEDDB=0 -s FULL_ES2=1 -s USE_SDL=2 -s USE_SDL_TTF=2 -s USE_FREETYPE=2 -s USE_LIBPNG=1 -s DISABLE_EXCEPTION_CATCHING=0 -s INITIAL_MEMORY=268435456 -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s OFFSCREEN_FRAMEBUFFER=1 -s DEMANGLE_SUPPORT=1 -s ABORT_ON_WASM_EXCEPTIONS=1  -m32 -march=pentium3 -DGCC3 -DGCC4 -fno-strict-aliasing -DGCC_LBLB_NOT_SUPPORTED  -shared -fPIC   -Wl,--whole-archive -o /vhome/builder/sandboxes/notes/bin/wasm/bin/libnoteswasm.a  `build %1 @lib.libnoteswasm.wasm.tmp -d -s -t` -L/vhome/builder/sandboxes/notes/bin/wasm/bin -lcrypto -Wl,--no-whole-archive -L/system/lib -L/usr/local/lib -L/usr/lib -ldl -lrt -lm -L/vhome/builder/sandboxes/notes/bin/wasm/bin -lstdc++
Iris Macro Substitution Utility Version 2.02
Copyright (c) Iris Associates, Inc., 1984-2001.  All rights reserved.

em++: warning: linking a library with `-shared` will emit a static object file.  This is a form of emulation to support existing build systems.  If you want to build a runtime shared library use the SIDE_MODULE setting. [-Wemcc]
em++: warning: USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
em++: warning: ignoring dynamic library libcrypto.so because not compiling to JS or HTML, remember to link it when compiling to JS or HTML at the end [-Wemcc]
em++: warning: ignoring dynamic library libstdc++.so because not compiling to JS or HTML, remember to link it when compiling to JS or HTML at the end [-Wemcc]
unexpected relocation type
UNREACHABLE executed at /b/s/w/ir/cache/builder/emscripten-releases/llvm-project/lld/wasm/InputFiles.cpp:131!
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /local/emsdk/upstream/bin/wasm-ld -o /vhome/builder/sandboxes/notes/bin/wasm/bin/libnoteswasm.a --whole-archive -L/local/emsdk/upstream/emscripten/system/local/lib /vhome/builder/sandboxes/notes/bin/wasm/lib/nem.wasm.a -L/local/emsdk/upstream/emscripten/system/lib /vhome/builder/sandboxes/notes/bin/wasm/lib/mcmdtbls.wasm.o -L/local/emsdk/upstream/emscripten/cache/wasm /vhome/builder/sandboxes/notes/bin/wasm/lib/nem_wasm.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/desk.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/mailer.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/wmisc.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/view.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/actions.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/actpane.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/xmlcommon.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/lside.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/lsxui.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/wksrep.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/designui.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ltssp30.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ltssm30.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/edit.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/assist.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/xmlproc.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/schui.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/bkmkui.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/dxlo.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/irtf.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/xrtf2.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/igif.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/hooks.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ibmp.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ijpeg.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ipcx.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/istrings.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/itiff.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/itext.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ihtml.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/xical.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/dxli2.wasm.a -L/vhome/builder/sandboxes/notes/bin/wasm/bin --no-whole-archive -L/system/lib -L/usr/local/lib -L/usr/lib -L/vhome/builder/sandboxes/notes/bin/wasm/bin --relocatable -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr 
 #0 0x00007fbecf562dd3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/emsdk/upstream/bin/../lib/libLLVM-12git.so+0x86bdd3)
 #1 0x00007fbecf560b2e llvm::sys::RunSignalHandlers() (/local/emsdk/upstream/bin/../lib/libLLVM-12git.so+0x869b2e)
 #2 0x00007fbecf563295 SignalHandler(int) (/local/emsdk/upstream/bin/../lib/libLLVM-12git.so+0x86c295)
 #3 0x00007fbed2e003c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007fbece9e118b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618b)
 #5 0x00007fbece9c0859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859)
 #6 0x00007fbecf4ad511 (/local/emsdk/upstream/bin/../lib/libLLVM-12git.so+0x7b6511)
 #7 0x000000000079292d lld::wasm::ObjFile::calcNewAddend(llvm::wasm::WasmRelocation const&) const (/local/emsdk/upstream/bin/wasm-ld+0x79292d)
 #8 0x000000000078fed9 lld::wasm::InputChunk::writeRelocations(llvm::raw_ostream&) const (/local/emsdk/upstream/bin/wasm-ld+0x78fed9)
 #9 0x00000000007c2c6c lld::wasm::CodeSection::writeRelocations(llvm::raw_ostream&) const (/local/emsdk/upstream/bin/wasm-ld+0x7c2c6c)
#10 0x00000000007ca099 lld::wasm::RelocSection::writeBody() (/local/emsdk/upstream/bin/wasm-ld+0x7ca099)
#11 0x00000000007b691a lld::wasm::SyntheticSection::finalizeContents() (/local/emsdk/upstream/bin/wasm-ld+0x7b691a)
#12 0x00000000007b0778 lld::wasm::(anonymous namespace)::Writer::run() (/local/emsdk/upstream/bin/wasm-ld+0x7b0778)
#13 0x00000000007a8941 lld::wasm::writeResult() (/local/emsdk/upstream/bin/wasm-ld+0x7a8941)
#14 0x000000000078b362 lld::wasm::(anonymous namespace)::LinkerDriver::link(llvm::ArrayRef<char const*>) (/local/emsdk/upstream/bin/wasm-ld+0x78b362)
#15 0x0000000000784b53 lld::wasm::link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&, llvm::raw_ostream&) (/local/emsdk/upstream/bin/wasm-ld+0x784b53)
#16 0x000000000048ac1d lldMain(int, char const**, llvm::raw_ostream&, llvm::raw_ostream&, bool) (/local/emsdk/upstream/bin/wasm-ld+0x48ac1d)
#17 0x000000000048a740 main (/local/emsdk/upstream/bin/wasm-ld+0x48a740)
#18 0x00007fbece9c20b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#19 0x000000000048a41a _start (/local/emsdk/upstream/bin/wasm-ld+0x48a41a)
em++: error: '/local/emsdk/upstream/bin/wasm-ld -o /vhome/builder/sandboxes/notes/bin/wasm/bin/libnoteswasm.a --whole-archive -L/local/emsdk/upstream/emscripten/system/local/lib /vhome/builder/sandboxes/notes/bin/wasm/lib/nem.wasm.a -L/local/emsdk/upstream/emscripten/system/lib /vhome/builder/sandboxes/notes/bin/wasm/lib/mcmdtbls.wasm.o -L/local/emsdk/upstream/emscripten/cache/wasm /vhome/builder/sandboxes/notes/bin/wasm/lib/nem_wasm.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/desk.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/mailer.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/wmisc.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/view.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/actions.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/actpane.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/xmlcommon.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/lside.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/lsxui.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/wksrep.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/designui.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ltssp30.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ltssm30.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/edit.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/assist.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/xmlproc.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/schui.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/bkmkui.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/dxlo.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/irtf.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/xrtf2.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/igif.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/hooks.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ibmp.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ijpeg.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ipcx.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/istrings.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/itiff.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/itext.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/ihtml.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/xical.wasm.a /vhome/builder/sandboxes/notes/bin/wasm/lib/dxli2.wasm.a -L/vhome/builder/sandboxes/notes/bin/wasm/bin --no-whole-archive -L/system/lib -L/usr/local/lib -L/usr/lib -L/vhome/builder/sandboxes/notes/bin/wasm/bin --relocatable -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr' failed (-6)

I went through this exercise once before with 2.0.5 and we built cleanly but then had runtime errors, so we decided to stay on 2.0.3 and see what would happen with a later update.

Is this something that has changed and needs to be addressed in the emscripten code or do I need to truly file a bug report with https://bugs.llvm.org/ directly?

@sbc100
Copy link
Collaborator

sbc100 commented Dec 1, 2020

Its a shame that error doesn't tel use what the unexpected relocation type is.

Even though this is technically and upstream bug we can deal with it here I think since its a wasm-ld issue and I'm the maintainer of that. Is there any chance you attach a zip file containing a repro code (i.e. all the input files and shell script to try to link them (preferable directly with wasm-ld .. see the line that starts with 0. Program arguments: /local/emsdk/upstream/bin/wasm-ld ...)

On a side note are you sure you want to be using -shared here.. since emscirpten doesn't support shared libraries in the normal sense it advisable not use this flag but instead to use static library (.a archives).

@rsielken
Copy link
Author

rsielken commented Dec 1, 2020

I stripped down the number of .a files included down to two, put everything in a single directory, and created test.sh to perform the step that was crashing.

builder@Sandbox:~/12934$ ./test.sh 

https://github.com/emscripten-core/emscripten/issues/12934

unexpected relocation type
UNREACHABLE executed at /b/s/w/ir/cache/builder/emscripten-releases/llvm-project/lld/wasm/InputFiles.cpp:131!
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /local/emsdk/upstream/bin/wasm-ld -o libnoteswasm.a --whole-archive nem.wasm.a nem_wasm.wasm.a --no-whole-archive --relocatable -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr 
 #0 0x00007f56c20b4dd3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/emsdk/upstream/bin/../lib/libLLVM-12git.so+0x86bdd3)
 #1 0x00007f56c20b2b2e llvm::sys::RunSignalHandlers() (/local/emsdk/upstream/bin/../lib/libLLVM-12git.so+0x869b2e)
 #2 0x00007f56c20b5295 SignalHandler(int) (/local/emsdk/upstream/bin/../lib/libLLVM-12git.so+0x86c295)
 #3 0x00007f56c59523c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007f56c153318b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618b)
 #5 0x00007f56c1512859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859)
 #6 0x00007f56c1fff511 (/local/emsdk/upstream/bin/../lib/libLLVM-12git.so+0x7b6511)
 #7 0x000000000079292d lld::wasm::ObjFile::calcNewAddend(llvm::wasm::WasmRelocation const&) const (/local/emsdk/upstream/bin/wasm-ld+0x79292d)
 #8 0x000000000078fed9 lld::wasm::InputChunk::writeRelocations(llvm::raw_ostream&) const (/local/emsdk/upstream/bin/wasm-ld+0x78fed9)
 #9 0x00000000007c2c6c lld::wasm::CodeSection::writeRelocations(llvm::raw_ostream&) const (/local/emsdk/upstream/bin/wasm-ld+0x7c2c6c)
#10 0x00000000007ca099 lld::wasm::RelocSection::writeBody() (/local/emsdk/upstream/bin/wasm-ld+0x7ca099)
#11 0x00000000007b691a lld::wasm::SyntheticSection::finalizeContents() (/local/emsdk/upstream/bin/wasm-ld+0x7b691a)
#12 0x00000000007b0778 lld::wasm::(anonymous namespace)::Writer::run() (/local/emsdk/upstream/bin/wasm-ld+0x7b0778)
#13 0x00000000007a8941 lld::wasm::writeResult() (/local/emsdk/upstream/bin/wasm-ld+0x7a8941)
#14 0x000000000078b362 lld::wasm::(anonymous namespace)::LinkerDriver::link(llvm::ArrayRef<char const*>) (/local/emsdk/upstream/bin/wasm-ld+0x78b362)
#15 0x0000000000784b53 lld::wasm::link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&, llvm::raw_ostream&) (/local/emsdk/upstream/bin/wasm-ld+0x784b53)
#16 0x000000000048ac1d lldMain(int, char const**, llvm::raw_ostream&, llvm::raw_ostream&, bool) (/local/emsdk/upstream/bin/wasm-ld+0x48ac1d)
#17 0x000000000048a740 main (/local/emsdk/upstream/bin/wasm-ld+0x48a740)
#18 0x00007f56c15140b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#19 0x000000000048a41a _start (/local/emsdk/upstream/bin/wasm-ld+0x48a41a)
./test.sh: line 14:  9325 Aborted                 (core dumped) /local/emsdk/upstream/bin/wasm-ld -o libnoteswasm.a --whole-archive nem.wasm.a nem_wasm.wasm.a --no-whole-archive --relocatable -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr

Here is the zip file with the file including the core from the run shown above:
12934-20201201.zip

Let me know if you need anything else to help here.

Your comment on -shared is noted.

@rsielken
Copy link
Author

Any luck in fixing/avoiding this? Any additional information needed or workaround that we can use? I'd like to upgrade our EMSDK version for other fixes but can't if we can't build.

@mbelew
Copy link

mbelew commented Dec 14, 2020

I'm also seeing this issue. When we build one of our third party libraries - https://www.cryptopp.com/release820.html
Download and unzip cryptopp820.zip. Then use this make command:

emmake make CXXFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=1 -s USE_PTHREADS=1 -s FETCH=1 -s DISABLE_EXCEPTION_CATCHING=0 -std=c++14 -O2 -fPIC" dynamic

The issue starts at 2.0.9, but 2.0.8 is ok.

This output is from trying a 2.0.10 build:
out.txt

@mbelew
Copy link

mbelew commented Dec 14, 2020

Incidentally, I noticed this libpthread.so in the stack trace:

0x00007f56c20b5295 SignalHandler(int) (/local/emsdk/upstream/bin/../lib/libLLVM-12git.so+0x86c295)
#3 0x00007f56c59523c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)

I experimented with changing CXXFLAGS, removing USE_PTHREADS=1. The library now compiles without the crash. So something is amiss with linking pthreads.

Our primary app uses threads extensively, so this is a big blocker that's keeping us from upgrading and using the new debug features.

@sbc100
Copy link
Collaborator

sbc100 commented Dec 18, 2020

Fix is in https://reviews.llvm.org/D93554

@rsielken
Copy link
Author

rsielken commented Jan 13, 2021

I had hoped this would have been included in 2.0.12 (although I knew this issue was still open and not closed), but I pulled 2.0.12, did a build, and see the same error.

https://emscripten.org/docs/introducing_emscripten/release_notes.html listed
An upstream LLVM regression with global initializer linking has been fixed (#13038).
for 2.0.11, so I hoped that had included https://reviews.llvm.org/D93554 too.

But, it doesn't look like https://reviews.llvm.org/D93554 has made it into EMSDK yet. Is there any target on when that will be picked up? Is there some way to patch 2.0.12 to pick up that fix?

@sbc100
Copy link
Collaborator

sbc100 commented Jan 13, 2021

I'm afraid https://reviews.llvm.org/D93554 has not yet landed in LLVM

@sbc100
Copy link
Collaborator

sbc100 commented Jan 13, 2021

This is now landed. The change will be in 2.0.13, or "tot" in a few hours.

arichardson pushed a commit to arichardson/llvm-project that referenced this issue Mar 29, 2021
When running in `-r/--relocatable` we output relocations but the
new TLS relocations type was missing from `ObjFile::calcNewAddend`
causing this combination of inputs/flags to crash the linker.

Also avoid creating tls variables in relocatable mode.  These variables
are only needed when linking final executables.

Fixes: emscripten-core/emscripten#12934
Fixes: PR48506

Differential Revision: https://reviews.llvm.org/D93554
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
When running in `-r/--relocatable` we output relocations but the
new TLS relocations type was missing from `ObjFile::calcNewAddend`
causing this combination of inputs/flags to crash the linker.

Also avoid creating tls variables in relocatable mode.  These variables
are only needed when linking final executables.

Fixes: emscripten-core/emscripten#12934
Fixes: PR48506

Differential Revision: https://reviews.llvm.org/D93554
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants