RSSAmplifier

Blog

Nick Desaulniers

Recent content on Nick Desaulniers

nickdesaulniers.github.ioRSS feed ↗43 posts

Latest posts

USPS as an ISP

While on a hike with colleagues, one asked a thought provoking question: Should the United States Post Service (USPS) operate as an Internet Service Provider (ISP)? This post is an opinion piece playing with that idea; here are my thoughts. It’s far from a hot take, and has been discussed before. Article 1 Section 8 of the United States Constitution states: “The Congress shall have…

Disambiguating Arm, Arm ARM, Armv9, ARM9, ARM64, AArch64, A64, A78, ...

If you’re new to the Arm ecosystem, consider this a quick primer on terms you likely have seen before but might have questions about. The Arm architecture is a family of Reduced Instruction Set Architectures (RISC) with simple addressing modes. Data processing is done on register operands otherwise relying on loads and stores to move data into and out of registers. Arm Limited, the British…

Forking is not free; the hidden costs

The Open Source software development model is a powerful approach to collaboratively iterating on a shared solution to a common problem. Rather than competitors duplicating effort to come up with multiple suboptimal solutions, they can collaborate together to build something greater. Forking is the term used to denote making a copy of a codebase. The copy, known as a “fork” is used as…

Critical Edge Splitting

A maximal length sequence of branch-free code that terminates with a branch or jump is referred to as a basic block. A basic block that branches to another forms an edge in the Control Flow Graph (CFG). The initial basic block starting an edge is the predecessor; it precedes and is succeeded by the successor basic block. An edge between basic blocks is considered a critical edge if the predecessor…

Debugging -Wframe-larger-than=

Unless work is done per architecture to implement HAVE_ARCH_VMAP_STACK / CONFIG_VMAP_STACK, the Linux kernel defaults to two pages worth of stack per thread. Note: on many contemporary systems the page size is 4KiB, but this is actually configurable for many architectures. The trade offs probably require a separate post. If you see code that checks for alignment via bitwise tricks like addr & 4095…

Off by Two

“War stories” in programming are entertaining tales of truly evil bugs that kept you up at night. Inspired by posts like My Hardest Bug Ever, Debugging an evil Go runtime bug, and others from /r/TalesFromDebugging, I wanted to share with you one of my favorites from recent memory. Recent work has given me much fulfilment and a long list of truly awful bugs to recount. My blog has been…

f() vs f(void) in C vs C++

TL;DR Prefer f(void) in C to potentially save a 2B instruction per function call when targeting x86_64 as a micro-optimization. -Wstrict-prototypes can help. Doesn’t matter for C++. The Problem While messing around with some C code in godbolt Compiler Explorer, I kept noticing a particular funny case. It seemed with my small test cases that sometimes function calls would zero out the return…

Finding Compiler Bugs With C-Reduce

Support for a long awaited GNU C extension, asm goto, is in the midst of landing in Clang and LLVM. We want to make sure that we release a high quality implementation, so it’s important to test the new patches on real code and not just small test cases. When we hit compiler bugs in large source files, it can be tricky to find exactly what part of potentially large translation units are…

Booting a Custom Linux Kernel in QEMU and Debugging It With GDB

Typically, when we modify a program, we’d like to run it to verify our changes. Before booting a compiled Linux kernel image on actual hardware, it can save us time and potential headache to do a quick boot in a virtual machine like QEMU as a sanity check. If your kernel boots in QEMU, it’s not a guarantee it will boot on metal, but it is a quick assurance that the kernel image is not completely…

Speeding Up Linux Kernel Builds With ccache

ccache, the compiler cache, is a fantastic way to speed up build times for C and C++ code that I previously recommended. Recently, I was playing around with trying to get it to speed up my Linux kernel builds, but wasn’t seeing any benefit. Usually when this happens with ccache, there’s something non-deterministic about the builds that prevents cache hits. Turns out someone asked this…

GCC vs LLVM Q3 2017 Commit Rates and Active Developer Counts

A blog post from a few years ago that really stuck with me was Martin Olsson’s Browser Engines 2015: Commit Rates and Active Developer Counts, where he shows information about the number of authors and commits to popular web browsers. The graphs and analysis had interesting takeaways like showing the obvious split in blink and webkit, and relative number of contributors of the projects. Martin had…

Running Clang-Tidy on the Linux Kernel

Clang-Tidy is a linter from the LLVM ecosystem. I wanted to try to run it on the Linux kernel to see what kind of bugs it would find. The false positive rate seems pretty high (a persistent bane to static analysis), but some patching in both the tooling and the source can likely help bring this rate down. The most straightforward way to invoke Clang-Tidy is with a compilation database, which is a…

Submitting Your First Patch to the Linux Kernel and Responding to Feedback

After working on the Linux kernel for Nexus and Pixel phones for nearly a year, and messing around with the excellent Eudyptula challenge, I finally wanted to take a crack at submitting patches upstream to the Linux kernel. This post is woefully inadequate compared to the existing documentation, which should be preferred. http://elixir.free-electrons.com/linux/latest/source/Documentation/process…

Static and Dynamic Libraries

This is the second post in a series on memory segmentation. It covers working with static and dynamic libraries in Linux and OSX. Make sure to check out the first on object files and symbols. Let’s say we wanted to reuse some of the code from our previous project in our next one. We could continue to copy around object files, but let’s say we have a bunch and it’s hard to keep track of all of…

Object Files and Symbols

What was supposed to be one blog post about memory segmentation turned into what will be a series of posts. As the first in the series, we cover the extreme basics of object files and symbols. In follow up posts, I plan to talk about static libraries, dynamic libraries, dynamic linkage, memory segments, and finally memory usage accounting. I also cover command line tools for working with these…

Cross Compiling C/C++ for Android

Let’s say you want to build a hello world command line application in C or C++ and run it on your Android phone. How would you go about it? It’s not super practical; apps visible and distributable to end users must use the framework (AFAIK), but for folks looking to get into developing on ARM it’s likely they have an ARM device in their pocket. This post is for folks who typically invoke their…

Setting up mutt with gmail on Ubuntu

I was looking to set up the mutt email client on my Ubuntu box to go through my gmail account. Since it took me a couple of hours to figure out, and I’ll probably forget by the time I need to know again, I figure I’d post my steps here. I’m on Ubuntu 16.04 LTS (lsb_release -a) Install mutt: $ sudo apt-get install mutt In gmail, allow other apps to access gmail:

Data Models and Word Size

This post is a follow up to my previous blog post about word size. Three C/C++ programmers walk into a bar. One argues that sizeof(void*) is equivalent to sizeof(long), one argues that sizeof(void*) is equivalent to sizeof(int), and the third argues it’s sizeof(long long). Simultaneously, they’re all right, but they’re also all wrong (and need a lesson about portable C code). What the hell is…

What's in a Word?

Recently, there some was some confusion between myself and a coworker over the definition of a “word.” I’m currently working on a blog post about data alignment and figured it would be good to clarify some things now, that we can refer to later. Having studied computer engineering and being quite fond of processor design, when I think of a “word,” I think of the…

Intro to Debugging X86-64 Assembly

I’m hacking on an assembly project, and wanted to document some of the tricks I was using for figuring out what was going on. This post might seem a little basic for folks who spend all day heads down in gdb or who do this stuff professionally, but I just wanted to share a quick intro to some tools that others may find useful. ( oh god, I’m doing it)

My SIGGRAPH 2015 Experience

I was recently lucky enough to get to attend my first SIGGRAPH conference this year. While I didn’t attend any talks, I did spend some time in the expo. Here is a collection of some of the neat things I saw at SIGGRAPH 2015. Sorry it’s not more collected; I didn’t have the intention of writing a blog post until after folks kept asking me “how was it?” VR Most booths…

Additional C/C++ Tooling

21st Century C by Ben Klemens was a great read. It had a section with an intro to autotools, git, and gdb. There are a few other useful tools that came to mind that I’ve used when working with C and C++ codebases. These tools are a great way to start contributing to Open Source C & C++ codebases; running these tools on the code or adding them to the codebases.

Interpreter Compiler JIT

Interpreters and compilers are interesting programs, themselves used to run or translate other programs, respectively. Those other programs that might be interpreted might be languages like JavaScript, Ruby, Python, PHP, and Perl. The other programs that might be compiled are C, C++, and to some extent Java and C#. Taking the time to do translation to native machine code ahead of time can result…

Hidden in Plain Sight - Public Key Crypto

How is it possible for us to communicate securely when there’s the possibility of a third party eavesdropping on us? How can we communicate private secrets through public channels? How do such techniques enable us to bank online and carry out other sensitive transactions on the Internet while trusting numerous relays? In this post, I hope to explain public key cryptography, with actual code…

Writing My First Technical Book Chapter

It’s a feeling of immense satisfaction when we complete a major achievement. Being able to say “it’s done” is such a great stress relief. Recently, I completed work on my first publication, a chapter about Emscripten for the upcoming book WebGL Insights to be published by CRC Press in time for SIGGRAPH 2015. One of the life goals I’ve had for a while is writing a…

Let's Write Some X86-64

…"‘Our speech interposes itself between apprehension and truth like a dusty pane or warped mirror. The tongue of Eden was like a flawless glass; a light of total understanding streamed through it. Thus Babel was a second Fall.’ And Isaac the Blind, an early Kabbalist, said that, to quote Gershom Scholem’s translation, ‘The speech of men is connected with divine…

Write a Test Case

Your application just broke, oh no! It couldn’t have been your code, right? I’ve always had trouble spotting mistakes in my own work such as spelling, grammar, mathematical, or even in programming. With spelling or grammar, office applications quickly pick up on my mistakes and underline them for me, but most of my mistakes come from my own hubris. I’m confident in what I do, and…

Function.prototype.bind Edge Cases

ECMAScript 5’s Function.prototype.bind is a great tool that’s implemented in all modern browser JavaScript engines. It allows you to modify the context, this, of a function when it is evaluated in the future. Knowing what this refers to in various contexts is key to being a professional JavaScript developer; don’t show up to an interview without knowing all about it. Here’s…

Making Great Node.js Modules With Coffeescript

Node.js is a great runtime for writing applications in JavaScript, the language I primarily develop in. CoffeeScript is a programming language that compiles to JavaScript. Why would we write a reusable piece of code, a module , in CoffeeScript? CoffeeScript is a very high level language and beautifully brings together my favorite aspects of JavaScript, Ruby, and Python. In this tutorial,…

Designated Initialization With Compound Literals in C

Just a quick post on something I just discovered and found neat (I always find obscure C syntax interesting). I was trying to figure out how to use a C designated initializer, where a member was a pointer to another designated initializer. At this point, you need a compound literal. Just a quick background on C initialization: // verbosely create an array with a known size int arr [3]; arr[0] = 1;…

Why I'll Be Marching This 4th

If you’ve done nothing wrong, then you’ve got nothing to hide. Wrong. Nothing ever justifies giving up your human rights , especially to prove lack of wrong doing, and any government that asks you to do so is not your friend. Terrorism has become a weapon used against us by those elected to lead to keep us compliant, like blinders you’d put on a horse. The threat just keeps…

8 Months in Mozilla

Besides 3 months interrupted to finish degree requirements, and including an internship, I’ve been at Mozilla for about 8 months now. After reading a blog post of another software engineer’s experience at Microsoft, I count my blessings. Reading that article set off too many alarms in my head. It was well written, and I sugguest you go read it, but my takeaway was that that any big name…

Rust: Pattern Matching and the Option Type

The other day I was thinking about the function for performing dynamic memory allocation in the C standard library, malloc. From the manual pages, If successful, the malloc() function returns a pointer to allocated memory. If there is an error, it returns a NULL pointer and sets errno to ENOMEM. One of the most common errors when using malloc is not checking for allocation failure. The allocation…

The Persistence of Memory

I would like to die on Mars… Elon Musk Elon Musk, the 21st Century Industrialist, Bloomberg Well, isn’t that forward thinking? Granted, the full quote I would like to die on Mars, just not on impact is meant to sound hopeful of his company, SpaceX. I agree that some day, humans will be buried on Mars. But is it forward thinking, enough? Does it push the needle to where it needs to be…

Basic JIT

Ever since I learned about Just In Time Compilation from the various Ruby VMs and JavaScript VMs, I’ve been inspired. I could tell you all about how just in time (JIT) compilation worked, and how it could give your interpreted language a speed boost. It was so cool. Well, it still is! There’s a ton of research going on around JIT compilation. But the problem for me is that I could…

Commandments of a Mobile Web

Over the past few years, there’s been certain paradigm shifts in web development. When you think of milestones that really changed how development on the web was done, the two biggest were Ajax and HTML5. Development was identifiably different before and after such technological advancements. There were some who initially doubted the technologies, but I’m sure such doubters eventually…

C Function Pointers Alternate Syntax

On an interview with Square, I made the mistake of stating that one of the benefits of working with JavaScript over C is that functions are first class in JavaScript, therefore they may be passed around. To which the interviewer replied, “Well, C can do that, what about function pointers?” What? Luckily, I was able to get out of that jam by guessing that JavaScript had a nicer syntax.…

[Internet] Freedom Is Not Free

Last week, the Internet community lost a member in the on going war against the copyright industry. While I’ve never met the deceased, or even heard of the deceased before his suicide, I’m horrified. I’m horrified that the government we are asked to put so much faith in, would give someone, not that different from myself, such a ridiculous sentence. That I could be thrown away,…

Closures: JavaScript, Ruby, and Rust

It’s all about closures. Understanding scope is paramount to coding. What can you access and what can’t you access. Closures allow us to access variables that otherwise might be awkward to pass into a function. Closures can help us out of tricky situations, but can confuse those from backgrounds with (typically) statically typed languages that may not support closing over variables.…

About

Nick Desaulniers is a software engineer at Google working on compiling the Linux Kernel with Clang (and LLVM). Nick has previously worked on TensorFlow’s Accelerated Linear Algebra (XLA) JIT compiler for Tensor Processing Units (TPUs), and the Linux kernel for the Nexus and Pixel phones while at Google. Nick also hacked on open source projects like Firefox, Firefox OS, Emscripten, and Rust…

Blog Archive

2023 Mar 10 USPS as an ISP 2023 Mar 10 Disambiguating Arm, Arm ARM, Armv9, ARM9, ARM64, AArch64, A64, A78, ... 2023 Feb 1 Forking is not free; the hidden costs 2023 Jan 27 Critical Edge Splitting 2023 Jan 20 Debugging -Wframe-larger-than= 2020 Apr 6 Off by Two 2019 May 12 f() vs f(void) in C vs C 2019 Jan 18 Finding Compiler Bugs With C-Reduce 2018 Oct 24 Booting a Custom Linux Kernel in QEMU and…

Publications

Desaulniers, Nick. “WebGL Off the Main Thread.” Mozilla Hacks. Mozilla. January 22, 2015. Link Desaulniers, Nick. “Better than Gzip Compression with Brotli.” Mozilla Hacks. Mozilla. November 6, 2015. Link Desaulniers, Nick. “Stereoscopic Rendering in WebVR.” Mozilla Hacks. Mozilla. September 16, 2015. Link Desaulniers, Nick. “Streaming media on demand with…

Talks

2019 Compiling the Linux Kernel with LLVM Tools FOSDEM ‘19’ - Brussels, Belgium - February 2-3 slides - video 2018 Compiling the Linux Kernel with Clang Linux Plumbers Conference 2018 - Vancouver, Canada - November 13-15 slides - video 2017 Compiling Android Userspace and Linux Kernel with LLVM 2017 US LLVM Developers’ Meeting - San Jose, CA - October 18-19 abstract - video Clang…