Haha, it's almost like some detective short story. Surprisingly it wasn't as hard to follow as I thought. Maybe I'm starting to get good at this Computer Science thing.
Must be my fantastic writing. Seriously though, assembly isn't all that hard, mentally. It's difficult in the same way that unloading a truck full of sand with your bare hands is difficult. Which is to say, it takes a long time, but all it really needs is time, not deep thought. People get scared away from it because they don't know where to start with it, or because it looks really hard, or because it just takes too…
Anatomy of a Compiler Bug
11–20 of 21 posts
Re: Anatomy of a Compiler Bug
#12Earlier quoted context omitted.
Must be my fantastic writing. Seriously though, assembly isn't all that hard, mentally. It's difficult in the same way that unloading a truck full of sand with your bare hands is difficult. Which is to say, it takes a long time, but all it really needs is time, not deep thought. People get scared away from it because they don't know where to start with it, or because it looks really hard, or because it just takes too…
Or because they don't see immediate value in it, as typical programming isn't done in ASM nowadays. I think it's worthwhile just to "demystify" computers, but since embedded programming, demos and retro gaming are part of my interests, I get practical benefits out of it as well.
Re: Anatomy of a Compiler Bug
#13I used to work on compilers, C/C++, COBOL, PL/I, Java, a whole bunch of them. This is actually somewhat similar to my favorite bug I encountered while implementing some stack mapping optimizations. The compiler itself was crashing out while compiling a SPEC2000 test case (perlbmk I think?) with an illegal instruction. This was already quite suspect since it was branching to somewhere WAY outside of where the program…
Why doesn't the standard library warn when it knows %Lf might be too long?
(I say newer, but according to manpages snprintf is defined by SUSv2, from 1997, and C99, from 1999; so they're pretty old by now.)
You could probably have the compiler warn, provided (1) the destination is still an array and not a pointer (2) the format string is known at compile time. But that's a very different thing. (Most compilers these days do warn about any calls to sprintf, recommending snprintf instead.)
Re: Anatomy of a Compiler Bug
#14I used to work on compilers, C/C++, COBOL, PL/I, Java, a whole bunch of them. This is actually somewhat similar to my favorite bug I encountered while implementing some stack mapping optimizations. The compiler itself was crashing out while compiling a SPEC2000 test case (perlbmk I think?) with an illegal instruction. This was already quite suspect since it was branching to somewhere WAY outside of where the program…
One trick I did once when I wrote code somewhere that didn't have snprintf: create a pipe, fprintf into it, and only read at most N bytes back.
It worked and was portable but I'm sure the performance was horrible; this wasn't anything professional, I was just messing around as a kid (back when it was more common to come across platforms that hadn't gotten to SUSv2 or C99 yet). Probably a better solution would be to steal an implementation from an open source libc.
Re: Anatomy of a Compiler Bug
#15Just curious: Were the lldb session snippets taken from the original debugger session? I keep getting weird looks when I use a command-line debugger just to have a transcript afterwards. (The weird looks being from people who'd rather send me a screenshot of their GUI debugger's call stack.)
Re: Anatomy of a Compiler Bug
#16Earlier quoted context omitted.
Why doesn't the standard library warn when it knows %Lf might be too long?
sprintf does not know the size of the destination buffer. That's why the newer snprintf, which takes a size as a 2nd parameter, is recommended. (I say newer, but according to manpages snprintf is defined by SUSv2, from 1997, and C99, from 1999; so they're pretty old by now.) You could probably have the compiler warn, provided (1) the destination is still an array and not a pointer (2) the format string is known at co…
Also see C11's sprintf_s() and similarly-named friends.
Re: Anatomy of a Compiler Bug
#17Re: Anatomy of a Compiler Bug
#18I used to work on compilers, C/C++, COBOL, PL/I, Java, a whole bunch of them. This is actually somewhat similar to my favorite bug I encountered while implementing some stack mapping optimizations. The compiler itself was crashing out while compiling a SPEC2000 test case (perlbmk I think?) with an illegal instruction. This was already quite suspect since it was branching to somewhere WAY outside of where the program…
> that platform doesn't have an snprintf (yay mainframes!) One trick I did once when I wrote code somewhere that didn't have snprintf: create a pipe, fprintf into it, and only read at most N bytes back. It worked and was portable but I'm sure the performance was horrible; this wasn't anything professional, I was just messing around as a kid (back when it was more common to come across platforms that hadn't gotten to…
Re: Anatomy of a Compiler Bug
#19Earlier quoted context omitted.
sprintf does not know the size of the destination buffer. That's why the newer snprintf, which takes a size as a 2nd parameter, is recommended. (I say newer, but according to manpages snprintf is defined by SUSv2, from 1997, and C99, from 1999; so they're pretty old by now.) You could probably have the compiler warn, provided (1) the destination is still an array and not a pointer (2) the format string is known at co…
> newer snprintf Also see C11's sprintf_s() and similarly-named friends.
Re: Anatomy of a Compiler Bug
#20Nice article. But I wish it had gotten into an explanation of the actual bug in LLVM's code. Anyone have a bug number?
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-...
Would love to hear your conclusions about what the ultimate cause was if you get that far.