Closed FictionIO closed 6 years ago
You shouldn't need to run with RENDERDOC_LOGFILE
, that env var is only intended for internal use.
I think what's happening is the library_loaded()
function is being called before other global constructors, including the std::string logfile
that's getting assigned to in rdclog_filename
. Why that is though, I'm not sure.
What's your reasoning for disabling XCB (and disabling then enabling xlib) ? Can you try again with a default build with no options set, just to test?
Also to clarify, which GCC version are you using, 4.9.1 or 6.4.0?
Sure. Thank you. Will only use qrenderdoc
in the future.
Apologies for XLib flags. I believe it was a copy/paste error, fixed.
Sadly we don't have XCB on our systems and had no time to prepare it for this build. Is this is an issue?
I tried GCC's both versions 4.9.1 and 6.4.0.
I had to point RENDERDOC_SWIG_PACKAGE to a local file because our build environment does not permit downloading an online content.
I believe everything should work without XCB. If your system is missing it then that's OK, I believe some vulkan drivers only advertise XCB so disabling support in renderdoc would make it impossible to replay properly, but if it's missing at a system level you probably aren't in that boat.
Setting RENDERDOC_SWIG_PACKAGE
and RENDERDOC_SWIG_PACKAGE
is fine, they are intended to be customised for any build as needed.
I'd suggest sticking with 6.4.0 for any testing, 4.9.1 might work but I generally use gcc5 as a minimum since some of the 4.x series don't work and I don't remember where the cut-off is.
Are you able to run one of my nightly builds, just to see if that works? That would eliminate something runtime vs. something build-time - my guess is the problem is build-time.
Also as a test to see if it is global constructor order related, can you add this code just above the declaration of rdclog_filename()
in common.cpp
:
struct test
{
test() { fprintf(stderr, "test()\n"); fflush(stderr); }
} do_test;
Then a similar fprintf()
in library_loaded()
. Then we'd see which message is printed first.
I got library_loaded
called first.
My changes to common.cpp
struct test
{
test() { fprintf(stderr, "test()\n"); fflush(stderr); }
} do_test;
void rdclog_filename(const char *filename)
{
string previous = logfile;
logfile = "";
if(filename && filename[0])
logfile = filename;
FileIO::logfile_close(NULL);
logfileOpened = false;
if(!logfile.empty())
{
logfileOpened = FileIO::logfile_open(logfile.c_str());
if(logfileOpened && previous.c_str())
{
vector<unsigned char> previousContents;
FileIO::slurp(previous.c_str(), previousContents);
if(!previousContents.empty())
FileIO::logfile_append((const char *)&previousContents[0], previousContents.size());
FileIO::Delete(previous.c_str());
}
}
}
My changes to posix_libentry.cpp
// DllMain equivalent
void library_loaded()
{
fprintf(stderr, "library_loaded()\n"); fflush(stderr);
....
....
GDB Log:
bash-4.2$ SHELL=/bin/sh gdb --args qrenderdoc
GNU gdb (GDB) 8.0
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from qrenderdoc...rundone.
(gdb) run
Starting program: /builds/renderdoc/1.x.16012018/2ab48ab3d9/bin/qrenderdoc
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
library_loaded()
Program received signal SIGSEGV, Segmentation fault.
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (this=0x7fffffff7288, __str=<error reading variable: Cannot access memory at address 0xffffffffffffffe8>)
at /user_data/.tmp/build/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:613
613 /user_data/.tmp/build/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc: No such file or directory.
(gdb) bt
#0 std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (this=0x7fffffff7288, __str=<error reading variable: Cannot access memory at address 0xffffffffffffffe8>)
at /user_data/.tmp/build/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:613
#1 0x00007ffff71b843e in rdclog_filename(char const*) () from /builds/renderdoc/1.x.16012018/2ab48ab3d9/bin/../lib/librenderdoc.so
#2 0x00007ffff71bd613 in RenderDoc::Initialise() () from /builds/renderdoc/1.x.16012018/2ab48ab3d9/bin/../lib/librenderdoc.so
#3 0x00007ffff738c3bf in library_loaded() () from /builds/renderdoc/1.x.16012018/2ab48ab3d9/bin/../lib/librenderdoc.so
#4 0x00007ffff738c726 in __do_global_ctors_aux () from /builds/renderdoc/1.x.16012018/2ab48ab3d9/bin/../lib/librenderdoc.so
#5 0x0000000000000001 in ?? ()
#6 0x0000000000000001 in ?? ()
#7 0x00007fffffff7408 in ?? ()
#8 0x00007ffff6be91fb in _init () from /builds/renderdoc/1.x.16012018/2ab48ab3d9/bin/../lib/librenderdoc.so
#9 0x0000000000000009 in ?? ()
#10 0x00007ffff7dea4bf in _dl_init_internal () from /lib64/ld-linux-x86-64.so.2
#11 0x00007ffff7ddc1aa in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#12 0x0000000000000001 in ?? ()
#13 0x00007fffffff8304 in ?? ()
#14 0x0000000000000000 in ?? ()
(gdb)
Yeh that's the cause of the crash then, the string isn't initialised when we try to use it, so it explodes. Technically the order of global constructors is undefined between translation units like that, but AFAIK gcc/clang should do it based on link order - so I have posix_libentry.cpp listed last in the list of sources to have library_loaded()
called last.
Normally it's a bad idea to rely on this behaviour, but I don't have much alternative since I need something that will execute and initialise as soon as the library is loaded in the target process. On windows this is provided nicely with DllMain, but linux doesn't have an equivalent - you have to use global constructors, which then lead to problems like this.
Can you run a verbose make (make --trace
) and ensure that the file is still last for you? Maybe something bizarre has happened and the order has gotten muddled. You should get a final link line something like:
/usr/bin/c++ -fPIC -std=c++11 ... other flags ... -Wl,--no-undefined -shared -Wl,-soname,librenderdoc.so -o ../bin/librenderdoc.so CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/blit.vert.c.o ... a lot of other files ... CMakeFiles/rdoc.dir/os/posix/posix_stringio.cpp.o CMakeFiles/rdoc.dir/os/posix/posix_threading.cpp.o CMakeFiles/rdoc.dir/os/posix/posix_libentry.cpp.o -lm -ldl -lrt -lpthread -lX11 -lxcb -lxcb-keysyms
I had CMAKE_VERBOSE_MAKEFILE
already turned on. I confirm its the last linked file.
/builds/gcc/6.4.0/9a8a21199e/bin/c++ -fPIC -std=c++11 -fstrict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-result -Wno-type-limits -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -O3 -DNDEBUG -Wl,--version-script,/user_data/.tmp/build/renderdoc/renderdoc.version -Wl,--no-undefined -shared -Wl,-soname,librenderdoc.so -o ../bin/librenderdoc.so CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/blit.vert.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/checkerboard.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/debuguniforms.h.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/fixedcol.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/histogram.comp.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/mesh.comp.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/mesh.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/mesh.geom.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/mesh.vert.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/minmaxresult.comp.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/minmaxtile.comp.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/outline.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/quadresolve.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/quadwrite.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/texdisplay.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/gl_texsample.h.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/gles_texsample.h.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/vk_texsample.h.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/text.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/text.vert.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/array2ms.comp.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/ms2array.comp.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/trisize.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/trisize.geom.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/deptharr2ms.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/glsl/depthms2arr.frag.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/data/sourcecodepro.ttf.c.o CMakeFiles/renderdoc.dir/CMakeFiles/data.src/driver/vulkan/renderdoc.json.c.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_common.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_counters.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_debug.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_driver.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_initstate.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_manager.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_renderstate.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_replay.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_resources.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_program_iterate.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_shader_refl.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_stringise.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_buffer_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_debug_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_draw_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_emulated.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_framebuffer_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_get_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_interop_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_query_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_sampler_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_shader_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_state_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_texture_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/wrappers/gl_uniform_funcs.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_hooks_linux_shared.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_replay_linux.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/glx_hooks_linux.cpp.o driver/gl/CMakeFiles/rdoc_gl.dir/gl_hooks_linux.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_common.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_core.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_counters.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_debug.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_dispatchtables.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_info.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_initstate.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_sparse_initstate.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_manager.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_memory.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_replay.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_resources.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_state.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_serialise.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_stringise.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_layer.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_cmd_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_descriptor_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_device_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_draw_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_dynamic_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_get_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_misc_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_queue_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_resource_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_shader_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_sync_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/wrappers/vk_wsi_funcs.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_posix.cpp.o driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_linux.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/spirv_common.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/spirv_compile.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/spirv_disassemble.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/spirv_stringise.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/OGLCompilersDLL/InitializeDll.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/GlslangToSpv.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/InReadableOrder.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/Logger.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/SpvBuilder.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/hlsl/hlslAttributes.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/hlsl/hlslParseHelper.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/hlsl/hlslOpMap.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/hlsl/hlslParseables.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/hlsl/hlslScanContext.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/hlsl/hlslGrammar.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/hlsl/hlslTokenStream.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/GenericCodeGen/CodeGen.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/GenericCodeGen/Link.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/Constant.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/glslang_tab.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/iomapper.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/InfoSink.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/Initialize.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/Intermediate.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/intermOut.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/IntermTraverse.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/limits.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/parseConst.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/ParseContextBase.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/PoolAlloc.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/propagateNoContraction.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/reflection.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/RemoveTree.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/Scan.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/Versions.cpp.o driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/OSDependent/Unix/ossource.cpp.o driver/ihv/amd/CMakeFiles/rdoc_amd.dir/amd_isa.cpp.o driver/ihv/amd/CMakeFiles/rdoc_amd.dir/amd_isa_devices.cpp.o driver/ihv/amd/CMakeFiles/rdoc_amd.dir/amd_isa_posix.cpp.o CMakeFiles/rdoc.dir/common/common.cpp.o CMakeFiles/rdoc.dir/common/dds_readwrite.cpp.o CMakeFiles/rdoc.dir/core/core.cpp.o CMakeFiles/rdoc.dir/core/image_viewer.cpp.o CMakeFiles/rdoc.dir/core/target_control.cpp.o CMakeFiles/rdoc.dir/core/remote_server.cpp.o CMakeFiles/rdoc.dir/core/replay_proxy.cpp.o CMakeFiles/rdoc.dir/core/android.cpp.o CMakeFiles/rdoc.dir/core/plugins.cpp.o CMakeFiles/rdoc.dir/core/resource_manager.cpp.o CMakeFiles/rdoc.dir/data/glsl_shaders.cpp.o CMakeFiles/rdoc.dir/hooks/hooks.cpp.o CMakeFiles/rdoc.dir/maths/camera.cpp.o CMakeFiles/rdoc.dir/maths/matrix.cpp.o CMakeFiles/rdoc.dir/os/os_specific.cpp.o CMakeFiles/rdoc.dir/replay/app_api.cpp.o CMakeFiles/rdoc.dir/replay/basic_types_tests.cpp.o CMakeFiles/rdoc.dir/replay/capture_options.cpp.o CMakeFiles/rdoc.dir/replay/capture_file.cpp.o CMakeFiles/rdoc.dir/replay/entry_points.cpp.o CMakeFiles/rdoc.dir/replay/replay_driver.cpp.o CMakeFiles/rdoc.dir/replay/replay_output.cpp.o CMakeFiles/rdoc.dir/replay/replay_controller.cpp.o CMakeFiles/rdoc.dir/serialise/serialiser.cpp.o CMakeFiles/rdoc.dir/serialise/lz4io.cpp.o CMakeFiles/rdoc.dir/serialise/zstdio.cpp.o CMakeFiles/rdoc.dir/serialise/streamio.cpp.o CMakeFiles/rdoc.dir/serialise/rdcfile.cpp.o CMakeFiles/rdoc.dir/serialise/codecs/xml_codec.cpp.o CMakeFiles/rdoc.dir/serialise/codecs/chrome_json_codec.cpp.o CMakeFiles/rdoc.dir/serialise/comp_io_tests.cpp.o CMakeFiles/rdoc.dir/serialise/serialiser_tests.cpp.o CMakeFiles/rdoc.dir/serialise/streamio_tests.cpp.o CMakeFiles/rdoc.dir/strings/grisu2.cpp.o CMakeFiles/rdoc.dir/strings/string_utils.cpp.o CMakeFiles/rdoc.dir/strings/utf8printf.cpp.o CMakeFiles/rdoc.dir/3rdparty/jpeg-compressor/jpgd.cpp.o CMakeFiles/rdoc.dir/3rdparty/jpeg-compressor/jpge.cpp.o CMakeFiles/rdoc.dir/3rdparty/catch/catch.cpp.o CMakeFiles/rdoc.dir/3rdparty/pugixml/pugixml.cpp.o CMakeFiles/rdoc.dir/3rdparty/lz4/lz4.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/entropy_common.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/error_private.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/fse_decompress.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/pool.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/threading.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/xxhash.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/zstd_common.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/fse_compress.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/huf_compress.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/zstdmt_compress.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/zstd_compress.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/huf_decompress.c.o CMakeFiles/rdoc.dir/3rdparty/zstd/zstd_decompress.c.o CMakeFiles/rdoc.dir/3rdparty/stb/stb_impl.c.o CMakeFiles/rdoc.dir/3rdparty/tinyexr/tinyexr.cpp.o CMakeFiles/rdoc.dir/3rdparty/tinyfiledialogs/tinyfiledialogs.c.o CMakeFiles/rdoc.dir/os/posix/linux/linux_stringio.cpp.o CMakeFiles/rdoc.dir/os/posix/linux/linux_callstack.cpp.o CMakeFiles/rdoc.dir/os/posix/linux/linux_process.cpp.o CMakeFiles/rdoc.dir/os/posix/linux/linux_threading.cpp.o CMakeFiles/rdoc.dir/os/posix/linux/linux_hook.cpp.o CMakeFiles/rdoc.dir/os/posix/linux/linux_network.cpp.o CMakeFiles/rdoc.dir/3rdparty/plthook/plthook_elf.c.o CMakeFiles/rdoc.dir/os/posix/posix_network.cpp.o CMakeFiles/rdoc.dir/os/posix/posix_process.cpp.o CMakeFiles/rdoc.dir/os/posix/posix_stringio.cpp.o CMakeFiles/rdoc.dir/os/posix/posix_threading.cpp.o CMakeFiles/rdoc.dir/os/posix/posix_libentry.cpp.o -lm -ldl -lrt -lpthread -lX11
As for global constructors, can't we ensure correct ordering by just:
std::string & logfile()
{
static std::string static_logfile;
return static_logfile;
}
void rdclog_filename(const char *filename)
{
string previous = logfile();
...
In this case that would probably work yes, but there are other cases I can think of e.g. where library hooks are globally registered, which need to be registered before the initialisation happens. Try adding a print in OpenGLHook()
in gl_hooks_linux.cpp
. If that is called after library_loaded then fixing the logfile would still lead to a broken library that won't hook properly.
Building test for OpenGLHook()
I have a feeling we can fix these issues with some restructuring to how we initialise the library. We need two rules:
This will guarantee correct initialisation order, makes project simpler to debug (for this kind of problems), and decouples project's build link order and run-time behaviour.
Probably I need to spend more time on the structure of the project. I'm totally new. Apologies if this makes no sense.
It does make sense, but I don't want to make a large-scale restructure like that to workaround a problem on one particular case. Even aside from linked third party code that wouldn't follow this pattern, it would add ugly coupling between code that shouldn't be needed.
The code already uses a singleton pattern for lazy initialisation in many cases, e.g. LibraryHooks::GetInstance()
or RenderDoc::Inst()
where this might be needed. If there was a complex general many:many initialisation order problem then it would be worth trying to tidy that up, but I only have one need - running the actual initialisation code last after the rest of the init, which can happen in any order.
I'd first like to try to figure out why you're encountering this problem - if this were a general problem I'd expect other people to run into it. If we can figure that out, then we can figure out what's an appropriate solution.
From this stackoverflow answer the behaviour should be that constructors are called in link order. It seems like this behaviour changed in GCC 4.7 and previously it was in reverse order (which I didn't know), so I wonder if your GCC has some patches applied that diverge from upstream. Could you paste /usr/bin/c++ -v
so we can see the exact version/configure string, maybe that would shed some light.
As mentioned in the SO answer can you try running the link command that you pasted above and appending -Wl,--print-map
. Look in the output for .init_array
. E.g. I get:
cd build/renderdoc
/usr/bin/c++ -fPIC -std=c++11 .... -Wl,--print-map | grep .init_array
.init_array 0x0000000000ba59a8 0xc8
*(SORT(.init_array.*) SORT(.ctors.*))
*(.init_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .ctors)
.init_array 0x0000000000ba59a8 0x8 /usr/lib/gcc/x86_64-linux-gnu/6/crtbeginS.o
.init_array 0x0000000000ba59b0 0x8 driver/gl/CMakeFiles/rdoc_gl.dir/gl_driver.cpp.o
.init_array 0x0000000000ba59b8 0x8 driver/gl/CMakeFiles/rdoc_gl.dir/gl_replay.cpp.o
.init_array 0x0000000000ba59c0 0x8 driver/gl/CMakeFiles/rdoc_gl.dir/gl_hooks_linux_shared.cpp.o
.init_array 0x0000000000ba59c8 0x8 driver/gl/CMakeFiles/rdoc_gl.dir/gl_hooks_linux.cpp.o
.init_array 0x0000000000ba59d0 0x8 driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_dispatchtables.cpp.o
.init_array 0x0000000000ba59d8 0x8 driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_replay.cpp.o
.init_array 0x0000000000ba59e0 0x8 driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_resources.cpp.o
.init_array 0x0000000000ba59e8 0x8 driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_layer.cpp.o
.init_array 0x0000000000ba59f0 0x8 driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/GlslangToSpv.cpp.o
.init_array 0x0000000000ba59f8 0x8 driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/InReadableOrder.cpp.o
.init_array 0x0000000000ba5a00 0x8 driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/SpvBuilder.cpp.o
.init_array 0x0000000000ba5a08 0x8 driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp.o
.init_array 0x0000000000ba5a10 0x8 driver/ihv/amd/CMakeFiles/rdoc_amd.dir/amd_isa.cpp.o
.init_array 0x0000000000ba5a18 0x8 CMakeFiles/rdoc.dir/common/common.cpp.o
.init_array 0x0000000000ba5a20 0x8 CMakeFiles/rdoc.dir/core/android.cpp.o
.init_array 0x0000000000ba5a28 0x8 CMakeFiles/rdoc.dir/maths/matrix.cpp.o
.init_array 0x0000000000ba5a30 0x8 CMakeFiles/rdoc.dir/serialise/zstdio.cpp.o
.init_array 0x0000000000ba5a38 0x8 CMakeFiles/rdoc.dir/serialise/codecs/xml_codec.cpp.o
.init_array 0x0000000000ba5a40 0x8 CMakeFiles/rdoc.dir/serialise/codecs/chrome_json_codec.cpp.o
.init_array 0x0000000000ba5a48 0x8 CMakeFiles/rdoc.dir/strings/grisu2.cpp.o
.init_array 0x0000000000ba5a50 0x8 CMakeFiles/rdoc.dir/3rdparty/catch/catch.cpp.o
.init_array 0x0000000000ba5a58 0x8 CMakeFiles/rdoc.dir/os/posix/linux/linux_stringio.cpp.o
.init_array 0x0000000000ba5a60 0x8 CMakeFiles/rdoc.dir/os/posix/linux/linux_hook.cpp.o
.init_array 0x0000000000ba5a68 0x8 CMakeFiles/rdoc.dir/os/posix/posix_libentry.cpp.o
Which does match the link order. I'd be interested to see what you get - if it's reversed, or in some other order.
I got library_loaded()
running before OpenGLHook()
GCC version output:
bash-4.2$ c++ -v
Using built-in specs.
COLLECT_GCC=/builds/gcc/6.4.0/9a8a21199e/bin/c++
COLLECT_LTO_WRAPPER=/builds/gcc/6.4.0/9a8a21199e/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.4.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/builds/gcc/6.4.0/0eef0dea2c --disable-multilib --disable-multiarch --enable-__cxa_atexit --with-default-libstdcxx-abi=gcc4-compatible AR_FLAGS=crD --with-pic
Thread model: posix
gcc version 6.4.0 (GCC)
(--with-default-libstdcxx-abi=gcc4-compatible looks suspicious )
Output from link command (grep .init_array):
.preinit_array
*(.preinit_array)
.init_array 0x000000000114dcb0 0x108
*(SORT(.init_array.*) SORT(.ctors.*))
*(.init_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .ctors)
Output from link command (grep .ctor)
.text._ZNK7glslang17TSwizzleSelectorsIiE4sizeEv
.text._ZNK7glslang17TSwizzleSelectorsIiEixEi
.text._ZNK7glslang17TSwizzleSelectorsIiE4sizeEv
.text._ZNK7glslang17TSwizzleSelectorsIiEixEi
.text._ZNK7glslang17TSwizzleSelectorsINS_15TMatrixSelectorEE4sizeEv
.text._ZNK7glslang17TSwizzleSelectorsINS_15TMatrixSelectorEEixEi
.text._ZN7glslang17TSwizzleSelectorsIiE9push_backEi
.text._ZNK7glslang17TSwizzleSelectorsIiE4sizeEv
.text._ZNK7glslang17TSwizzleSelectorsIiEixEi
.text._ZN7glslang17TSwizzleSelectorsIiEC2Ev
.text._ZNK7glslang17TSwizzleSelectorsIiE4sizeEv
.text._ZNK7glslang17TSwizzleSelectorsIiEixEi
.rela.text._ZN7glslang13TIntermediate10addSwizzleIiEEPNS_12TIntermTypedERNS_17TSwizzleSelectorsIT_EERKNS_10TSourceLocE
.rela.text._ZN7glslang13TIntermediate10addSwizzleINS_15TMatrixSelectorEEEPNS_12TIntermTypedERNS_17TSwizzleSelectorsIT_EERKNS_10TSourceLocE
*(.rela.ctors)
.rela.ctors 0x0000000000056a78 0x318 /lib/../lib64/crti.o
0x0000000000385681 glglobalalphafactorssun_renderdoc_hooked(short)
0x00000000007371ce glslang::HlslParseContext::parseMatrixSwizzleSelector(glslang::TSourceLoc const&, std::basic_string<char, std::char_traits<char>, glslang::pool_allocator<char> > const&, int, int, glslang::TSwizzleSelectors<glslang::TMatrixSelector>&)
0x000000000073755a glslang::HlslParseContext::getMatrixComponentsColumn(int, glslang::TSwizzleSelectors<glslang::TMatrixSelector> const&)
.text._ZN7glslang17TSwizzleSelectorsINS_15TMatrixSelectorEE9push_backES1_
0x000000000076ef78 glslang::TSwizzleSelectors<glslang::TMatrixSelector>::push_back(glslang::TMatrixSelector)
.text._ZNK7glslang17TSwizzleSelectorsINS_15TMatrixSelectorEE4sizeEv
0x000000000076efb0 glslang::TSwizzleSelectors<glslang::TMatrixSelector>::size() const
.text._ZNK7glslang17TSwizzleSelectorsINS_15TMatrixSelectorEEixEi
0x000000000076efc0 glslang::TSwizzleSelectors<glslang::TMatrixSelector>::operator[](int) const
.text._ZN7glslang17TSwizzleSelectorsIiEC2Ev
0x000000000076f102 glslang::TSwizzleSelectors<int>::TSwizzleSelectors()
0x000000000076f102 glslang::TSwizzleSelectors<int>::TSwizzleSelectors()
.text._ZNK7glslang17TSwizzleSelectorsIiE4sizeEv
0x000000000076f118 glslang::TSwizzleSelectors<int>::size() const
.text._ZNK7glslang17TSwizzleSelectorsIiEixEi
0x000000000076f128 glslang::TSwizzleSelectors<int>::operator[](int) const
.text._ZN7glslang17TSwizzleSelectorsINS_15TMatrixSelectorEEC2Ev
0x000000000076f16c glslang::TSwizzleSelectors<glslang::TMatrixSelector>::TSwizzleSelectors()
0x000000000076f16c glslang::TSwizzleSelectors<glslang::TMatrixSelector>::TSwizzleSelectors()
.text._ZN7glslang17TSwizzleSelectorsIiE9push_backEi
0x00000000007704d2 glslang::TSwizzleSelectors<int>::push_back(int)
0x00000000007afeec glslang::TIntermediate::foldSwizzle(glslang::TIntermTyped*, glslang::TSwizzleSelectors<int>&, glslang::TSourceLoc const&)
.text._ZN7glslang13TIntermediate10addSwizzleIiEEPNS_12TIntermTypedERNS_17TSwizzleSelectorsIT_EERKNS_10TSourceLocE
0x00000000007e4998 glslang::TIntermTyped* glslang::TIntermediate::addSwizzle<int>(glslang::TSwizzleSelectors<int>&, glslang::TSourceLoc const&)
.text._ZN7glslang13TIntermediate10addSwizzleINS_15TMatrixSelectorEEEPNS_12TIntermTypedERNS_17TSwizzleSelectorsIT_EERKNS_10TSourceLocE
0x00000000007e4a7c glslang::TIntermTyped* glslang::TIntermediate::addSwizzle<glslang::TMatrixSelector>(glslang::TSwizzleSelectors<glslang::TMatrixSelector>&, glslang::TSourceLoc const&)
0x00000000007fbd4e glslang::TParseContextBase::parseSwizzleSelector(glslang::TSourceLoc const&, std::basic_string<char, std::char_traits<char>, glslang::pool_allocator<char> > const&, int, glslang::TSwizzleSelectors<int>&)
.text._ZN7glslang17TSwizzleSelectorsIiE6resizeEi
0x00000000007fc9c2 glslang::TSwizzleSelectors<int>::resize(int)
*(SORT(.init_array.*) SORT(.ctors.*))
*(.init_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .ctors)
.ctors 0x000000000114dcb0 0x8 driver/gl/CMakeFiles/rdoc_gl.dir/gl_common.cpp.o
.ctors 0x000000000114dcb8 0x8 driver/gl/CMakeFiles/rdoc_gl.dir/gl_driver.cpp.o
.ctors 0x000000000114dcc0 0x8 driver/gl/CMakeFiles/rdoc_gl.dir/gl_replay.cpp.o
.ctors 0x000000000114dcc8 0x8 driver/gl/CMakeFiles/rdoc_gl.dir/gl_hooks_linux_shared.cpp.o
.ctors 0x000000000114dcd0 0x8 driver/gl/CMakeFiles/rdoc_gl.dir/gl_hooks_linux.cpp.o
.ctors 0x000000000114dcd8 0x8 driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_core.cpp.o
.ctors 0x000000000114dce0 0x8 driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_dispatchtables.cpp.o
.ctors 0x000000000114dce8 0x8 driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_replay.cpp.o
.ctors 0x000000000114dcf0 0x8 driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_resources.cpp.o
.ctors 0x000000000114dcf8 0x8 driver/vulkan/CMakeFiles/rdoc_vulkan.dir/vk_layer.cpp.o
.ctors 0x000000000114dd00 0x8 driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/GlslangToSpv.cpp.o
.ctors 0x000000000114dd08 0x8 driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/InReadableOrder.cpp.o
.ctors 0x000000000114dd10 0x8 driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/SPIRV/SpvBuilder.cpp.o
.ctors 0x000000000114dd18 0x8 driver/shaders/spirv/CMakeFiles/rdoc_spirv.dir/__/__/__/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp.o
.ctors 0x000000000114dd20 0x8 driver/ihv/amd/CMakeFiles/rdoc_amd.dir/amd_isa.cpp.o
.ctors 0x000000000114dd28 0x8 CMakeFiles/rdoc.dir/common/common.cpp.o
.ctors 0x000000000114dd30 0x8 CMakeFiles/rdoc.dir/core/android.cpp.o
.ctors 0x000000000114dd38 0x8 CMakeFiles/rdoc.dir/maths/matrix.cpp.o
.ctors 0x000000000114dd40 0x8 CMakeFiles/rdoc.dir/os/os_specific.cpp.o
.ctors 0x000000000114dd48 0x8 CMakeFiles/rdoc.dir/replay/basic_types_tests.cpp.o
.ctors 0x000000000114dd50 0x8 CMakeFiles/rdoc.dir/serialise/zstdio.cpp.o
.ctors 0x000000000114dd58 0x8 CMakeFiles/rdoc.dir/serialise/codecs/xml_codec.cpp.o
.ctors 0x000000000114dd60 0x8 CMakeFiles/rdoc.dir/serialise/codecs/chrome_json_codec.cpp.o
.ctors 0x000000000114dd68 0x8 CMakeFiles/rdoc.dir/serialise/comp_io_tests.cpp.o
.ctors 0x000000000114dd70 0x8 CMakeFiles/rdoc.dir/serialise/serialiser_tests.cpp.o
.ctors 0x000000000114dd78 0x8 CMakeFiles/rdoc.dir/serialise/streamio_tests.cpp.o
.ctors 0x000000000114dd80 0x8 CMakeFiles/rdoc.dir/strings/grisu2.cpp.o
.ctors 0x000000000114dd88 0x8 CMakeFiles/rdoc.dir/strings/string_utils.cpp.o
.ctors 0x000000000114dd90 0x8 CMakeFiles/rdoc.dir/strings/utf8printf.cpp.o
.ctors 0x000000000114dd98 0x8 CMakeFiles/rdoc.dir/3rdparty/catch/catch.cpp.o
.ctors 0x000000000114dda0 0x8 CMakeFiles/rdoc.dir/os/posix/linux/linux_stringio.cpp.o
.ctors 0x000000000114dda8 0x8 CMakeFiles/rdoc.dir/os/posix/linux/linux_hook.cpp.o
.ctors 0x000000000114ddb0 0x8 CMakeFiles/rdoc.dir/os/posix/posix_libentry.cpp.o
.ctors 0x000000000114ddb8 0x10
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
.ctors 0x000000000114ddb8 0x8 /builds/gcc/6.4.0/9a8a21199e/bin/../lib/gcc/x86_64-pc-linux-gnu/6.4.0/crtbeginS.o
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
.ctors 0x000000000114ddc0 0x8 /builds/gcc/6.4.0/9a8a21199e/bin/../lib/gcc/x86_64-pc-linux-gnu/6.4.0/crtendS.o
0x00000000011a3f78 unsupported_real_glglobalalphafactorssun
So going by the GCC bug linked from the earlier SO answer it looks to me like your GCC is using the old behaviour from before 4.7 - it's using the .ctors instead of .init_array, which is linked backwards so the last item in the list is the first one initialised - which would tie into the fprintf experiments. My .ctor list looks like:
*(.rela.ctors)
*(SORT(.init_array.*) SORT(.ctors.*))
*(.init_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .ctors)
.ctors
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
Looking at the GCC docs there is a --enable/disable-initfini-array
option which should enable/disable this behaviour, and then if it's omitted "the configure script will try to guess whether the .init_array and .fini_array sections are supported and, if they are, use them.".
I'm not sure if any of the configure options you have implies --disable-initfini-array
, the --with-default-libstdcxx-abi
seems suspicious as you say but I can't see any indication that it would. For what it's worth, my version doesn't include --enable/disable-initfini-array
either but it does have --with-default-libstdcxx-abi=new
.
But my understanding is still that this behaviour is being flipped somehow, I presume due to something in the configuration of your environment. You could check to see if that's the case by removing the list(APPEND sources os/posix/posix_libentry.cpp)
and then add a list(INSERT renderdoc_objects 0 os/posix/posix_libentry.cpp)
immediately before add_library(renderdoc SHARED ${renderdoc_objects})
. I think that should cause posix_libentry.cpp to be linked first - if the theory is correct, that should then cause its constructor to be last.
I confirm default-libstdcxx-abi=gcc4-compatible
has no effect. I was able to get the same error on GCC 7 without this flag.
bash-4.2$ c++ -v
Using built-in specs.
COLLECT_GCC=/builds/gcc/7.1.0/1d6f0982af/bin/c++
COLLECT_LTO_WRAPPER=/builds/gcc/7.1.0/1d6f0982af/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/builds/gcc/7.1.0/4ddf6fa45d --disable-multilib --disable-multiarch --enable-__cxa_atexit AR_FLAGS=crD --with-pic
Thread model: posix
gcc version 7.1.0 (GCC)
Now I have GCC built with --with-default-libstdcxx-abi=new
and --enable-initfini-array
. It does fixes that issue but it seems I have a different problem now. Im not sure if Im still doing everything correctly.
bash-4.2$ c++ -v
Using built-in specs.
COLLECT_GCC=/builds/gcc/6.4.0/6359df24a4/bin/c++
COLLECT_LTO_WRAPPER=/builds/gcc/6.4.0/6359df24a4/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.4.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/builds/gcc/6.4.0/1f2fd7504e --disable-multilib --disable-multiarch --enable-__cxa_atexit --with-default-libstdcxx-abi=new --enable-initfini-array AR_FLAGS=crD --with-pic
Thread model: posix
gcc version 6.4.0 (GCC)
bash-4.2$ SHELL=/bin/sh gdb --args qrenderdoc
GNU gdb (GDB) 8.0
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from qrenderdoc...done.
(gdb) run
Starting program: /builds/renderdoc/1.x.15012018/df8b47058e/bin/qrenderdoc
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
warning: Cannot parse .gnu_debugdata section; LZMA support was disabled at compile time
Log - QRenderDoc initialising.
Fatal - This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, xcb.
Reinstalling the application may fix this problem.
Program received signal SIGILL, Illegal instruction.
0x00007ffff7250a57 in RENDERDOC_LogMessage () from /builds/renderdoc/1.x.15012018/df8b47058e/bin/../lib/librenderdoc.so
(gdb) bt
#0 0x00007ffff7250a57 in RENDERDOC_LogMessage () from /builds/renderdoc/1.x.15012018/df8b47058e/bin/../lib/librenderdoc.so
#1 0x0000000000b48dac in sharedLogOutput (type=QtFatalMsg, context=..., msg=...) at ../../qrenderdoc/Code/qrenderdoc.cpp:61
#2 0x00007ffff4db4738 in ?? () from /builds/qt/5.6.1/156c964dc4/lib/libQt5Core.so.5
#3 0x00007ffff4db5fd6 in QMessageLogger::fatal(char const*, ...) const () from /builds/qt/5.6.1/156c964dc4/lib/libQt5Core.so.5
#4 0x00007ffff58956ba in QGuiApplicationPrivate::createPlatformIntegration() () from /builds/qt/5.6.1/156c964dc4/lib/libQt5Gui.so.5
#5 0x00007ffff589570d in QGuiApplicationPrivate::createEventDispatcher() () from /builds/qt/5.6.1/156c964dc4/lib/libQt5Gui.so.5
#6 0x00007ffff4f97b5b in QCoreApplicationPrivate::init() () from /builds/qt/5.6.1/156c964dc4/lib/libQt5Core.so.5
#7 0x00007ffff5896dec in QGuiApplicationPrivate::init() () from /builds/qt/5.6.1/156c964dc4/lib/libQt5Gui.so.5
#8 0x00007ffff62afb79 in QApplicationPrivate::init() () from /builds/qt/5.6.1/156c964dc4/lib/libQt5Widgets.so.5
#9 0x0000000000b4aab6 in main (argc=1, argv=0x7fffffff7408) at ../../qrenderdoc/Code/qrenderdoc.cpp:216
ASM Layout:
0x7ffff7250a57 <RENDERDOC_LogMessage+55> ud2
The SIGILL is from the fatal error message, that's by design. The real issue is that Qt is saying
This application failed to start because it could not find or load the Qt platform plugin "xcb"
but also
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, xcb.
My guess would be that in compiling renderdoc with a new/different compiler to the rest of your system, it has made it incompatible with the libxcb.so plugin that Qt relies upon, so the library load fails. Though I'm surprised it can still link against the normal Qt libraries.
I'm not sure how to debug that as it's more of a system/Qt issue. Maybe you could try using LD_DEBUG to find out the problem.
I had a friend on CentOS 7 build and run qrenderdoc without any need for a custom gcc or complex steps. He told me he needed to run:
yum install centos-release-scl
yum install devtoolset-7
scl enable devtoolset-7 bash
And build renderdoc from that bash, so the devtoolset-7 tools are first in PATH.
Hi @baldurk ,
Thank you very much for all help.
I can confirm it builds and runs fine with GCC 4.9.1 and 6.4.0 built with --with-default-libstdcxx-abi=new
, --enable-initfini-array
.
As for the QT error I had above, yes It was due to our environment setup. Thanks a lot for pointing that as well.
Sadly I'm unable to install centos-release-scl
or devtoolset-7
. Thanks a lot for mentioning though.
Hey, I'm glad you got it working eventually, sorry you had so many problems. I'll close this issue now then since it seems like you and other centos users should be able to build OK, but let me know if there's something else left to do.
If it becomes possible to refactor in future to remove this dependency on the global constructor order I will try to remember to update you and let you know. For now it's difficult since I have this unusual requirement for a "main" like entry-point, and it's not feasible to eliminate/lazy init all other globals entirely.
One possibility is during the cmake build to construct a tiny test program to see which order the constructors are called in, and modify the build settings appropriately.
The same issue affects the entirety of renderdoc, as available on the Ubuntu 22.04 LTS repos, currently, btw. (Which is version 1.18)
Please do not comment on old issues that have been closed.
If you are encountering a bug or are requesting a feature please open a new issue. You can reference this issue if you wish, but opening a new issue prevents any confusion of accidentally linking two unrelated issues and means that each issue can be handled in a clean process.
Hi,
I hope Im missing something but I'm getting a Segmentation Fault when I launch qrenderdoc on Centos EL7, GCC 4.9.1/6.4.0
I tried launching with both
qrenderdoc
andRENDERDOC_LOGFILE=<some log file path> qrenderdoc
GDB Log:
My build parameters:
Version: https://github.com/baldurk/renderdoc/commit/bbac580c3a81ea1249b69292cd18b2ddb4282c6f