Precision Opportunities for Demanded Bits in LLVM
https://blog.regehr.org/archives/1714 [blog.regehr.org]
2020-01-22 22:37
tags:
compiler
perf
programming
A fun thing that optimizing compilers can do is to automatically infer when the full power of some operation is not needed, in which case it may be that the operation can be replaced by a cheaper one. This happens in several different ways; the method we care about today is driven by LLVM’s demanded bits static analysis, whose purpose is to prove that certain bits of an SSA value are irrelevant. For example, if a 32-bit value is truncated to 8 bits, and if that value has no other uses, then the 24 high bits of the original value clearly do not matter.
Helping Generative Fuzzers Avoid Looking Only Where the Light is Good
https://blog.regehr.org/archives/1700 [blog.regehr.org]
2019-11-05 04:20
tags:
development
fuzzing
testing
Using a generative fuzzer — which creates test cases from scratch, rather than mutating a collection of seed inputs — feels to me a lot like being the drunk guy in the joke: we’re looking for bugs that can be triggered by inputs that the generator is likely to generate, because we don’t have an obviously better option, besides doing some hard work in improving the generator. This problem has bothered me for a long time.
Write Fuzzable Code
https://blog.regehr.org/archives/1687 [blog.regehr.org]
2019-08-21 03:48
tags:
development
fuzzing
testing
Fuzzing is sort of a superpower for locating vulnerabilities and other software defects, but it is often used to find problems baked deeply into already-deployed code. Fuzzing should be done earlier, and moreover developers should spend some effort making their code more amenable to being fuzzed.
This post is a non-comprehensive, non-orthogonal list of ways that you can write code that fuzzes better. Throughout, I’ll use “fuzzer” to refer to basically any kind of randomized test-case generator, whether mutation-based (afl, libFuzzer, etc.) or generative (jsfunfuzz, Csmith, etc.). Not all advice will apply to every situation, but a lot of it is sound software engineering advice in general. I’ve bold-faced a few points that I think are particularly important.
Design and Evolution of C-Reduce
https://blog.regehr.org/archives/1678 [blog.regehr.org]
2019-07-10 06:10
tags:
c
compiler
development
fuzzing
programming
testing
Since 2008, my colleagues and I have developed and maintained C-Reduce, a tool for programmatically reducing the size of C and C++ files that trigger compiler bugs. C-Reduce also usually does a credible job reducing test cases in languages other than C and C++; we’ll return to that later.
Part 2: https://blog.regehr.org/archives/1679
It’s Time for a Modern Synthesis Kernel
https://blog.regehr.org/archives/1676 [blog.regehr.org]
2019-07-05 01:28
tags:
jit
systems
The promise of kernel-mode runtime code generation is that we can have very fast, feature-rich operating systems by, for example, not including code implementing generic read() and write() system calls, but rather synthesizing code for these operations each time a file is opened. The idea is that at file open time, the OS has a lot of information that it can use to generate highly specialized code, eliding code paths that are provably not going to execute.
Verifying Popcount
https://blog.regehr.org/archives/1667 [blog.regehr.org]
2019-04-24 21:42
tags:
c
compsci
programming
Popcount is the function that returns the number of set bits in its argument. Showing that a popcount implementation does what it claims to do has become one of my favorite examples to use when I need to quickly show students how we can reason about programs mathematically. Something like a selection sort is probably the more standard example here, but sorting gets into some subtleties that I’d rather reserve for a second example. Popcount is so easy that this whole example can be done in a half hour.
Explaining Code using ASCII Art
https://blog.regehr.org/archives/1653 [blog.regehr.org]
2019-02-18 19:01
tags:
archive
development
docs
text
visualization
People tend to be visual: we use pictures to understand problems. Mainstream programming languages, on the other hand, operate in an almost completely different kind of abstract space, leaving a big gap between programs and pictures. This piece is about pictures drawn using a text character set and then embedded in source code. I love these! The other day I asked around on Twitter for more examples and the responses far exceeded expectations (thanks everyone!). There are a ton of great examples in the thread; here I’ve categorized a few of them. Click on images go to the repositories.
Synthesizing Constants
https://blog.regehr.org/archives/1636 [blog.regehr.org]
2018-11-08 19:57
tags:
compiler
compsci
programming
In this piece I want to discuss an aspect of program synthesis that sounds like it should be easy, but isn’t: synthesizing constant values.
In summary, constant synthesis is a hard problem that hasn’t received a lot of attention yet.
Learning When Values are Changed by Implicit Integer Casts
https://blog.regehr.org/archives/1633 [blog.regehr.org]
2018-11-05 21:49
tags:
c
compiler
programming
Like unsigned integer wraparound (and unlike signed integer overflow) these changes of value are not undefined behavior, but they may be unintentional and may also be bugs. As of recently, Clang contains support for dynamically detecting value changes and either providing a diagnostic or else terminating the program. Some fine-grained flags are available for controlling these diagnostics, but you can enable all of them (plus some others, such as signed overflow and unsigned wraparound checks) using -fsanitize=integer.
What’s the difference between an integer and a pointer?
https://blog.regehr.org/archives/1621 [blog.regehr.org]
2018-09-19 14:21
tags:
c
compiler
programming
What should we take away from this? First, it is a big mistake to try to understand pointers in a programming language as if they follow the same rules as pointer-sized integer values. Even people who have come to terms with UB and its consequences are often surprised by this. Second, these issues are not specific to C and C++, but rather are going to create problems in any language that wants highly optimizing compilers but also permits low-level pointer manipulation.
source: L
How LLVM Optimizes a Function
https://blog.regehr.org/archives/1603 [blog.regehr.org]
2018-09-06 19:02
tags:
compiler
perf
Although this diff looks a bit alarming, there’s not all that much happening.
Closing the Loop: The Importance of External Engagement in Computer Science Research
https://blog.regehr.org/archives/1582 [blog.regehr.org]
2018-04-21 01:38
tags:
academia
compsci
ideas
On leaky abstractions from engineering to academia.
Trust Boundaries in Software Systems
https://blog.regehr.org/archives/1576 [blog.regehr.org]
2018-02-20 16:10
tags:
development
intro-programming
security
One of the big things that has changed in computer science education over the last 20 years is that it is now mandatory to prepare students for writing software that lives in a hostile environment. This content can’t be limited to a computer security course, it has to be spread throughout the curriculum. My experience, based on talking to people, looking through textbooks, and looking at lecture material on the web, is that overall we’re not yet doing a great job at this.
Stories Behind Papers: Integer Overflow
https://blog.regehr.org/archives/1559 [blog.regehr.org]
2018-02-08 02:08
tags:
academia
c
compiler
programming
standard
Overall, dynamic detection of integer-related undefined behaviors in C/C++ is not difficult, but convincing people to take these bugs seriously was a long struggle and the broader issue of how integer overflows relate to program bugs is interesting and deep.
A Conversation about Teaching Software Engineering
https://blog.regehr.org/archives/1569 [blog.regehr.org]
2018-01-24 16:04
tags:
academia
development
intro-programming
Wow, this is a lot of material, way more than we cover in depth in a semester. Even so, I find it super useful as a high-level vision for the kinds of things students should end up at least having been exposed to.
Some Goals for High-impact Verified Compiler Research
https://blog.regehr.org/archives/1565 [blog.regehr.org]
2018-01-12 06:56
tags:
academia
compiler
compsci
I believe that translation validation, a branch of formal methods, is just about ready for widespread use. Translation validation means proving that a particular execution of a compiler did the right thing, as opposed to proving once and for all that every execution of a compiler will do the right thing. These are very different.
Undefined Behavior in 2017
https://blog.regehr.org/archives/1520 [blog.regehr.org]
2017-07-05 18:53
tags:
article
best
c
compiler
defense
development
programming
security
standard
swtools
Goal 1: Every UB (yes, all ~200 of them, we’ll give the list towards the end of this post) must either be documented as having some defined behavior, be diagnosed with a fatal compiler error, or else — as a last resort — have a sanitizer that detects that UB at runtime.
Goal 2: Every UB must either be documented as having some defined behavior, be diagnosed with a fatal compiler error, or else have an optional mitigation mechanism that meets the requirements above.
Pointer Overflow Checking is in LLVM
https://blog.regehr.org/archives/1518 [blog.regehr.org]
2017-06-05 15:02
tags:
c
compiler
programming
Today’s quick post is about another piece of the puzzle that very recently landed in LLVM: pointer overflow checking. At the machine level a pointer overflow looks just like an unsigned integer overflow, but of course at the language level the overflowing operation is pointer arithmetic, not unsigned integer arithmetic.
Been floating around for a while. See also: https://wdtz.org/catching-pointer-overflow-bugs.html
Compiler Optimizations are Awesome
https://blog.regehr.org/archives/1515 [blog.regehr.org]
2017-05-31 08:08
tags:
compiler
development
perf
This piece, which I hadn’t gotten around to writing until now since I thought it was all pretty obvious, explains why Daniel J. Bernstein’s talk, The death of optimizing compilers (audio) is wrong, and in fact compiler optimizations are extremely wonderful and aren’t going anywhere.
Translation Validation of Bounded Exhaustive Test Cases
http://blog.regehr.org/archives/1510 [blog.regehr.org]
2017-05-10 03:19
tags:
compiler
compsci
fuzzing
Our focus is the middle-end optimizers, which seem to be the most difficult part of a compiler to get right. The target is LLVM.