Repository navigation
Description
Intention
I wanted to instrument both entry and exit of functions inside libtensorflow_cc.so.2
Describe the bug
When writing the output .so file, this error appears:
code_coverage: /tmp/root/spack-stage/spack-stage-dyninst-master-rooqjdjhh54uwore55jelghq4o64fagf/spack-src/dyninstAPI/src/emit-x86.C:1160: virtual bool EmitterAMD64Stat::emitPLTCall(func_instance*, codeGen&): Assertion `numeric_limits<int32_t>::lowest() <= offset && offset <= numeric_limits<int32_t>::max() && "offset more than 32 bits"' failed.
Aborted (core dumped)
To Reproduce
Steps to reproduce the behavior:
I modified the codeCoverage example with a simple instrumentation that can be seen here:
jordialcaraz/examples@636fdc1
To reproduce the issue, apply the changes or download the modified files.
Then, run
mkdir inst
./code_coverage -s ../../tensorflow/libtensorflow_cc.so.2 inst/tensorflow.inst
If you have tensorflow installed with python, you should be able to find the tensorflow libraries at
ls python3 -c "import os, tensorflow; print(os.path.dirname(tensorflow.__file__))"
If you have access to our machines at UOregon, I have a docker images in one of our machines with all the libraries, Dyninst installed and the modified example.
Also, it takes around 45-50 minutes until codeCoverage outputs the name of the functions it found.
Expected behavior
The instrumented library should be generated without crashing.
System (please complete the following information):
- What platform?
x86_64 - What commit?
spack install dyninst@master, the last commit at that moment was
cbf3187
Additional context
spack spec dyninst@master
[+] dyninst@master~ipo+openmp~stat_dysect~static build_system=cmake build_type=Release commit=cbf31878a8933191bc08a70bb03be46ac000dd09 generator=make platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^boost@1.86.0+atomic~charconv+chrono~clanglibcpp~cobalt+container~context~contract~conversion+date_time~debug+exception~fiber+filesystem~graph~graph_parallel~icu~iostreams~json~locale~log~math+mpi+multithreaded~nowide~numpy~pic~process~program_options~python+random~regex~serialization+shared~singlethreaded~stacktrace+system~taggedlayout~test+thread+timer~type_erasure~url~versionedlayout~wave build_system=generic cxxstd=11 patches=a440f96 visibility=hidden platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[e] ^mpich@5.0.1~argobots~cuda+fortran~hwloc+hydra~level_zero+libxml2~mpi5-abi+pci~rocm+romio~slurm~vci~verbs~wrapperrpath~xpmem build_system=autotools datatype-engine=auto device=ch4 netmod=ofi pmi=default platform=linux os=ubuntu24.04 target=x86_64_v3
[+] ^cmake@3.31.12~doc+ncurses+ownlibs~qtgui build_system=generic build_type=Release platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^curl@8.22.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2+nghttp2 build_system=autotools libs:=shared,static tls:=openssl platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^nghttp2@1.67.1 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^openssl@3.6.1~docs+shared build_system=generic certs=mozilla platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[b] ^ca-certificates-mozilla@2026-05-14 build_system=generic platform=linux os=ubuntu24.04 target=x86_64_v3
[+] ^perl@5.42.2+cpanm+opcode+open+shared+threads build_system=generic platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^berkeley-db@18.1.40+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^gdbm@1.26 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^readline@8.3 build_system=autotools patches=21f0a03,72dee13,e273643 platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^less@710 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^ncurses@6.6~symlinks+termlib abi=none build_system=autotools patches=7a351bc platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^zlib-ng@2.3.3+compat+new_strategies+opt+pic+shared build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^compiler-wrapper@1.1.0 build_system=generic platform=linux os=ubuntu24.04 target=x86_64_v3
[+] ^elfutils@0.194~debuginfod+exeprefix+nls build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^bzip2@1.0.8~debug~pic+shared build_system=generic platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[b] ^diffutils@3.12 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^gettext@1.0+bzip2+curses+git~libunistring+libxml2+pic+shared+tar+xz build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^libxml2@2.15.3+pic~python+shared build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^tar@1.35 build_system=autotools patches=85cb6b4 zip=pigz platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^pigz@2.8 build_system=makefile platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^libiconv@1.18 build_system=autotools libs:=shared,static platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[b] ^m4@1.4.21+sigsegv build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[b] ^libsigsegv@2.15 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^pkgconf@2.5.1 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^xz@5.8.3~pic build_system=autotools libs:=shared,static platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^zstd@1.5.7+programs build_system=makefile compression:=none libs:=shared,static platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[e] ^gcc@13.3.0+binutils+bootstrap+futex~graphite+libsanitizer~mold~nvptx~piclibs~profiled~strip build_system=autotools build_type=Release languages:='c,c++,fortran' platform=linux os=ubuntu24.04 target=x86_64_v3
[+] ^gcc-runtime@13.3.0 build_system=generic platform=linux os=ubuntu24.04 target=x86_64_v3
[e] ^glibc@2.39 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3
[+] ^gmake@4.4.1~guile build_system=generic platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^intel-tbb@2023.1.0~ipo+shared+tm build_system=cmake build_type=Release cxxstd=default generator=make platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[b] ^cmake@3.31.12~doc+ncurses+ownlibs~qtgui build_system=generic build_type=Release platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[b] ^curl@8.21.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2+nghttp2 build_system=autotools libs:=shared,static tls:=openssl platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[b] ^openssl@3.6.1~docs+shared build_system=generic certs=mozilla platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[b] ^perl@5.42.2+cpanm+opcode+open+shared+threads build_system=generic platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[b] ^less@692 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[+] ^hwloc@2.13.0~cairo~cuda~gl~level_zero~libudev+libxml2~nvml~opencl+pci~rocm build_system=autotools libs:=shared,static patches=b4db98b platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
[+] ^libpciaccess@0.17 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c=gcc@13.3.0
[b] ^util-macros@1.20.2 build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3
[+] ^libiberty@2.46.0+pic build_system=autotools platform=linux os=ubuntu24.04 target=x86_64_v3 %c,cxx=gcc@13.3.0
Activity
bbiiggppiigg commentedon Nov 13, 2026
@jordialcaraz
Can you give #2614 a try?
After fixing it I'm able to finish intrumenting libtensforflow.
But since my local machine does not have CUDA / NVIDIA device it throws exception, which is currently not supported by dynisntr instrumentation.
We do have access to UOregon Machines so pleaset let me know which machine you are using (at ideally in future issues / communucation), so I can try to reproduce and debug on the same machine as you are experiencing issues at.
jordialcaraz commentedon Nov 16, 2026
Hi @bbiiggppiigg ,
I'm testing the commit, built with spack, and it was able to generate the instrumented file. But I'm seeing an error when importing tensorflow, maybe some initialization function is not correctly instrumented. I will try to disable the instrumentation of the initialization functions and report back.
With the fix, is it expected that it needs so much memory?
This is with top:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1734687 root 20 0 100.2g 94.7g 1.0g R 99.7 18.8 56:34.17 code_coverage
bbiiggppiigg commentedon Nov 16, 2026
I think the memory is expected since #2614 is not primarily designed to fix memory consumption, but to avoid data being too far way from the instrumentation code (so it is within range of the offset dyninst currently used).
Can you tell me which machine you are running on so I can try to get tensorflow working from end to end and uncover any possible issues that you might run into (instead of communicating one bug after another).
In the meantime I'll see if there is something I can do about the memory consumption.
jordialcaraz commentedon Nov 16, 2026
Hi @bbiiggppiigg ,
I'm using Gilgamesh.
If you want to try to reproduce the issue, you can use our machines at oregon and, if you have docker permission:
There is a "dyninst@14" installed, that version is just Dyninst pointing to the commit with your fix.
bbiiggppiigg commentedon Nov 16, 2026
Here is where the memory goes. I added the current and peak RSS (
VmRSS/VmHWM) to everyDYNINST_DEBUG_PROGRESSline, plus a few markers inside parsing, and reran the rewrite oflibtensorflow_cc.so.2(TF 2.20.0) with yourcode_coverageand #2614 on an x86_64 machine. The run took 63 min and peaked at 95.3 GiB, which matches the 94.7g you saw.parse_frames, +18.5 G)insertSnippetlibtensorflow_framework.so.2shows the same shape at a smaller scale: peak 16.2 G, 4.3 G for parsing, 6.1 G for building the reloc blocks.What this shows:
InstructionAPI::Instructionby value (632 bytes, plus the decoded operands on the heap). That is consistent with the 329 MB of.textin this library, but it is an estimate from object sizes; we have not counted instructions yet.The next step on our side is to confirm the per-instruction cost and see how much of it can be avoided, for example by not keeping a decoded copy of every instruction for the whole rewrite. That would be a separate change from #2614.
bbiiggppiigg commentedon Nov 16, 2026
@jordialcaraz
The problem is that certain avx instruction is currently not decoded correctly by dyninst.
We expect this to be fixed when we moved to Zydis in the near (hopefully future).
bbiiggppiigg commentedon Nov 17, 2026
@jordialcaraz
Can you test this branch out?
https://github.com/dyninst/dyninst/tree/bbiiggppiigg/tf-2613-jordi
This is #2614 + #2620 .
I've tested on gilgamesh with your mutator and it seems to be able to generate tracefiles correctly.
Note that the memory consumption raised to 237 GB since more instructions and more blocks are discovered after the decoder fix in #2620
jordialcaraz commentedon Nov 18, 2026
Hi @bbiiggppiigg ,
I tried the branch and it works with the prints.
Thank you for the fix.
jordialcaraz commentedon Nov 18, 2026
Hi @bbiiggppiigg ,
I was testing a bit more, and with the codeCoverage, with all functions instrumented, I run into an error:
Will see if I can fix it, it worked when I only testing with import tensorflow. However, with MNIST, it fails. Will keep you updated, maybe skipping the instrumentation of some calls can fix it.
bbiiggppiigg commentedon Nov 18, 2026
You can also keep a branch for your reproducer so I can just try to reproduce whatever you are trying to .
bbiiggppiigg commentedon Nov 19, 2026
The
double free or corruption (out)in the full code-coverage run is a liveness bug, not something in the earlier fixes.llvm::ConstantRange::~ConstantRangeends in a conditional tail call:Liveness did not treat the
jneintooperator delete[]as a call, so%rdiwas dead there. The exit snippet put its string argument in%rdiwithout saving it, andoperator delete[]freed that string.The fix is draft PR #2625. It is now also on
bbiiggppiigg/tf-2613-jordi(head ae7af55 = the two earlier commits + #2625).With that branch, Keras MNIST (the keras.io simple convnet, 1 epoch, on the GPU) runs against the rewritten
libtensorflow_cc.so.2, with every function instrumented by the code_coverage mutator:The rewrite took 1 h 20 min with a peak RSS of 227 GiB. Training is much slower with the instrumentation: one epoch took 436 s.
bbiiggppiigg commentedon Nov 19, 2026
@jordialcaraz
There was a liveness bug on conditional tail call.
I've added the fix to the branch as one additional commit, and with that fix MNIST now should be working on gilgamesh.
jordialcaraz commentedon Nov 19, 2026
Hi @bbiiggppiigg ,
Thanks, I'm trying to test the fix.
jordialcaraz commentedon Nov 19, 2026
Hi @bbiiggppiigg ,
Sorry for the late reply, I had some issues with docker.
I tested the new commit and there are two cases, one that works and one that doesn't.
What I'm using is this modified example from dyninst:
https://github.com/jordialcaraz/examples/blob/master/codeCoverage/code_coverage.C
Case one is using the code as is, and it fails with a segmentation fault.
The other case is removing the comments at lines 196, 224, 236 and 247, which instruments every function executed (except those at the list).
Maybe this issue can be fixed, but as they are initialization functions, maybe it is not possible, and they are not that interesting to instrument.
But the second case fails with a "Bus error".
You can use image jordi-dyninst-ai-tensorflow-a1 with Gilgamesh, you can go to
cd /root/examples/codeCoverageAnd the lines I execute are inside:
cat instrument.shI built Dyninst with spack and this modification to the package
version("14", branch="bbiiggppiigg/tf-2613-jordi")I will see tomorrow if I can test with TAU, the example with the prints is just for testing, as instrumenting this library takes a while.
Thank you.
bbiiggppiigg commentedon Nov 19, 2026
Your case 1 runs the same mutator we used for the result above: with the skip list commented out, your
code_coverage.Cdiffers from ours only in oneprintf. With it, our build ofae7af5573crewrotelibtensorflow_cc.so.2on gilgamesh andmnist.pytrained to the original accuracy. So the difference is probably in the Dyninst build or the environment, not the mutator. We cannot look inside the container from our account, so two requests:spack find -lv dyninst(andspack find -p dyninst) from inside the container? Withversion("14", branch=...), Spack fetches the branch when it builds, but it does not rebuild an already installeddyninst@14when the branch moves. If the install predatesae7af5573c,spack uninstall dyninst(orspack install --overwrite dyninst@14) and a fresh rewrite should pick up the fix.inst/libtensorflow_cc.so.2to a directory on gilgamesh that other users can read (outside the container), and tell us the path? Then we can inspect howatexitwas instrumented without redoing the rewrite.In the meantime we are rewriting the library again with our build and keeping the coverage output, to check whether
atexitruns in our case and how its tail call to__cxa_atexitis instrumented. The bus error with the skip list enabled may be a separate issue; we will look at it once case 1 is understood.2 remaining items
bbiiggppiigg commentedon Nov 19, 2026
@jordialcaraz
Can you also put an uninstrumented copy under /tmp ?
So I can try to instrument it and see what went wrong.
jordialcaraz commentedon Nov 19, 2026
Done.
Called the file
original_libtensorflow_cc.so.2bbiiggppiigg commentedon Nov 19, 2026
I think I fonud the cause. I'll let you know when I push the fix for it.
tests: run far_rip_relative on a non-PIE executable and a shared library
dyninstAPI: form far RIP-relative targets relative to the code (x86_64)
tests: run far_rip_relative on a non-PIE executable and a shared library
dyninstAPI: form far RIP-relative targets relative to the code (x86_64)
bbiiggppiigg commentedon Nov 20, 2026
We reproduced the error with tensorflow 2.21.0 and ported the fix to your branch:
bbiiggppiigg/tf-2613-jordiis now at5e19d55116. We verified it end to end on gilgamesh: with the fix, the rewrittenlibtensorflow_cc.so.2imports andmnist.pytrains (accuracy 0.9740, 0.9727 uninstrumented).Spack does not rebuild the installed
dyninst@14when the branch moves, so please reinstall it (spack install --overwrite dyninst@14) and check thatspack find -lv dyninstshowscommit=5e19d55116before rewriting again.jordialcaraz commentedon Nov 20, 2026
Hi @bbiiggppiigg ,
I tested the fix, but I'm still running into some issues. Now, it doesn't crash at that point, but at another.
As you can't access docker with our machine, I will try to build everything outside docker so you can access it. That way it may be easier to debug. May modify the example a bit, with the prints, it takes too long.
jordialcaraz commentedon Nov 23, 2026
Hi @bbiiggppiigg
I looked a bit more and it is working now.
The issue was that the library also includes call to GPU, so it fails when I enable the GPU, but works with MNIST when using only CPU.
kupsch commentedon Nov 24, 2026
Here is a small reproducer for the
emitPLTCallassert that doesn't need TensorFlow: #2634 adds it as a regression test,dyninstAPI_far_plt_call. On master it asserts in about 2 seconds.The static rewriter puts a call's jump slot and the instrumentation that calls through it in the same new region, and
emitPLTCallreaches the slot with a 32-bit displacement. The test puts them more than 2 GiB apart:With a 1900 MiB gap the rewrite works and the output runs.
#2614 removes what made the gap in the TensorFlow rewrite (a new copy of each snippet string every time its code is generated). #2577 adds far forms for shared-variable loads and stores. Neither changes the 32-bit reach of
emitPLTCalloremitPLTJump, so the reproducer still asserts with each of them and with both merged (#2614 at c3aba36, #2577 at 72fcd0f).A fix could load the slot's address into a scratch register and call through it when the slot is out of reach, or allocate each slot near the code that uses it. Only x86_64 has this limit: aarch64 and ppc64le build the full offset in a register.
tests: run far_rip_relative on a non-PIE executable and a shared library
dyninstAPI: form far RIP-relative targets relative to the code (x86_64)
tests: run far_rip_relative on a non-PIE executable and a shared library
dyninstAPI: form far RIP-relative targets relative to the code (x86_64)