Compiling issues
mbelouso opened this issue · comments
Hey guys,
I have the following issue. When compiling with:
make exe -f makefile11
I get the following error after it compiles lots of other things:
/usr/bin/ld: /home/mbelouso/MotionCor3/Lib/libmrcfile.a(CLoadExtHeader.o): relocation R_X86_64_32 against symbol '__gxx_personality_v0@@CXXABI_1.3' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: failed to set dynamic section sizes: bad value collect2: error: ld returned 1 exit status make: *** [makefile11:160: exe] Error 1
gcc and g++ version is 11.4, CUDA 11.8, linux mint 21
Any thoughts?
I had the same issue but adding -Xcompiler -no-pie
to makefile11 in the exe block worked for me (copied from Issue #4)
See #4 (comment) for the full code snippet
@elainehoml Thanks for the heads up. I added these lines to the makefile11, but still run into the same issue. Same error output as in my initial post.
Adding these flags in makefile11 seems to work. A different workaround that worked for me as well was to use GCC 10 instead of GCC 11.
Just to provide more context here, at some point several popular Linux distributions decided to compile their packaged versions of gcc with the -enable-default-pie
option (see here). The version of gcc used isn't as relevant so much as whether or not gcc was compiled with PIE as default. The list of compile options for the particular gcc binary you're using can be found by typing gcc -v
(or g++ -v
in the case of g++
).
A PIE (position independent executable) is a binary compiled with a security measure that is meant to prevent some common buffer overflow attacks; I'm not certain, but I imagine it has become the default due to several high-profile buffer overflow exploits in somewhat recent years (e.g., Heartbleed).
I'm uncertain why PIE binaries can't be produced with NVCC, but some frightfully old CUDA docs provide a clue:
The host linker on Mac OS 10.7 generates position-independent executables by default. As CUDA does not support position-independent executable currently, the linker must generate position-dependent executable by passing in the -no_pie option. If nvcc is being used to link the application, this option will be passed to the linker by default. To override the default behavior, the -Xlinker -pie option can be passed to nvcc.
My educated guess is that modern versions of CUDA still do not support PIE binaries, although I can find no documentation out there to confirm or deny this hypothesis.