AcademySoftwareFoundation / OpenShadingLanguage

Advanced shading language for production GI renderers
BSD 3-Clause "New" or "Revised" License
2.12k stars 365 forks source link

Build fails with LTO #1810

Open eli-schwartz opened 6 months ago

eli-schwartz commented 6 months ago

I tried to build with the following *FLAGS to optimize the build: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

Note the -Werror=* flags are used to help detect cases where the compiler tries to optimize by assuming UB cannot exist in the source code -- if it does exist, ordinarily the code would be miscompiled, and this says to make the miscompilation a fatal error.

I got this error:

[164/173] : && /usr/bin/x86_64-pc-linux-gnu-g++ -fPIC -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS  -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0  -Wl,--version-script=/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/build-scripts/hidesymbols.map  -Wl,--exclude-libs,ALL -shared -Wl,-soname,liboslexec.so.1.14.1 -o lib/liboslexec.so.1.14.1 src/liboslexec/CMakeFiles/oslexec.dir/shadingsys.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/closure.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/dictionary.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/context.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/instance.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/loadshader.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/master.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opcolor.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opfmt.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opmatrix.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opmessage.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opnoise.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opspline.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opstring.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/optexture.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/oslexec.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/pointcloud.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/rendservices.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/constfold.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/runtimeoptimize.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/typespec.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/lpexp.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/lpeparse.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/automata.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/accum.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opclosure.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/shadeimage.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/backendllvm.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/llvm_gen.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/llvm_instance.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/llvm_util.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/rs_fallback.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/journal.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_analysis.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_backendllvm.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_llvm_gen.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_llvm_instance.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_rendservices.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/ast.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/codegen.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/oslcomp.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/symtab.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/typecheck.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osogram.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osolex.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/oslgram.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osllex.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osl_llvm_compiled_ops.bc.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osl_llvm_compiled_rs_dependent_ops.bc.cpp.o -L/usr/lib/llvm/17/lib64 -Wl,-rpath,/usr/lib/llvm/17/lib64:/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/lib:  lib/liboslquery.so.1.14.1  lib/liboslnoise.so.1.14.1  /usr/lib64/libOpenImageIO.so.2.5.9  -lm  /usr/lib64/libboost_filesystem.so  /usr/lib64/libboost_system.so  /usr/lib64/libboost_thread.so  /usr/lib64/libboost_chrono.so  /usr/lib64/libboost_atomic.so  -ldl  /usr/lib/llvm/17/lib64/libclang-cpp.so  /usr/lib/llvm/17/lib64/libLLVM-17.0.6.so  /usr/lib64/libOpenImageIO_Util.so.2.5.9  /usr/lib64/libImath-3_1.so.29.10.0  -lm  /usr/lib64/libpugixml.so.1.14 && :
FAILED: lib/liboslexec.so.1.14.1 
: && /usr/bin/x86_64-pc-linux-gnu-g++ -fPIC -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS  -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0  -Wl,--version-script=/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/build-scripts/hidesymbols.map  -Wl,--exclude-libs,ALL -shared -Wl,-soname,liboslexec.so.1.14.1 -o lib/liboslexec.so.1.14.1 src/liboslexec/CMakeFiles/oslexec.dir/shadingsys.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/closure.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/dictionary.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/context.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/instance.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/loadshader.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/master.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opcolor.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opfmt.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opmatrix.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opmessage.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opnoise.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opspline.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opstring.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/optexture.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/oslexec.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/pointcloud.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/rendservices.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/constfold.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/runtimeoptimize.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/typespec.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/lpexp.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/lpeparse.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/automata.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/accum.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/opclosure.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/shadeimage.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/backendllvm.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/llvm_gen.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/llvm_instance.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/llvm_util.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/rs_fallback.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/journal.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_analysis.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_backendllvm.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_llvm_gen.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_llvm_instance.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/batched_rendservices.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/ast.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/codegen.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/oslcomp.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/symtab.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/__/liboslcomp/typecheck.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osogram.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osolex.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/oslgram.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osllex.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osl_llvm_compiled_ops.bc.cpp.o src/liboslexec/CMakeFiles/oslexec.dir/osl_llvm_compiled_rs_dependent_ops.bc.cpp.o -L/usr/lib/llvm/17/lib64 -Wl,-rpath,/usr/lib/llvm/17/lib64:/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/lib:  lib/liboslquery.so.1.14.1  lib/liboslnoise.so.1.14.1  /usr/lib64/libOpenImageIO.so.2.5.9  -lm  /usr/lib64/libboost_filesystem.so  /usr/lib64/libboost_system.so  /usr/lib64/libboost_thread.so  /usr/lib64/libboost_chrono.so  /usr/lib64/libboost_atomic.so  -ldl  /usr/lib/llvm/17/lib64/libclang-cpp.so  /usr/lib/llvm/17/lib64/libLLVM-17.0.6.so  /usr/lib64/libOpenImageIO_Util.so.2.5.9  /usr/lib64/libImath-3_1.so.29.10.0  -lm  /usr/lib64/libpugixml.so.1.14 && :
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/llvm_instance.cpp:150:8: error: type ‘struct HelperFuncRecord’ violates the C++ One Definition Rule [-Werror=odr]
  150 | struct HelperFuncRecord {
      |        ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/batched_llvm_instance.cpp:168:8: note: a different type is defined in another translation unit
  168 | struct HelperFuncRecord {
      |        ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/batched_llvm_instance.cpp:171:9: note: the first difference of corresponding definitions is field ‘vector_width’
  171 |     int vector_width;
      |         ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/batched_llvm_instance.cpp:168:8: note: a type with different number of fields is defined in another translation unit
  168 | struct HelperFuncRecord {
      |        ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/osogram.hpp:82:7: error: type ‘union YYSTYPE’ violates the C++ One Definition Rule [-Werror=odr]
   82 | union YYSTYPE
      |       ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/oslgram.hpp:113:7: note: a different type is defined in another translation unit
  113 | union YYSTYPE
      |       ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/osogram.y:47:17: note: the first difference of corresponding definitions is field ‘s’
   47 |     const char *s;  // For string values -- guaranteed to be a ustring.c_str()
      |                 ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/../liboslcomp/oslgram.y:50:17: note: a field with different name is defined in another translation unit
   50 |     ASTNode    *n;  // Abstract Syntax Tree node
      |                 ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/osogram.cpp:474:7: error: type ‘union yyalloc’ violates the C++ One Definition Rule [-Werror=odr]
  474 | union yyalloc
      |       ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/oslgram.cpp:565:7: note: a different type is defined in another translation unit
  565 | union yyalloc
      |       ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/osogram.cpp:476:14: note: the first difference of corresponding definitions is field ‘yyss_alloc’
  476 |   yy_state_t yyss_alloc;
      |              ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/oslgram.cpp:567:14: note: a field of same name but different type is defined in another translation unit
  567 |   yy_state_t yyss_alloc;
      |              ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/osolex.cpp:931:8: error: type ‘struct yyguts_t’ violates the C++ One Definition Rule [-Werror=odr]
  931 | /* Holds the entire state of the reentrant scanner. */
      |        ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/osllex.cpp:957:8: note: a different type is defined in another translation unit
  957 | /* Holds the entire state of the reentrant scanner. */
      |        ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/osolex.cpp:935:19: note: the first difference of corresponding definitions is field ‘yyextra_r’
  935 |     /* User-defined. Not touched by flex. */
      |                   ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/osllex.cpp:961:19: note: a field of same name but different type is defined in another translation unit
  961 |     /* User-defined. Not touched by flex. */
      |                   ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/osoreader.h:27:7: note: type name ‘OSL_v1_14_1::pvt::OSOReader’ should match type name ‘OSL_v1_14_1::pvt::OSLCompilerImpl’
   27 | class OSOReader {
      |       ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/../liboslcomp/oslcomp_pvt.h:36:7: note: the incompatible type is defined here
   36 | class OSLCompilerImpl {
      |       ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:118:1: error: type of ‘osl_allocate_weighted_closure_component’ does not match original declaration [-Werror=lto-type-mismatch]
  118 | DECL(osl_allocate_weighted_closure_component, "CXiiX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:64:1: note: return value type mismatch
   64 | osl_allocate_weighted_closure_component(ShaderGlobals* sg, int id, int size,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:64:1: note: ‘osl_allocate_weighted_closure_component’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:117:1: error: type of ‘osl_allocate_closure_component’ does not match original declaration [-Werror=lto-type-mismatch]
  117 | DECL(osl_allocate_closure_component, "CXii")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:56:1: note: return value type mismatch
   56 | osl_allocate_closure_component(ShaderGlobals* sg, int id, int size)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:56:1: note: ‘osl_allocate_closure_component’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:115:1: error: type of ‘osl_mul_closure_float’ does not match original declaration [-Werror=lto-type-mismatch]
  115 | DECL(osl_mul_closure_float, "CXCf")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:43:1: note: return value type mismatch
   43 | osl_mul_closure_float(ShaderGlobals* sg, ClosureColor* a, float w)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:43:1: note: ‘osl_mul_closure_float’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:116:1: error: type of ‘osl_mul_closure_color’ does not match original declaration [-Werror=lto-type-mismatch]
  116 | DECL(osl_mul_closure_color, "CXCc")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:30:1: note: return value type mismatch
   30 | osl_mul_closure_color(ShaderGlobals* sg, ClosureColor* a, const Color3* w)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:30:1: note: ‘osl_mul_closure_color’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:114:1: error: type of ‘osl_add_closure_closure’ does not match original declaration [-Werror=lto-type-mismatch]
  114 | DECL(osl_add_closure_closure, "CXCC")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:18:1: note: return value type mismatch
   18 | osl_add_closure_closure(ShaderGlobals* sg, const ClosureColor* a,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:18:1: note: ‘osl_add_closure_closure’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:120:1: error: type of ‘osl_closure_to_ustringhash’ does not match original declaration [-Werror=lto-type-mismatch]
  120 | DECL(osl_closure_to_ustringhash, "hXC")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:85:1: note: return value type mismatch
   85 | osl_closure_to_ustringhash(ShaderGlobals* sg, ClosureColor* c)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:85:1: note: type ‘ustringhash_pod’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:85:1: note: ‘osl_closure_to_ustringhash’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:119:1: error: type of ‘osl_closure_to_string’ does not match original declaration [-Werror=lto-type-mismatch]
  119 | DECL(osl_closure_to_string, "sXC")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:74:1: note: return value type mismatch
   74 | osl_closure_to_string(ShaderGlobals* sg, ClosureColor* c)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/opclosure.cpp:74:1: note: ‘osl_closure_to_string’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:206:1: error: type of ‘osl_pointcloud_write’ does not match original declaration [-Werror=lto-type-mismatch]
  206 | DECL(osl_pointcloud_write, "iXhXiXXX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:474:1: note: return value type mismatch
  474 | osl_pointcloud_write(ShaderGlobals* sg, ustringhash_pod filename_,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:474:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:474:1: note: ‘osl_pointcloud_write’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:207:1: error: type of ‘osl_pointcloud_write_helper’ does not match original declaration [-Werror=lto-type-mismatch]
  207 | DECL(osl_pointcloud_write_helper, "xXXXihLX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:460:1: note: type mismatch in parameter 1
  460 | osl_pointcloud_write_helper(ustringhash_pod* names_, TypeDesc* types,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:460:1: note: ‘osl_pointcloud_write_helper’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:205:1: error: type of ‘osl_pointcloud_get’ does not match original declaration [-Werror=lto-type-mismatch]
  205 | DECL(osl_pointcloud_get, "iXhXihLX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:436:1: note: return value type mismatch
  436 | osl_pointcloud_get(ShaderGlobals* sg, ustringhash_pod filename_,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:436:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:436:1: note: ‘osl_pointcloud_get’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:204:1: error: type of ‘osl_pointcloud_search’ does not match original declaration [-Werror=lto-type-mismatch]
  204 | DECL(osl_pointcloud_search, "iXhXfiiXXii*")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:383:1: note: return value type mismatch
  383 | osl_pointcloud_search(ShaderGlobals* sg, ustringhash_pod filename_,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:383:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/pointcloud.cpp:383:1: note: ‘osl_pointcloud_search’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:410:1: error: type of ‘osl_trace’ does not match original declaration [-Werror=lto-type-mismatch]
  410 | DECL(osl_trace, "iXXXXXXXX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:497:1: note: return value type mismatch
  497 | osl_trace(void* sg_, void* opt_, void* Pos_, void* dPosdx_, void* dPosdy_,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:497:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:497:1: note: ‘osl_trace’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:409:1: error: type of ‘osl_trace_set_traceset’ does not match original declaration [-Werror=lto-type-mismatch]
  409 | DECL(osl_trace_set_traceset, "xXh")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:490:1: note: type mismatch in parameter 1
  490 | osl_trace_set_traceset(void* opt, const ustringhash_pod x)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:490:1: note: ‘osl_trace_set_traceset’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:408:1: error: type of ‘osl_trace_set_shade’ does not match original declaration [-Werror=lto-type-mismatch]
  408 | DECL(osl_trace_set_shade, "xXi")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:483:1: note: type mismatch in parameter 1
  483 | osl_trace_set_shade(void* opt, int x)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:483:1: note: ‘osl_trace_set_shade’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:407:1: error: type of ‘osl_trace_set_maxdist’ does not match original declaration [-Werror=lto-type-mismatch]
  407 | DECL(osl_trace_set_maxdist, "xXf")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:477:1: note: type mismatch in parameter 1
  477 | osl_trace_set_maxdist(void* opt, float x)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:477:1: note: ‘osl_trace_set_maxdist’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:406:1: error: type of ‘osl_trace_set_mindist’ does not match original declaration [-Werror=lto-type-mismatch]
  406 | DECL(osl_trace_set_mindist, "xXf")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:471:1: note: type mismatch in parameter 1
  471 | osl_trace_set_mindist(void* opt, float x)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:471:1: note: ‘osl_trace_set_mindist’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:242:1: error: type of ‘osl_get_trace_options’ does not match original declaration [-Werror=lto-type-mismatch]
  242 | DECL(osl_get_trace_options, "XX");
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:462:1: note: return value type mismatch
  462 | osl_get_trace_options(void* sg_)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:462:1: note: ‘osl_get_trace_options’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:404:1: error: type of ‘osl_get_textureinfo_st’ does not match original declaration [-Werror=lto-type-mismatch]
  404 | DECL(osl_get_textureinfo_st, "iXhXffhiiiXX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:430:1: note: return value type mismatch
  430 | osl_get_textureinfo_st(void* sg_, ustringhash_pod name_, void* handle, float s,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:430:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:430:1: note: ‘osl_get_textureinfo_st’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:403:1: error: type of ‘osl_get_textureinfo’ does not match original declaration [-Werror=lto-type-mismatch]
  403 | DECL(osl_get_textureinfo, "iXhXhiiiXX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:403:1: note: return value type mismatch
  403 | osl_get_textureinfo(void* sg_, ustringhash_pod name_, void* handle,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:403:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:403:1: note: ‘osl_get_textureinfo’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:402:1: error: type of ‘osl_environment’ does not match original declaration [-Werror=lto-type-mismatch]
  402 | DECL(osl_environment, "iXhXXXXXiXXXXXXX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:349:1: note: return value type mismatch
  349 | osl_environment(void* sg_, ustringhash_pod name_, void* handle, void* opt_,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:349:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:349:1: note: ‘osl_environment’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:401:1: error: type of ‘osl_texture3d’ does not match original declaration [-Werror=lto-type-mismatch]
  401 | DECL(osl_texture3d, "iXhXXXXXXiXXXXXXX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:286:1: note: return value type mismatch
  286 | osl_texture3d(void* sg_, ustringhash_pod name_, void* handle, void* opt_,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:286:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:286:1: note: ‘osl_texture3d’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:400:1: error: type of ‘osl_texture’ does not match original declaration [-Werror=lto-type-mismatch]
  400 | DECL(osl_texture, "iXhXXffffffiXXXXXXX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:232:1: note: return value type mismatch
  232 | osl_texture(void* sg_, ustringhash_pod name_, void* handle, void* opt_, float s,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:232:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:232:1: note: ‘osl_texture’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:399:1: error: type of ‘osl_texture_set_missingcolor_alpha’ does not match original declaration [-Werror=lto-type-mismatch]
  399 | DECL(osl_texture_set_missingcolor_alpha, "xXif")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:221:1: note: type mismatch in parameter 1
  221 | osl_texture_set_missingcolor_alpha(void* opt, int alphaindex,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:221:1: note: ‘osl_texture_set_missingcolor_alpha’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:398:1: error: type of ‘osl_texture_set_missingcolor_arena’ does not match original declaration [-Werror=lto-type-mismatch]
  398 | DECL(osl_texture_set_missingcolor_arena, "xXX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:215:1: note: type mismatch in parameter 1
  215 | osl_texture_set_missingcolor_arena(void* opt, const void* missing)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:215:1: note: ‘osl_texture_set_missingcolor_arena’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:397:1: error: type of ‘osl_texture_set_subimagename’ does not match original declaration [-Werror=lto-type-mismatch]
  397 | DECL(osl_texture_set_subimagename, "xXh")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:207:1: note: type mismatch in parameter 1
  207 | osl_texture_set_subimagename(void* opt, ustringhash_pod subimagename_)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:207:1: note: ‘osl_texture_set_subimagename’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:396:1: error: type of ‘osl_texture_set_subimage’ does not match original declaration [-Werror=lto-type-mismatch]
  396 | DECL(osl_texture_set_subimage, "xXi")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:200:1: note: type mismatch in parameter 1
  200 | osl_texture_set_subimage(void* opt, int subimage)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:200:1: note: ‘osl_texture_set_subimage’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:395:1: error: type of ‘osl_texture_set_interp_code’ does not match original declaration [-Werror=lto-type-mismatch]
  395 | DECL(osl_texture_set_interp_code, "xXi")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:194:1: note: type mismatch in parameter 1
  194 | osl_texture_set_interp_code(void* opt, int mode)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:194:1: note: ‘osl_texture_set_interp_code’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:394:1: error: type of ‘osl_texture_set_interp’ does not match original declaration [-Werror=lto-type-mismatch]
  394 | DECL(osl_texture_set_interp, "xXh")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:184:1: note: type mismatch in parameter 1
  184 | osl_texture_set_interp(void* opt, ustringhash_pod modename_)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:184:1: note: ‘osl_texture_set_interp’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:373:1: error: type of ‘osl_texture_decode_interpmode’ does not match original declaration [-Werror=lto-type-mismatch]
  373 | DECL(osl_texture_decode_interpmode, "ih");
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:177:1: note: return value type mismatch
  177 | osl_texture_decode_interpmode(ustringhash_pod name_)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:177:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:177:1: note: ‘osl_texture_decode_interpmode’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:393:1: error: type of ‘osl_texture_set_time’ does not match original declaration [-Werror=lto-type-mismatch]
  393 | DECL(osl_texture_set_time, "xXf")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:171:1: note: type mismatch in parameter 1
  171 | osl_texture_set_time(void* opt, float x)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:171:1: note: ‘osl_texture_set_time’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:392:1: error: type of ‘osl_texture_set_fill’ does not match original declaration [-Werror=lto-type-mismatch]
  392 | DECL(osl_texture_set_fill, "xXf")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:165:1: note: type mismatch in parameter 1
  165 | osl_texture_set_fill(void* opt, float x)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/optexture.cpp:165:1: note: ‘osl_texture_set_fill’ was previously declared here

[... and much more, but "There was an error creating your Issue: body is too long (maximum is 65536 characters)." so...]

/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:235:1: error: type of ‘osl_naninf_check’ does not match original declaration [-Werror=lto-type-mismatch]
  235 | DECL(osl_naninf_check, "xiXiXhihiih")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4591:1: note: type mismatch in parameter 1
 4591 | osl_naninf_check(int ncomps, const void* vals_, int has_derivs, void* sg,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4591:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4591:1: note: ‘osl_naninf_check’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:239:1: error: type of ‘osl_incr_get_userdata_calls’ does not match original declaration [-Werror=lto-type-mismatch]
  239 | DECL(osl_incr_get_userdata_calls, "xX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4774:1: note: type mismatch in parameter 1
 4774 | osl_incr_get_userdata_calls(void* sg_)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4774:1: note: ‘osl_incr_get_userdata_calls’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:238:1: error: type of ‘osl_bind_interpolated_param’ does not match original declaration [-Werror=lto-type-mismatch]
  238 | DECL(osl_bind_interpolated_param, "iXhLiXiXiXi")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4735:1: note: return value type mismatch
 4735 | osl_bind_interpolated_param(void* sg_, ustringhash_pod name_, long long type,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4735:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4735:1: note: ‘osl_bind_interpolated_param’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:237:1: error: type of ‘osl_get_attribute’ does not match original declaration [-Werror=lto-type-mismatch]
  237 | DECL(osl_get_attribute, "iXihhiiLX")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4719:1: note: return value type mismatch
 4719 | osl_get_attribute(void* sg_, int dest_derivs, ustringhash_pod obj_name_,
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4719:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4719:1: note: ‘osl_get_attribute’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/builtindecl.h:230:1: error: type of ‘osl_raytype_name’ does not match original declaration [-Werror=lto-type-mismatch]
  230 | DECL(osl_raytype_name, "iXh")
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4708:1: note: return value type mismatch
 4708 | osl_raytype_name(void* sg_, ustringhash_pod name_)
      | ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4708:1: note: type ‘int’ should match type ‘void’
/var/tmp/portage/media-libs/osl-9999/work/osl-9999/src/liboslexec/shadingsys.cpp:4708:1: note: ‘osl_raytype_name’ was previously declared here
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/osogram.cpp:126:6: error: type ‘yysymbol_kind_t’ violates the C++ One Definition Rule [-Werror=odr]
  126 | enum yysymbol_kind_t
      |      ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/oslgram.cpp:129:6: note: an enum with different value name is defined in another translation unit
  129 | enum yysymbol_kind_t
      |      ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/osogram.cpp:134:3: note: name ‘YYSYMBOL_HINT’ differs from name ‘YYSYMBOL_INT_LITERAL’ defined in another translation unit
  134 |   YYSYMBOL_HINT = 5,                       /* HINT  */
      |   ^
/var/tmp/portage/media-libs/osl-9999/work/osl-9999_build/src/liboslexec/oslgram.cpp:137:3: note: mismatching definition
  137 |   YYSYMBOL_INT_LITERAL = 5,                /* INT_LITERAL  */
      |   ^
lto1: some warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/x86_64-pc-linux-gnu-g++ returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Originally reported downstream: https://bugs.gentoo.org/875836 Full build log: build.log

lgritz commented 6 months ago

This looks like various places where we've technically violated the ODR, naming different things the same name in different file scopes, assuming that the compilation units will not interfere with each other. This would ordinarily not be a problem until something like LTO comes along and wants to mash the compilation units together.

I suspect that the solution is going to involve carefully rooting those out and changing the names to be unique. Maybe putting them in anon namespaces in their file scopes will also work?

eli-schwartz commented 6 months ago

places where we've technically violated the ODR [...] This would ordinarily not be a problem until something like LTO comes along

The thing about LTO is that it is "just" a really powerful global optimizer. An ODR violation is an ODR violation either way, and even without LTO it can produce generated code that misbehaves in difficult to detect runtime bugs.

What LTO is also really good at is giving the compiler extremely good whole-program visibility for diagnostics. :)

...

I suspect that the solution is going to involve carefully rooting those out and changing the names to be unique. Maybe putting them in anon namespaces in their file scopes will also work?

I suspect you also want to verify whether they are coincidentally named the same or are supposed to be semantically the same item and the definitions fell out of sync.

The DECL stuff looks suspicious.

The yy* issues can be solved by teaching flex/bison to use prefixes for their internal generated code that are different per file -- such is the peril of code generators. :)

lgritz commented 6 months ago

Does anybody know of a utility that can enumerate all the ODR violations in a codebase?

eli-schwartz commented 4 months ago

Does anybody know of a utility that can enumerate all the ODR violations in a codebase?

Easiest way to do that I guess is via whole-program analysis. Which is what gcc -flto does. :D