NonLinLoc
NonLinLoc copied to clipboard
Build error "relocation truncated to fit: R_X86_64_PC32 against symbol ..."
Until the following commit https://github.com/alomax/NonLinLoc/commit/18b61d1ce47f020e03ddee6f44d9d2334578bd3f, the compiler show the following error when I tried to build on Ubuntu 20.04 LTS:
iori@totoro:~/Codelab/NonLinLoc/src$ make
[ 1%] Built target loclist
[ 2%] Built target phaselist
[ 4%] Built target GridGraphLib
[ 19%] Built target GRID_LIB_OBJS
[ 22%] Built target Grid2GMT
[ 25%] Built target scat2latlon
[ 26%] Built target velmod
[ 29%] Built target Vel2Grid
[ 30%] Built target NLLoc1
[ 40%] Built target NLLOC_LIB_OBJS
[ 43%] Built target NLDiffLoc
[ 45%] Built target Time_3d_NLL
[ 47%] Built target fmm2grid
[ 49%] Linking C executable bin/Loc2ddct
CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o: in function `ConvertLocToCT':
Loc2ddct.c:(.text+0x1d7): relocation truncated to fit: R_X86_64_PC32 against symbol `fn_hyp_in_list' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x204): relocation truncated to fit: R_X86_64_PC32 against symbol `fn_hyp_in_list' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x2bb): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x324): relocation truncated to fit: R_X86_64_PC32 against symbol `GeometryMode' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x34c): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x4cc): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x5c1): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x613): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x9a6): relocation truncated to fit: R_X86_64_PC32 against symbol `MsgStr' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x9b2): relocation truncated to fit: R_X86_64_PC32 against symbol `MsgStr' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
Loc2ddct.c:(.text+0x9fc): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/Loc2ddct.dir/build.make:106: bin/Loc2ddct] Error 1
make[1]: *** [CMakeFiles/Makefile2:465: CMakeFiles/Loc2ddct.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
OS version: Ubuntu 20.04.2 LTS GCC version: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Hello Indra
I think the problem is that your compiler is trying to use 32 bit memory offsets, and some of the arrays in NLL Loc2ddct.c (and perhaps Loc2ssst.c) are too big for 32 bit offsets. (https://stackoverflow.com/questions/57331990/c-compiling-relocation-truncated-to-fit-r-x86-64-pc32-against-symbol)
You might either:
- Try to upgrade your compiler to full 64 bit. (or maybe there are CMake or compiler flags to do this?)
Or 2) you can reduce the NLL array sizes. I think one array causing problems is Arrival in Loc2ddct.c. To change this:
In src/include/GridLib.h, change:
#define X_MAX_NUM_STATIONS_DIFF 500000
to a much smaller value, e.g.
#define X_MAX_NUM_STATIONS_DIFF 50000
or #define X_MAX_NUM_STATIONS_DIFF 5000
I think the array allocation causing the problem is in Loc2ddct.c here:
// re-allocate arrivals arrays
// allocate arrivals array
MAX_NUM_STATIONS = X_MAX_NUM_STATIONS_DIFF;
MAX_NUM_ARRIVALS = MAX_NUM_ARRIVALS_STA * MAX_NUM_STATIONS;
if ((Arrival = (ArrivalDesc *) malloc(MAX_NUM_ARRIVALS * sizeof (ArrivalDesc))) == NULL) {
nll_puterr("ERROR: re-allocating Arrival array.");
return (EXIT_ERROR_MEMORY);
}
Please tell us if this helps, as there are others with the same problem...
Thanks,
Best regards,
Anthony
Thanks for the reply Anthony, I tried changing X_MAX_NUM_STATIONS_DIFF to 5000 in the src/include/GridLib.h but still failed to compile on Ubuntu 20.04 LTS 64 bit and produce the same error. I added -g flags for debugging info and this is the error:
[ 50%] Linking C executable bin/Loc2ddct
CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o: in function `ConvertLocToCT':
/home/iori/Codelab/NonLinLoc/src/Loc2ddct.c:174:(.text+0x1d7): relocation truncated to fit: R_X86_64_PC32 against symbol `fn_hyp_in_list' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
/home/iori/Codelab/NonLinLoc/src/Loc2ddct.c:179:(.text+0x204): relocation truncated to fit: R_X86_64_PC32 against symbol `fn_hyp_in_list' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
/home/iori/Codelab/NonLinLoc/src/Loc2ddct.c:194:(.text+0x2bb): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
/home/iori/Codelab/NonLinLoc/src/Loc2ddct.c:211:(.text+0x324): relocation truncated to fit: R_X86_64_PC32 against symbol `GeometryMode' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
/home/iori/Codelab/NonLinLoc/src/Loc2ddct.c:214:(.text+0x34c): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
/home/iori/Codelab/NonLinLoc/src/Loc2ddct.c:245:(.text+0x4cc): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
/home/iori/Codelab/NonLinLoc/src/Loc2ddct.c:281:(.text+0x5c1): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
/home/iori/Codelab/NonLinLoc/src/Loc2ddct.c:302:(.text+0x613): relocation truncated to fit: R_X86_64_PC32 against symbol `Arrival' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o: in function `sprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:(.text+0x9a6): relocation truncated to fit: R_X86_64_PC32 against symbol `MsgStr' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o: in function `ConvertLocToCT':
/home/iori/Codelab/NonLinLoc/src/Loc2ddct.c:247:(.text+0x9b2): relocation truncated to fit: R_X86_64_PC32 against symbol `MsgStr' defined in COMMON section in CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o
CMakeFiles/Loc2ddct.dir/Loc2ddct.c.o: in function `sprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:(.text+0x9fc): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/Loc2ddct.dir/build.make:106: bin/Loc2ddct] Error 1
make[1]: *** [CMakeFiles/Makefile2:465: CMakeFiles/Loc2ddct.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I think GCC only failed to compile Loc2ddct.c and Loc2ssst.c. When I comment the CMake entry for those two files in the CMakeLists.txt, GCC can compile other codes successfully.
Hi Indra Thanks for the test and information.
As far as I can tell, this may be an issue with older gcc compilers: https://stackoverflow.com/questions/43367427/32-bit-absolute-addresses-no-longer-allowed-in-x86-64-linux Is you compiler fairly recent?
Otherwise, it is possible that adding the following to src/CMakeLists.txt will help, but I am not expert at this level and cannot test here (this change compiles fine with AppleClang 11.0.0.11000033)
# Adds options to the COMPILE_OPTIONS directory property. These options are used when compiling targets from the current directory and below.
add_compile_options(-mcmodel=medium)
# Add options to the link step for executable, shared library or module library targets in the current directory and below that are added after this command is invoked.
add_link_options("-Wl,-no_pie")
Best regards, Anthony
Hello again Indra
Someone else with a similar problem as you reported was able to compile all with the following changes:
Line 115 Loc2ddc.c , the value 100000 causes the error. Replaced with 50000, for example, compilation succeeds.
Lines 127 and 153 Loc2sst.c, the function strlcpy does not exist under Linux. When replaced by strncpy (suggested by the compiler), compilation succeeds.
I have made these changes in the code here and will push to the repository after testing and if you confirm these fixes work for your configuration.
Please tell me if this helps...
Thanks, Anthony
Hello Anthony
As you've suggested, I changed MAX_NUM_DIFF_HYPOCENTERS in the Loc2ddc.c line 113 to 50000 and replaced all strlcpy functions to strncpy in the lines 127 and 153 Loc2ssst.c. GCC now can compile all codes successfully.
Thank for your help.
Hello Anthony
As you've suggested, I changed
MAX_NUM_DIFF_HYPOCENTERSin the Loc2ddc.c line 113 to 50000 and replaced allstrlcpyfunctions tostrncpyin the lines 127 and 153 Loc2ssst.c. GCC now can compile all codes successfully.Thank for your help.
Great - thanks for the update. I hope this closes the issue...
Anthony
just FYI but just experienced this issue with a fresh install on a fairly new system, Ubuntu 21.04, gcc 9.3, 128 gb ram, etc etc. I suspect this is more of a bug than a compatibility issue.
Also had to change the strlcpy to strncpy as mentioned, but I managed to get MAX_NUM_DIFF_HYPOCENTERS to 75 000 with success.
Can you tell me exactly what changes you made to remove the error (if it was an error) on the new system? Thanks Anthony
I did the same as:
As you've suggested, I changed MAX_NUM_DIFF_HYPOCENTERS in the Loc2ddc.c line 113 to 50000 and replaced all strlcpy functions to strncpy in the lines 127 and 153 Loc2ssst.c. GCC now can compile all codes successfully.
EXCEPT I was able to raise MAX_NUM_DIFF_HYPOCENTERS to 75000 instead of 50000. At 80000 it fails again, so somewhere between 75 and 80k a limit is being surpassed. I briefly looked through the .h files but didn't see anything too obvious.
I have Ubuntu 20.04 and gcc 9.3.0 on a 64-bit system and confirm the solution works, i.e.
strlcpyis replaced withstrncpyin Loc2ssst.c- Decreasing
MAX_NUM_DIFF_HYPOCENTERSin Loc2ddct.c. For me it successfully compiles with a value as high asMAX_NUM_DIFF_HYPOCENTERS 78000
@savardge Thanks so much for reporting that!
Anthony
Hello @alomax ,
I faced the same two issues on Debian 11, with gcc-9.
And the solutions already mentionned (strncpy and MAX_NUM_DIFF_HYPOCENTERS) also made the code compiled.
Regarding MAX_NUM_DIFF_HYPOCENTERS, I found the boundary at exactly 78546 :
- 78546 compile
- 78457 doesn't compile
Jean-Marie
Hi @jmsaurel Thanks, this is quite helpful! The value in future distributions is now 50000. Anthony