Bug 233481 - flex/lex: __dead2 define in flex.skl precludes cross compiles for embedded systems
Summary: flex/lex: __dead2 define in flex.skl precludes cross compiles for embedded sy...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.2-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2018-11-24 21:13 UTC by Craig Leres
Modified: 2018-11-24 21:14 UTC (History)
0 users

See Also:

patch (537 bytes, patch)
2018-11-24 21:14 UTC, Craig Leres
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Craig Leres freebsd_committer 2018-11-24 21:13:49 UTC
We're unable to compile a lex generated module for the openvehicles.com project with the devel/xtensa-esp32-elf toolchain. The problem is the flex/lex generated code unconditionally defines __dead2 when !defined(__FreeBSD__):

    In file included from /home/leres/esp/openvehicles-xtensa-esp32-elf/components/newlib/include/stdio.h:35:0,
                     from /home/leres/src/Open-Vehicle-Monitoring-System-3/vehicle/OVMS.V3/components/dbc/yacclex/dbc_tokeniser.c:30:
    /home/leres/esp/openvehicles-xtensa-esp32-elf/components/newlib/include/sys/cdefs.h:246:0: warning: "__dead2" redefined
     #define __dead2  __attribute__((__noreturn__))
    /home/leres/src/Open-Vehicle-Monitoring-System-3/vehicle/OVMS.V3/components/dbc/yacclex/dbc_tokeniser.c:26:0: note: this is the location of the previous definition
     #define __dead2

The problem is the generated code unconditionally defines __dead2:

    /* First, we deal with  platform-specific or compiler-specific issues. */

    #if defined(__FreeBSD__)
    #ifndef __STDC_LIMIT_MACROS
    #define __STDC_LIMIT_MACROS
    #include <sys/cdefs.h>
    #include <stdint.h>
    #define __dead2

And then later includes stdio.h:

    /* begin standard C headers. */
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>
    #include <stdlib.h>

    /* end standard C headers. */

But stdio.h causes the xtensa-esp32-elf version sys/cdefs.h to be included which defines __dead2 for the second time:

    #if __GNUC_PREREQ__(2, 7)
    #define __dead2         __attribute__((__noreturn__))

The only workaround is to do hacky post-processing on the generated code (or perhaps use the textproc/flex port which does not patch the standard flex.skl file).

The attached patch moves the __dead2 define after the "standard C headers" are included and only attempts to define __dead2 if it is not already defined.
Comment 1 Craig Leres freebsd_committer 2018-11-24 21:14:12 UTC
Created attachment 199525 [details]