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.
CONTINUE READING
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.
CONTINUE READING
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.
CONTINUE READING
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.
CONTINUE READING
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.
CONTINUE READING