RobertBeckebans / RBDOOM-3-BFG

Doom 3 BFG Edition source port with updated DX12 / Vulkan renderer and modern game engine features
https://www.moddb.com/mods/rbdoom-3-bfg
GNU General Public License v3.0
1.38k stars 251 forks source link

debug builds fail to link for gcc and clang #885

Closed SRSaunders closed 3 weeks ago

SRSaunders commented 3 weeks ago

Due to recent changes in idWaveFile::WriteWaveFormatDirect(), gcc and clang debug builds fail to link because of:

file->WriteBig( format.id );

gcc 13.2.1 Manjaro linux:

/usr/bin/ld: CMakeFiles/RBDoom3BFG.dir/sound/WaveFile.cpp.o: warning: relocation against `_ZN10idWaveFile9waveFmt_t2idE' in read-only section `.text'
/usr/bin/ld: CMakeFiles/RBDoom3BFG.dir/sound/WaveFile.cpp.o: in function `idWaveFile::WriteWaveFormatDirect(idWaveFile::waveFmt_t&, idFile*, bool)':
/home/steve/Documents/RBDOOM-3-BFG/neo/sound/WaveFile.cpp:433:(.text+0x106c): undefined reference to `idWaveFile::waveFmt_t::id'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

clang 16.0.6 Manjaro linux, and Apple clang version 15.0.0 (clang-1500.1.0.2.5):

/usr/bin/ld: CMakeFiles/RBDoom3BFG.dir/sound/WaveFile.cpp.o: in function `idWaveFile::WriteWaveFormatDirect(idWaveFile::waveFmt_t&, idFile*, bool)':
/home/steve/Documents/RBDOOM-3-BFG/neo/sound/WaveFile.cpp:433:(.text+0x1198): undefined reference to `idWaveFile::waveFmt_t::id'
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

An easy workaround that compiles and links everywhere (Win, Linux, Mac) is:

auto id = format.id;
file->WriteBig( id );

The following also works, but you need to duplicate the type info from the declaration:

file->WriteBig( static_cast<const uint32>( format.id ) );

RobertBeckebans commented 3 weeks ago

Strange it worked for me on Kubuntu 23.10 but I haven't tested gcc. Fix is uploaded.

SRSaunders commented 3 weeks ago

Thanks - that approach works too. Note the compile failures were on Debug builds. Release builds worked on linux.

Strange issue - something to do with the template and non-relocatable text sections from the static declaration of format.id (see gcc error above). There might have been a template fix or linker option to handle this, but the code change is easier.