Fortunately, LLVM has a tool called bugpoint which can reduce this IR into a more manageable size of work. Doing manual reduction via an iterative process of "this doesn't look necessary; cut it out" the first time took me about an hour to produce a pile of code small enough to actually analyze. Doing it via bugpoint on the second bug took closer to 30 minutes. Unfortunately, the hard part is figuring out how to actually use the tool in the first place: none of the manuals give an example command line invocation, and they start playing games of "look at that documentation over there". So, I am going to remedy this situation by actually giving functional documentation.
In this case, I have an assert in an LLVM pass that is being triggered. This pass isn't being run as part of opt, but rather its own tool that takes as input an LLVM IR file. So the first step is to get the IR file (clang -cc1 -emit-llvm -O3 is sufficient for my needs). After that, it's time to prepare a shell script that actually compiles the code; you can skip this step if you don't actually need to provide arguments to the program. For example, my bugpoint.sh script would look like:
#!/bin/bash /path/to/tool "$@" -arg1 -arg2 -arg3=bleargh -o /dev/null
After that, the next step is to actually invoke bugpoint. Here's the command line that's running as I write this post: bugpoint --compile-custom -compile-command ./bugpoint.sh io_lat4.ll. Since my program causes an assertion failure, bugpoint figures out that I'm trying to crash on code generation (it can also detect miscompilation errors). Hopefully, the first bit of output you get should look like the following:
Error running tool: ./bugpoint.sh bugpoint-test-program.bc-FB1NoU Text indicating your program crashed *** Debugging code generator crash!
If you've seen this much (you may need to wait for it to crash; it can take a long time if you doing Debug+Asserts builds), you know that it's trying to find code that makes your tool crash. After that, bugpoint tries to first reduce global initializers and then tries to eliminate as many functions as possible. After that, it tries eliminating basic blocks and then goes to work eliminating instructions. You will see lots of streaming output telling you what stuff it's removing; the documentation says it's helpful to capture this output, but I've found it useless.
When everything is done, you should get several files of the form bugpoint-*.bc; the most useful one is bugpoint-reduced-simplified.bc, which is the most reduced testcase. What you get now is a nice, reduced testcase? Not quite. First, it gives you just a bitcode file (I'd prefer .ll files, simply because my first thought is to read them to figure out what's going on). Another problem I have with bugpoint is that it doesn't do things like attempt to eliminate unused struct entries, nor does it bother to clean up some of its names. Take a look at this struct monstrosity: %struct.su3_matrix.4.134.147.173.199.212.238.290.303.329.381.394.407.459.472.485.498.524.550.563.576.589.602.615.628.654.667.680.719.758.823.836.849.862.1044.1057.1096.1808 = type { [3 x [3 x %struct.complex.3.133.146.172.198.211.237.289.302.328.380.393.406.458.471.484.497.523.549.562.575.588.601.614.627.653.666.679.718.757.822.835.848.861.1043.1056.1095.1807]] }.
Anyways, I hope this helps anyone else who has looked at bugpoint before and wondered "How do I actually use this tool to do something useful?".
3 comments:
Unlock your spa’s full potential with Premier Salon Marketing – the top Marketing Agency for Spa businesses. We specialize in tailored strategies that drive growth, boost bookings, and build lasting client relationships. From social media to SEO, we elevate your brand with results-driven marketing solutions. Let us help your spa stand out in a competitive market and achieve unmatched success. Choose Premier Salon Marketing – where beauty meets smart marketing.
SDAD Technology is proud to be recognized as the Best SEO Company in India, delivering cutting-edge digital marketing solutions tailored to meet the unique needs of businesses across industries. With a team of seasoned SEO experts, we specialize in helping brands achieve top rankings on major search engines like Google, Bing, and Yahoo.
Our SEO strategies are data-driven, ethical, and customized to align with each client’s goals. From comprehensive keyword research and on-page optimization to powerful link-building and technical SEO, SDAD Technology ensures measurable results that drive organic traffic and boost conversions. We also offer local SEO, eCommerce SEO, and SEO audits to ensure a complete digital presence.
What sets us apart is our commitment to transparency, consistent communication, and continuous improvement. We believe in building long-term relationships with our clients by delivering value, not just promises.
Whether you're a startup or an established enterprise, SDAD Technology offers affordable and effective SEO services designed to maximize ROI. Partner with us to unlock your website’s true potential and stay ahead of the competition in the digital age.
Post a Comment