Search code examples
gccsegmentation-faultarmu-bootdevice-tree

compiler segfault when printf is added (gcc 10.2 aarch64_none-elf- from arm)


I know this is not adequate for stack overflow question, but ..
This is a function in scripts/dtc/libfdt/fdt_ro.c of u-boot v2021.10.

const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
                const char *name, int namelen, int *lenp)
{
    int poffset;
    const struct fdt_property *prop;

    printf("uuu0 nodeoffset = 0x%x, name = %s, namelen = %d\n", nodeoffset, name, namelen);
    prop = fdt_get_property_namelen_(fdt, nodeoffset, name, namelen, lenp,
                     &poffset);
    //printf("uuu1 prop = 0x%lx, *lenp = 0x%x, poffset = 0x%x\n", prop, *lenp, poffset);
    if (!prop)
        return NULL;

    /* Handle realignment */
    if (fdt_chk_version() && fdt_version(fdt) < 0x10 &&
        (poffset + sizeof(*prop)) % 8 && fdt32_to_cpu(prop->len) >= 8)
        return prop->data + 4;
    return prop->data;
}

When I build the program, if I uncomment the second printf, the compiler seg-faults.
I have no idea. Is it purely compiler problem(I think so it should never die at least)? or can it be linked to my fault somewhere in another code? Is there any method to know the cause of the segfault? (probably not.).


Solution

  • If you're getting a segmentation fault when running the compiler itself, the compiler has a bug. There are some errors in your code, but those should result in compile-time diagnostics (warnings or error messages), never a compile-time crash.

    The code in your question is incomplete (missing declarations for fdt_get_property_namelen_, printf, NULL, etc.). Reproduce the problem with a complete self-contained source file and submit a bug report: https://gcc.gnu.org/bugzilla/