Removing build metadata, for reproducible kernel builds

John Baldwin jhb at
Thu Dec 3 16:57:48 UTC 2015

On Thursday, December 03, 2015 10:28:10 AM Erik Cederstrand wrote:
> > Den 2. dec. 2015 kl. 21.03 skrev John Baldwin <jhb at>:
> > 
> > As I noted in the review, this will break kgdb -n (and possibly crashinfo,
> > less certain about that).  Keeping the path (which should not vary if you
> > build out of the same tree) will be sufficient to let kgdb -n still work
> > (though it may need some changes to recognize both formats).
> Would it be feasible to include the relative build path instead of the absolute path? I seem to remember patches floating around for the __FILE__ macro, but I don't know if (k)gdb can work with relative paths.

This is what kgdb -n does:

         * No kernel image here.  Parse the dump header.  The kernel object
         * directory can be found there and we probably have the kernel
         * image still in it.  The object directory may also have a kernel
         * with debugging info (called kernel.debug).  If we have a debug
         * kernel, use it.
        snprintf(path, sizeof(path), "%s/info.%d", crashdir, nr);
        info = fopen(path, "r");
        if (info == NULL) {
                warn("%s", path);
        while (fgets(path, sizeof(path), info) != NULL) {
                l = strlen(path);
                if (l > 0 && path[l - 1] == '\n')
                        path[--l] = '\0';
                if (strncmp(path, "    ", 4) == 0) {
                        s = strchr(path, ':');
                        s = (s == NULL) ? path + 4 : s + 1;
                        l = snprintf(path, sizeof(path), "%s/kernel.debug", s);
                        if (stat(path, &st) == -1 || !S_ISREG(st.st_mode)) {
                                path[l - 6] = '\0';
                                if (stat(path, &st) == -1 ||
                        kernel = strdup(path);

It basically pulls the path from the 'version' string in the /var/crash/info.X
line, appends 'kernel.debug' to it and sees if there is a file with that
pathname.  If so, it uses it.  This means it doesn't find a kernel in some
/boot/foo, it looks in the build directory.

crashinfo instead finds all the 'kernel' files under /boot, extracts the
version string using gdb from each kernel, and does a string compare with the
version string in info.X.  For this reason, crashinfo will still work if each
string is unique.  However, with the proposal, kernels built with different
kernel configs from the same tree would have the same version string, thus being

A more robust solution than the string compares would be build-id, but that
requires a newer linker which we don't have.

John Baldwin

More information about the freebsd-arch mailing list