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 #endif #include <sys/cdefs.h> #include <stdint.h> #else #define __dead2 #endif 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.
Created attachment 199525 [details] patch
Looks like the __dead define was removed in April of 2021. commit d37f81e35b6e8f114b04315e06bab2cf0c03946c Author: Alex Richardson <arichardson@FreeBSD.org> Date: Wed Apr 21 10:48:55 2021 +0100 contrib/flex: Drop local __dead2 patch Upstream flex has added a yynoreturn macro, so this diff is no longer needed. Partially reverts r181269. Reviewed By: jkim Differential Revision: https://reviews.freebsd.org/D29679