build: fix LTO on Linux

Add -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing to
compile and link options for gcc/clang always.

Rename struct yy_buffer_state in src/sdl/expr-lex.cpp to struct
yy_buffer_state_sdl because it breaks when linking the SDL binary with
-Werror=odr.

Fix #1260

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2024-03-30 21:57:26 +00:00
parent cc9a03ce48
commit 3518dc6a05
2 changed files with 22 additions and 16 deletions

View File

@ -2,12 +2,14 @@ if(X86_32 OR X86_64)
add_compile_options(-mfpmath=sse -msse2) add_compile_options(-mfpmath=sse -msse2)
endif() endif()
if(X86_64) if(UPSTREAM_RELEASE)
# Require and optimize for Core2 level support, tune for generic. if(X86_64)
add_compile_options(-march=core2 -mtune=generic) # Require and optimize for Core2 level support, tune for generic.
elseif(X86_32) add_compile_options(-march=core2 -mtune=generic)
# Optimize for pentium-mmx and tune for generic for older builds. elseif(X86_32)
add_compile_options(-march=pentium-mmx -mtune=generic) # Optimize for pentium-mmx and tune for generic for older builds.
add_compile_options(-march=pentium-mmx -mtune=generic)
endif()
endif() endif()
# Common flags. # Common flags.
@ -54,5 +56,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
endif() endif()
if(VBAM_STATIC) if(VBAM_STATIC)
add_link_options("-static-libgcc" "-static-libstdc++" "-Wl,-Bstatic" "-lstdc++" "-lpthread") add_link_options(-static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread)
endif() endif()
# To support LTO, this must always fail.
add_compile_options(-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing)
add_link_options( -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing)

View File

@ -151,7 +151,7 @@ typedef unsigned int flex_uint32_t;
#ifndef YY_TYPEDEF_YY_BUFFER_STATE #ifndef YY_TYPEDEF_YY_BUFFER_STATE
#define YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE
typedef struct yy_buffer_state* YY_BUFFER_STATE; typedef struct yy_buffer_state_sdl* YY_BUFFER_STATE;
#endif #endif
extern int yyleng; extern int yyleng;
@ -184,7 +184,7 @@ typedef size_t yy_size_t;
#ifndef YY_STRUCT_YY_BUFFER_STATE #ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state { struct yy_buffer_state_sdl {
FILE* yy_input_file; FILE* yy_input_file;
char* yy_ch_buf; /* input buffer */ char* yy_ch_buf; /* input buffer */
@ -1218,7 +1218,7 @@ YY_BUFFER_STATE yy_create_buffer(FILE* file, int size)
{ {
YY_BUFFER_STATE b; YY_BUFFER_STATE b;
b = (YY_BUFFER_STATE)yyalloc(sizeof(struct yy_buffer_state)); b = (YY_BUFFER_STATE)yyalloc(sizeof(struct yy_buffer_state_sdl));
if (!b) if (!b)
YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()");
@ -1381,11 +1381,11 @@ static void yyensure_buffer_stack(void)
* immediate realloc on the next call. * immediate realloc on the next call.
*/ */
num_to_alloc = 1; num_to_alloc = 1;
(yy_buffer_stack) = (struct yy_buffer_state**)yyalloc(num_to_alloc * sizeof(struct yy_buffer_state*)); (yy_buffer_stack) = (struct yy_buffer_state_sdl**)yyalloc(num_to_alloc * sizeof(struct yy_buffer_state_sdl*));
if (!(yy_buffer_stack)) if (!(yy_buffer_stack))
YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()"); YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()");
memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state_sdl*));
(yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_max) = num_to_alloc;
(yy_buffer_stack_top) = 0; (yy_buffer_stack_top) = 0;
@ -1398,13 +1398,13 @@ static void yyensure_buffer_stack(void)
int grow_size = 8 /* arbitrary grow size */; int grow_size = 8 /* arbitrary grow size */;
num_to_alloc = (yy_buffer_stack_max) + grow_size; num_to_alloc = (yy_buffer_stack_max) + grow_size;
(yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc((yy_buffer_stack), (yy_buffer_stack) = (struct yy_buffer_state_sdl**)yyrealloc((yy_buffer_stack),
num_to_alloc * sizeof(struct yy_buffer_state*)); num_to_alloc * sizeof(struct yy_buffer_state_sdl*));
if (!(yy_buffer_stack)) if (!(yy_buffer_stack))
YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()"); YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()");
/* zero only the new slots.*/ /* zero only the new slots.*/
memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state_sdl*));
(yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_max) = num_to_alloc;
} }
} }
@ -1423,7 +1423,7 @@ YY_BUFFER_STATE yy_scan_buffer(char* base, yy_size_t size)
/* They forgot to leave room for the EOB's. */ /* They forgot to leave room for the EOB's. */
return 0; return 0;
b = (YY_BUFFER_STATE)yyalloc(sizeof(struct yy_buffer_state)); b = (YY_BUFFER_STATE)yyalloc(sizeof(struct yy_buffer_state_sdl));
if (!b) if (!b)
YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()"); YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()");