Why did the compiler do that - the one with VRP and integer size

Here’s a simple program - it right shifts a signed int by 9 bits, truncates it to an unsigned char, and returns 1 or 0 after comparing the result with 0x74. $ cat test.c extern int e; int main() { unsigned char result = e >> 9; // result = 0x74; if ((int)result != 0x74) return 1; return 0; } Let’s compile this for the avr target, choosing to optimize for size.

Thin LTO and compile time errors

GCC has had link time optimization (LTO) for quite a while now. Instead of generating just assembly code, it streams intermediate representation (IR) for the translation unit to the object file. At link time, when you provide all the object files necessary to link into the ELF, the compiler gets to see IR from all the translation units together, and this lets it perform optimizations across translation units. All you have to do is add -flto to the compiler and linker invocations and you’re done.

GCC's command line option handling and arbitrary values

Say you want to add your own command line option to the gcc driver. It’s pretty easy to do it as long as it is a number or a bitmask - just add an entry to your target’s opt file, and gcc’s option handling mechanism takes cares of it all. For example, this is how the avr target’s mn-flash option is described in avr.opt mn-flash= Target RejectNegative Joined Var(avr_n_flash) UInteger Init(-1) Set the number of 64 KiB flash segments.

Installing 64 bit Windows 10 on VirtualBox headless

Wanted to try Windows 10’s Windows On Linux subsystem to see if we can test mingw built toolchain binaries using the usual Dejagnu/expect/tcl testsuite runner. First step, of course, was to get my hands on a Windows 10 ISO. I didn’t have a spare machine lying around, so I decided to try this on a VM. I had a CentOS machine available that I could logon remotely, so I yum installed VirtualBox-5.

Making use of objcopy's --update-section for fun and profit

The binutils project’s objcopy utility gained an –update-section feature with the 2.26 release. This flag lets you insert the contents of any file into an already existing section in the ELF. You can make use of this flag to do a couple of things that are currently tricky to get right - placing data computed from the contents of the ELF (say the SHA1 hash of flash contents) into a binary, and creating a combined bootloader/application image from two separate binary files.

getprotobyname and the default ubuntu:vivid Docker image

Trying to setup a network server on a ubuntu:vivid docker image, I ran into a weird problem - the server would accept the TCP request and then drop the connection. After eliminating a bunch of possible causes (firewall, SELinux), I found that a simple python TCP server I cooked up worked just fine - it was just that particular network server program that was acting up. It worked perfectly fine on the Arch linux distribution running on my laptop though.

Docker - setting the default size of images with device mapper storage driver

Been playing around with docker ( for a while now to see if it can help create a one script setup for setting up the build environment for the avr8 toolchain. One pesky problem when using the device mapper storage driver (the default on RHEL) is that the created images/containers are small - only 10G. That isn’t going to cut it for building the GNU toolchain - the gcc repo itself takes up 2.

Debugging a debugger - gdb crash on Windows XP

If you’re one of the crazy guys building gdb for Windows using the 4.6.1 version of the mingw gcc compiler, here’s something to watch out for. gdb will crash on any error (even a mistyped command), but only on Windows XP. Turns out that gdb uses a setjmp/longjmp based error handling mechanism (see gdb/exceptions.c), and any error causes gdb to execute a longjmp. In Windows land, longjmp is implemented in msvcrt.

LTO and the linker command line

If you’re using GCC’s LTO feature, make sure you repeat the compiler flags when linking. So, if you compile code with -Os -ffunction-sections, make sure you pass the same flags to the gcc driver when linking. This is needed because LTO effectively recompiles by streaming in IR from the object files and regenerating code. Only this time it knows about the code in all the object files that’s going to be part of the final executable, so it can perform a bunch of optimizations it previously couldn’t.