Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 03 Dec 2015 08:51:29 -0800
From:      John Baldwin <jhb@freebsd.org>
To:        Erik Cederstrand <erik+lists@cederstrand.dk>
Cc:        freebsd-arch@freebsd.org, Ed Maste <emaste@freebsd.org>
Subject:   Re: Removing build metadata, for reproducible kernel builds
Message-ID:  <1758086.qmdp4H277Z@ralph.baldwin.cx>
In-Reply-To: <B95FC2E1-FCBD-48F6-854C-730906590AE5@cederstrand.dk>
References:  <CAPyFy2AYeN9XNg=b0=JMWDC9ctWarfiZ-5zQorOPhguDJgxYpg@mail.gmail.com> <1920964.NJpSim6qZF@ralph.baldwin.cx> <B95FC2E1-FCBD-48F6-854C-730906590AE5@cederstrand.dk>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday, December 03, 2015 10:28:10 AM Erik Cederstrand wrote:
> 
> > Den 2. dec. 2015 kl. 21.03 skrev John Baldwin <jhb@freebsd.org>:
> > 
> > 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);
                return;
        }
        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 ||
                                    !S_ISREG(st.st_mode))
                                        break;
                        }
                        kernel = strdup(path);
                        break;
                }
        }
        fclose(info);

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
indistinguishable.

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1758086.qmdp4H277Z>