NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/58115: [RB] usr.bin/config: stabilize ioconf.c output



>Number:         58115
>Category:       bin
>Synopsis:       [RB] usr.bin/config: stabilize ioconf.c output
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 04 23:00:00 +0000 2024
>Originator:     Jan-Benedict Glaw
>Release:        current
>Organization:
>Environment:
NetBSD amd64 + Linux amd64
>Description:
I'm currently working on advancing reproducibility (so that build artifacts when built on a Linux-based host system are the same compared to a NetBSD-hosted build). One difference affecting kernel and modules arise from qsort() usage. While both NetBSD's and GNU's qsort() functions work as expected, it would be nice to get a matching ioconf.c in both cases. (glibc's qsort() keeps the initial order of objects with equal comparison results, while NetBSD's version does not.)

As an example, let's look at sys/modules/spdmem/spdmem.ioconf:

```
spdmem* at iic? addr 0x50
spdmem* at iic? addr 0x51
spdmem* at iic? addr 0x52
spdmem* at iic? addr 0x53
spdmem* at iic? addr 0x54
spdmem* at iic? addr 0x55
spdmem* at iic? addr 0x56
spdmem* at iic? addr 0x57
```

On a NetBSD host, this is generated:
```
[...]
/* locators */
static int loc[8] = {
        0x57, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x50,
};
[...]
static struct cfdata cfdata_ioconf_spdmem[] = {
    /* driver           attachment    unit state      loc   flags  pspec */
/*  0: spdmem* at iic? addr 0x50 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  7,      0, &pspec0 },
/*  1: spdmem* at iic? addr 0x51 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  1,      0, &pspec0 },
/*  2: spdmem* at iic? addr 0x52 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  2,      0, &pspec0 },
/*  3: spdmem* at iic? addr 0x53 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  3,      0, &pspec0 },
/*  4: spdmem* at iic? addr 0x54 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  4,      0, &pspec0 },
/*  5: spdmem* at iic? addr 0x55 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  5,      0, &pspec0 },
/*  6: spdmem* at iic? addr 0x56 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  6,      0, &pspec0 },
/*  7: spdmem* at iic? addr 0x57 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  0,      0, &pspec0 },
    { NULL,             NULL,            0,    0,    NULL,      0, NULL }
};
[...]
```

...while on a Linux host, we see:

```
[...]
/* locators */
static int loc[8] = {
        0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
};
[...]
static struct cfdata cfdata_ioconf_spdmem[] = {
    /* driver           attachment    unit state      loc   flags  pspec */
/*  0: spdmem* at iic? addr 0x50 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  0,      0, &pspec0 },
/*  1: spdmem* at iic? addr 0x51 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  1,      0, &pspec0 },
/*  2: spdmem* at iic? addr 0x52 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  2,      0, &pspec0 },
/*  3: spdmem* at iic? addr 0x53 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  3,      0, &pspec0 },
/*  4: spdmem* at iic? addr 0x54 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  4,      0, &pspec0 },
/*  5: spdmem* at iic? addr 0x55 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  5,      0, &pspec0 },
/*  6: spdmem* at iic? addr 0x56 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  6,      0, &pspec0 },
/*  7: spdmem* at iic? addr 0x57 */
    { "spdmem",         "spdmem_iic",    0, STAR, loc+  7,      0, &pspec0 },
    { NULL,             NULL,            0,    0,    NULL,      0, NULL }
};
[...]
```

The resulting module has a different `loc` array as well as different pointers to it within the `cfdata_ioconf_spdmem` array.
>How-To-Repeat:
Just build a kernel and check generated ioconf.c files.
>Fix:
Extend sorting by eg. also tracking the overall input line number and use that as a sorting key IFF the sorting used right now would result in a "both are the same" result.



Home | Main Index | Thread Index | Old Index