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

/usr/bin/ld.gold: fatal error: LLVM gold plugin: <unknown>:0: Undefined temporary symbol .Ltmp265928 #48

Closed
maflcko opened this issue Feb 23, 2022 · 24 comments
Labels
bug Something isn't working

Comments

@maflcko
Copy link
Contributor

maflcko commented Feb 23, 2022

Was running ../run_both.sh bitcoin-core 3, but it failed.

...
[Log level 2] : 13:06:58 : Wrapping function sancov.module_ctor_8bit_counters.86728
[Log level 2] : 13:06:58 : Wrapping function event_listener_getbase
[Log level 2] : 13:06:58 : Wrapping function event_listener_getfd
[Log level 2] : 13:06:58 : Wrapping function event_listener_destroy
[Log level 2] : 13:06:58 : Wrapping function event_listener_disable
[Log level 2] : 13:06:58 : Wrapping function event_listener_enable
[Log level 2] : 13:06:58 : Wrapping function evconnlistener_set_error_cb
[Log level 2] : 13:06:58 : Wrapping function evconnlistener_set_cb
[Log level 2] : 13:06:58 : Wrapping function evconnlistener_get_base
[Log level 2] : 13:06:58 : Wrapping function evconnlistener_get_fd
[Log level 2] : 13:06:58 : Wrapping function evconnlistener_disable
[Log level 2] : 13:06:58 : Wrapping function evconnlistener_free
[Log level 2] : 13:06:58 : Wrapping function evconnlistener_new_bind
[Log level 2] : 13:06:58 : Wrapping function evconnlistener_new
[Log level 2] : 13:06:58 : Wrapping function listener_read_cb
[Log level 2] : 13:06:58 : Wrapping function evconnlistener_enable
[Log level 2] : 13:06:58 : Wrapping function sancov.module_ctor_8bit_counters.86775
[Log level 2] : 13:06:58 : Wrapping function evthread_posix_get_id
[Log level 2] : 13:06:58 : Wrapping function evthread_posix_cond_wait
[Log level 2] : 13:06:58 : Wrapping function pthread_cond_timedwait
[Log level 2] : 13:06:58 : Wrapping function pthread_cond_wait
[Log level 2] : 13:06:58 : Wrapping function evthread_posix_cond_signal
[Log level 2] : 13:06:58 : Wrapping function pthread_cond_broadcast
[Log level 2] : 13:06:58 : Wrapping function pthread_cond_signal
[Log level 2] : 13:06:58 : Wrapping function evthread_posix_cond_free
[Log level 2] : 13:06:58 : Wrapping function pthread_cond_destroy
[Log level 2] : 13:06:58 : Wrapping function evthread_posix_cond_alloc
[Log level 2] : 13:06:58 : Wrapping function pthread_cond_init
[Log level 2] : 13:06:58 : Wrapping function evthread_posix_unlock
[Log level 2] : 13:06:58 : Wrapping function evthread_posix_lock
[Log level 2] : 13:06:58 : Wrapping function pthread_mutex_trylock
[Log level 2] : 13:06:58 : Wrapping function evthread_posix_lock_free
[Log level 2] : 13:06:58 : Wrapping function evthread_posix_lock_alloc
[Log level 2] : 13:06:58 : Wrapping function evthread_use_pthreads
[Log level 2] : 13:06:58 : Wrapping function pthread_mutexattr_init
[Log level 2] : 13:06:58 : Wrapping function pthread_mutexattr_settype
[Log level 2] : 13:06:58 : Ended wrapping all functions
[Log level 1] : 13:06:59 : Finished introspector module
/usr/bin/ld.gold: fatal error: LLVM gold plugin: <unknown>:0: Undefined temporary symbol .Ltmp265928

clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Makefile:6708: test/fuzz/fuzz] Error 1
make[2]: Leaving directory '/src/bitcoin-core/src'
make[1]: *** [Makefile:17510: all-recursive] Error 1
make[1]: Leaving directory '/src/bitcoin-core/src'
make: *** [Makefile:812: all-recursive] Error 1
ERROR:root:Building fuzzers failed.
@maflcko
Copy link
Contributor Author

maflcko commented Feb 23, 2022

I was compiling OSS-Fuzz myself, but I see that something was merged upstream. Does it need a bump in this repo, like #25 ?

@DavidKorczynski
Copy link
Contributor

atm there are two different patches going on: the local ones from here and the ones already pushed to OSS-Fuzz. Ideally the patch we have here should be removed in favour of using the patches in upsteam OSS-Fuzz. I haven't looked at doing this yet, but am not sure if the upstream OSS-Fuzz patches are fully working with a local set up -- @Navidem there were some issues with running the fuzz-introspector set up in OSS-Fuzz locally, is this fixed?

For that reason I think it shouldn't be bumped atm because it will mix the two patches together, which will inevitably fail.

There were two major things changed recently in the compiler plugin: (1) we updated to latest LLVM version and new plugin manager, and (2) we add a global variable as a tag in the binary (this is a "major" change since it means now we add content to the module whereas previously we just observed). This issue could be related to that, potentially.

@Navidem
Copy link
Contributor

Navidem commented Feb 23, 2022

I haven't looked at doing this yet, but am not sure if the upstream OSS-Fuzz patches are fully working with a local set up

For local set-up we have to use build_patched_oss_fuzz.sh.

I just tried ../run_both.sh bitcoin-core 3 on commit 9497e29 and it passes fuzzer build successfully.

@maflcko
Copy link
Contributor Author

maflcko commented Feb 23, 2022

I was trying latest main from this morning. I'll try commit 9497e29 tomorrow.

@DavidKorczynski
Copy link
Contributor

Thanks! Let me know how it works -- I will also see if I can identify if the patching it now does can be the cause of this issue

@Navidem
Copy link
Contributor

Navidem commented Feb 23, 2022

Along with my previous comment, I also gave a try bitcoin-core on the latest commit today: 34de464 (by applying the patches locally), and it went on successfully as well. I can see the fuzzers running...
Hope this helps!

Running script_sign
...
Using seed corpus: script_sign_seed_corpus.zip
/out/script_sign -rss_limit_mb=2560 -timeout=25 -max_total_time=3 -detect_leaks=0 /tmp/script_sign_corpus < /dev/null
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 492432055
INFO: Loaded 1 modules   (191726 inline 8-bit counters): 191726 [0x55cba2b38be8, 0x55cba2b678d6), 
INFO: Loaded 1 PC tables (191726 PCs): 191726 [0x55cba2b678d8,0x55cba2e547b8), 
INFO:     9136 files found in /tmp/script_sign_corpus
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 1048576 bytes
INFO: seed corpus: files: 9136 min: 1b max: 1048756b total: 222936690b rss: 74Mb
#1024   pulse  cov: 4907 ft: 12976 corp: 410/17Kb exec/s: 256 rss: 93Mb
#2048   pulse  cov: 5828 ft: 16970 corp: 749/59Kb exec/s: 256 rss: 93Mb
#4096   pulse  cov: 6441 ft: 22604 corp: 1324/167Kb exec/s: 292 rss: 100Mb
#8192   pulse  cov: 6846 ft: 41798 corp: 3222/5693Kb exec/s: 89 rss: 137Mb
Running script_interpreter
...
Using seed corpus: script_interpreter_seed_corpus.zip
/out/script_interpreter -rss_limit_mb=2560 -timeout=25 -max_total_time=3 -detect_leaks=0 /tmp/script_interpreter_corpus < /dev/null
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 4248576247
INFO: Loaded 1 modules   (191726 inline 8-bit counters): 191726 [0x55acbb397be8, 0x55acbb3c68d6), 
INFO: Loaded 1 PC tables (191726 PCs): 191726 [0x55acbb3c68d8,0x55acbb6b37b8), 
INFO:     2070 files found in /tmp/script_interpreter_corpus
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 1048576 bytes
INFO: seed corpus: files: 2070 min: 1b max: 1084228b total: 152559799b rss: 68Mb
#1024   pulse  cov: 1801 ft: 7664 corp: 378/24Kb exec/s: 204 rss: 88Mb

@maflcko
Copy link
Contributor Author

maflcko commented Feb 24, 2022

Sorry for being unclear, let me provide exact steps to reproduce. My understanding is that the rust image is not yet built for introspector, thus an additional OSS-Fuzz patch is needed to change the image:

diff --git a/projects/bitcoin-core/Dockerfile b/projects/bitcoin-core/Dockerfile
index 61972719..6a2040a3 100644
--- a/projects/bitcoin-core/Dockerfile
+++ b/projects/bitcoin-core/Dockerfile
@@ -14,7 +14,7 @@
 #
 ################################################################################
 
-FROM gcr.io/oss-fuzz-base/base-builder-rust
+FROM gcr.io/oss-fuzz-base/base-builder
 
 # Packages taken from:
 # * https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md#dependency-build-instructions
diff --git a/projects/bitcoin-core/build.sh b/projects/bitcoin-core/build.sh
index 5c6ac475..3d644e83 100755
--- a/projects/bitcoin-core/build.sh
+++ b/projects/bitcoin-core/build.sh
@@ -15,7 +15,6 @@
 #
 ################################################################################
 
-$SRC/build_cryptofuzz.sh
 
 cd $SRC/bitcoin-core/
 
@@ -29,7 +28,8 @@ fi
 (
   cd depends
   sed -i --regexp-extended '/.*rm -rf .*extract_dir.*/d' ./funcs.mk  # Keep extracted source
-  make HOST=$BUILD_TRIPLET DEBUG=1 NO_QT=1 NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 boost_cxxflags="-std=c++17 -fvisibility=hidden -fPIC ${CXXFLAGS}" libevent_cflags="${CFLAGS}" -j$(nproc)
+  make HOST=$BUILD_TRIPLET NO_QT=1 NO_BDB=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 libevent_cflags="${CFLAGS}" sqlite_cflags="${CFLAGS}" -j$(nproc)
+  # DEBUG=1 is temporarily disabled due to libc++ bugs
 )
 
 # Build the fuzz targets
@@ -39,6 +39,9 @@ sed -i "s|PROVIDE_FUZZ_MAIN_FUNCTION|NEVER_PROVIDE_MAIN_FOR_OSS_FUZZ|g" "./confi
 
 # Temporarily compile with O2 to work around clang-13 (and later) UBSan
 # -fsanitize=vptr,object-size false positive that only happens with -O1
+# Fixed in https://github.com/llvm/llvm-project/commit/bbeaf2aac678
+# However, OSS-Fuzz is stuck on a buggy clang, so the workaround is still
+# needed. See https://github.com/google/oss-fuzz/pull/7140
 if [ "$SANITIZER" = "undefined" ]; then
   export CFLAGS="$CFLAGS -O2"
   export CXXFLAGS="$CXXFLAGS -O2"
@@ -79,14 +82,14 @@ fi
 # An alternative to mocking the string in the finished binary would be to
 # replace the string in the source code and re-invoke 'make'. This is slower,
 # so use the hack.
-export MAGIC_STR="b5813eee2abc9d3358151f298b75a72264ffa119d2f71ae7fefa15c4b70b4bc5b38e87e3107a730f25891ea428b2b4fabe7a84f5bfa73c79e0479e085e4ff157"
-sed -i "s|.*std::getenv(\"FUZZ\").*|std::string fuzz_target{\"$MAGIC_STR\"};|g" "./src/test/fuzz/fuzz.cpp"
-sed -i "s|.find(fuzz_target)|.find(fuzz_target.c_str())|g"                      "./src/test/fuzz/fuzz.cpp"
-make -j$(nproc)
-
 # Replace the magic string with the actual name of each fuzz target
 for fuzz_target in ${FUZZ_TARGETS[@]}; do
-  python3 -c "c_str_target=b\"${fuzz_target}\x00\";c_str_magic=b\"$MAGIC_STR\";c=open('./src/test/fuzz/fuzz','rb').read();c=c.replace(c_str_magic, c_str_target+c_str_magic[len(c_str_target):]);open(\"$OUT/$fuzz_target\",'wb').write(c)"
+  git checkout -- "./src/test/fuzz/fuzz.cpp"
+  sed -i "s|.*std::getenv(\"FUZZ\").*|std::string fuzz_target{\"$fuzz_target\"};|g" "./src/test/fuzz/fuzz.cpp"
+  sed -i "s|.find(fuzz_target)|.find(fuzz_target.c_str())|g"                        "./src/test/fuzz/fuzz.cpp"
+  make -j$(nproc)
+  mv './src/test/fuzz/fuzz' "$OUT/$fuzz_target"
+
   chmod +x "$OUT/$fuzz_target"
   (
     cd assets/fuzz_seed_corpus

You can then run a slightly faster build by selecting the "CI build":

OSS_FUZZ_CI=1 ../run_both.sh bitcoin-core 3

This will give the above failure.

@DavidKorczynski
Copy link
Contributor

I am seeing this same issue in jsoncpp

@DavidKorczynski
Copy link
Contributor

DavidKorczynski commented Mar 9, 2022

In the jsoncpp context I only see this issue in the OSS-Fuzz integration and not locally (outside OSS-Fuzz environments) using https://github.com/ossf/fuzz-introspector/tree/main/tests/jsoncpp

@DavidKorczynski
Copy link
Contributor

DavidKorczynski commented Mar 9, 2022

The error message seems to come from here:

https://github.com/llvm/llvm-project/blob/26bbde2612b2042c3a8a31aed7f45e065c3dd413/llvm/lib/MC/ELFObjectWriter.cpp#L638-L641

The global variable we add for tagging purposes is here:

llvm::GlobalVariable *GV = new GlobalVariable(
M,
FuzzIntrospectorTag->getType(),
true,
llvm::GlobalValue::LinkageTypes::ExternalLinkage,
FuzzIntrospectorTag,
"FuzzIntrospectorTag");

I think the issue happens because the linkage llvm::GlobalValue::LinkageTypes::ExternalLinkage will add the symbol (global variable) to the symbol table. However, the global variable we add is never referenced anywhere in the module, so I wonder if LLVM makes it a temporary and undefined symbol for that reason.

One possible solution may be to change the linkage, to either some form or weak linkage or PrivateLinakge which excludes the variable from the symbol table (https://llvm.org/doxygen/classllvm_1_1GlobalValue.html#aedfa75f0c85c4aa85b257f066fbea57c) -- will verify this hypothesis. I wonder why it would work only in some cases though, as the tagging does work for some examples.


This does not seem to be the issue: if I comment out the code that adds the global variable I still run into the issue in jsoncpp.

@DavidKorczynski
Copy link
Contributor

Update on jsoncpp: this issue is unrelated to fuzz-introspector it seems, in that if we disable fuzz-introspector (unset FUZZ_INTROSPECTOR) then the issue still occurs despite fuzz-introspector not doing any work

@DavidKorczynski
Copy link
Contributor

DavidKorczynski commented Apr 2, 2022

@MarcoFalke did you see any differences following the linker merge? I think this error is not due to fuzz-introspector following the comments above. It seemed to be related to something in latest LLVM itself.

Specifically, the issue occurred even without introspector for another project, and the error message seem to come from a place in the LLVM code that is distant to fuzz-introspector code https://github.com/llvm/llvm-project/blob/26bbde2612b2042c3a8a31aed7f45e065c3dd413/llvm/lib/MC/ELFObjectWriter.cpp#L638-L641

@maflcko
Copy link
Contributor Author

maflcko commented Apr 4, 2022

Sure, happy to take another look. I see there were some changes in the oss-fuzz repo and here, so I am wondering what is the best way to build fuzz-introspector right now? Start from the oss-fuzz repo or start from this repo?

@DavidKorczynski
Copy link
Contributor

DavidKorczynski commented Apr 4, 2022

One option that let's you avoid building the images yourself is to pull the latest oss-fuzz fuzz-introspector base-clang image. I am still in the process of updating the docs, but following this thread you can see details: #67 (comment)

Note that updating the docs is on my to-do list so it should hopefully be done in the near future.

@maflcko
Copy link
Contributor Author

maflcko commented Apr 4, 2022

Ok, I tried to run:

OSS_FUZZ_CI=1  python3 infra/helper.py build_fuzzers --sanitizer=introspector bitcoin-core

It fails with:

     |████████████████████████████████| 40kB 34.0MB/s 
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.8/site-packages (from python-dateutil>=2.7->matplotlib) (1.15.0)
Building wheels for collected packages: numpy
  Building wheel for numpy (PEP 517) ... done
  Created wheel for numpy: filename=numpy-1.22.3-cp38-cp38-linux_x86_64.whl size=15688858 sha256=eea9a47fd81c3cbc5a4cb12e33cf76e0726cef85448032e1d1e6e2d4a7aee94c
  Stored in directory: /root/.cache/pip/wheels/21/37/10/81a13af5964837a3627457192fbc14d926b1a2dcd810f70fbf
Successfully built numpy
Installing collected packages: cxxfilt, pyyaml, soupsieve, beautifulsoup4, lxml, python-dateutil, pyparsing, fonttools, numpy, pillow, cycler, kiwisolver, packaging, matplotlib
  Running setup.py install for pillow ... done
Successfully installed beautifulsoup4-4.10.0 cxxfilt-0.3.0 cycler-0.11.0 fonttools-4.31.2 kiwisolver-1.4.2 lxml-4.8.0 matplotlib-3.5.1 numpy-1.22.3 packaging-21.3 pillow-9.1.0 pyparsing-3.0.7 python-dateutil-2.8.2 pyyaml-6.0 soupsieve-2.3.1
WARNING: You are using pip version 19.2.3, however version 22.0.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
INFO:fuzz_utils:File: /out/cryptofuzz-bitcoin-cryptography-w15-p4 is executable
INFO:fuzz_utils:File: /out/addr_info_deserialize is executable
INFO:fuzz_utils:File: /out/cryptofuzz-bitcoin-cryptography-w2-p2 is executable
INFO:fuzz_utils:File: /out/llvm-symbolizer is executable
INFO:fuzz_utils:File: /out/addition_overflow is executable
INFO:fuzz_utils:File: /out/cryptofuzz-bitcoin-cryptography-w20-p8 is executable
INFO:fuzz_utils:File: /out/address_deserialize_v1_notime is executable
INFO:__main__:Pairings: []
INFO:__main__:Ending fuzz introspector post-processing
/usr/local/bin/compile: line 220: COVERAGE_URL: unbound variable
ERROR:root:Building fuzzers failed.

@DavidKorczynski
Copy link
Contributor

Thanks @MarcoFalke -- I'm on it, will let you know here once it's resolved.

DavidKorczynski added a commit to google/oss-fuzz that referenced this issue Apr 4, 2022
* infra: fuzz-introspector: ensure COVERAGE_URL exists

This is to make sure fuzz-introspector can run in local builds.

Ref:
ossf/fuzz-introspector#48 (comment)
Ref:
ossf/fuzz-introspector#67 (comment)

* refactor fuzz-introspector command generation

This is to shorten the long line that runs fuzz-introspector and also in
anticipation that down the line we will have more oss-fuzz specific
commands in fuzz-introspector
@maflcko
Copy link
Contributor Author

maflcko commented May 30, 2022

Happy to try again, just let me know :)

@DavidKorczynski
Copy link
Contributor

Argh I forgot to ping here -- apologies @MarcoFalke

The COVERAGE_URL issue is fixed.

This should be ready to test if building OSS-Fuzz images yourself from the fuzz-introspector repository.

If you would like to use the OSS-Fuzz images, then I would wait until this is merged google/oss-fuzz#7774 as it has a few bug fixes

MartinPetkov pushed a commit to MartinPetkov/oss-fuzz that referenced this issue Aug 15, 2022
* infra: fuzz-introspector: ensure COVERAGE_URL exists

This is to make sure fuzz-introspector can run in local builds.

Ref:
ossf/fuzz-introspector#48 (comment)
Ref:
ossf/fuzz-introspector#67 (comment)

* refactor fuzz-introspector command generation

This is to shorten the long line that runs fuzz-introspector and also in
anticipation that down the line we will have more oss-fuzz specific
commands in fuzz-introspector
@maflcko
Copy link
Contributor Author

maflcko commented Aug 30, 2022

Just tried again after the oss-fuzz bump to clang-15. Still reproducible with:

OSS_FUZZ_CI=1  python3 infra/helper.py build_fuzzers --sanitizer=introspector bitcoin-core

...

  CXXLD    test/fuzz/fuzz
/usr/bin/ld.gold: fatal error: LLVM gold plugin: <unknown>:0: Undefined temporary symbol .Ltmp175611

clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

This seems to be the same error that is listen on the instrospector tab on https://oss-fuzz-build-logs.storage.googleapis.com/index.html (also seen for a few other projects).

@DavidKorczynski
Copy link
Contributor

Thanks @MarcoFalke

My current understanding of this is it's not due to Fuzz Introspector but rather LTO (#48 (comment)). When I debugged it ( #48 (comment)) I could not locate the error in Fuzz Introspector but just in some llvm code, and the issue occurred with and without fuzz introspector.

@maflcko
Copy link
Contributor Author

maflcko commented Aug 31, 2022

Ok, I've moved the issue to bitcoin/bitcoin#25961 as it seems unrelated to this codebase.

@maflcko maflcko closed this as completed Aug 31, 2022
@DavidKorczynski
Copy link
Contributor

Given bitcoin/bitcoin#25961 (comment) we may need to force use of clang 16 -- this issue does affect a lot of projects.

@maflcko
Copy link
Contributor Author

maflcko commented Sep 1, 2022

Does introspector already use a different clang version than oss-fuzz? If yes, that should simplify things and I am happy to test that. Otherwise, it seems hard to bump the oss-fuzz clang version, so I might just wait until it happens "by itself".

Edit: Alternative (:sweat_smile:): Switch to aarch64, which doesn't seem to have the bug

@DavidKorczynski
Copy link
Contributor

By default it uses the same. However, in the past we've used a different version and it probably wouldn't be too much of a hassle to get that in again.

I'll try and see if it's possible to get fuzz introspector running with clang-16 and then check if this issue is resolved in some projects! If successful, I can then push some images up somewhere that uses clang-16 and then we can use the solution of #452 to run introspector with the latest clang on the latest oss-fuzz corpus.

Interesting it works on aarch64 -- it's an annoying compiler bug and it does seem to affect a significant amount of projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants