通用ELF中的重定位(EM:183)

4
这之前是可以工作的。我不知道发生了什么变化,但问题是我无法再运行它了。我正在使用Ubuntu 16.04 x86-64,在ARM CPU上交叉编译aarch64架构的代码。

这是我正在运行的配置命令:

./configure --host=aarch64-linux-gnu --prefix=/data/data/papi/independent --exec-prefix=/data/data/papi/dependent --with-static-lib=yes --with-shared-lib=no --with-static-tools --with-arch=aarch64 --with-CPU=arm --with-ffsll --with-walltimer=cycle --with-tls=__thread --with-virtualtimer=clock_cputime_id --with-perf-events

运行配置时的日志:

checking for architecture... aarch64
checking for OS... linux
checking for OS version... 4.15.0-29-generic
checking for perf_event workaround level... autodetect
checking for if MIC should be used... no
checking for aarch64-linux-gnu-xlc... no
checking for aarch64-linux-gnu-icc... no
checking for aarch64-linux-gnu-gcc... aarch64-linux-gnu-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether aarch64-linux-gnu-gcc accepts -g... yes
checking for aarch64-linux-gnu-gcc option to accept ISO C89... none needed
checking for aarch64-linux-gnu-xlf... no
checking for aarch64-linux-gnu-ifort... no
checking for aarch64-linux-gnu-gfortran... no
checking for aarch64-linux-gnu-f95... no
checking for aarch64-linux-gnu-f90... no
checking for aarch64-linux-gnu-f77... no
checking for xlf... no
checking for ifort... no
checking for gfortran... gfortran
configure: WARNING: using cross tools not prefixed with host triplet
checking whether we are using the GNU Fortran 77 compiler... yes
checking whether gfortran accepts -g... yes
checking for mpicc... mpicc
checking for gawk... gawk
checking how to run the C preprocessor... aarch64-linux-gnu-gcc -E
checking whether ln -s works... yes
checking whether make sets $(MAKE)... yes
checking for aarch64-linux-gnu-ranlib... aarch64-linux-gnu-ranlib
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for ANSI C header files... (cached) yes
checking for inline... inline
checking whether time.h and sys/time.h may both be included... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking c_asm.h usability... no
checking c_asm.h presence... no
checking for c_asm.h... no
checking intrinsics.h usability... no
checking intrinsics.h presence... no
checking for intrinsics.h... no
checking mach/mach_time.h usability... no
checking mach/mach_time.h presence... no
checking for mach/mach_time.h... no
checking sched.h usability... yes
checking sched.h presence... yes
checking for sched.h... yes
checking for gethrtime... no
checking for read_real_time... no
checking for time_base_to_time... no
checking for clock_gettime... yes
checking for mach_absolute_time... no
checking for sched_getcpu... yes
checking for dlopen and dlerror symbols in base system... not found
checking for dlopen and dlerror symbols in -ldl... found
checking for native compiler for header generation... gcc
checking for debug build... 
checking for -Wno-override-init... 1
checking for CPU type... arm
forcing use of pthread mutexes... 
checking for ffsll... yes
checking for working gettid... no
checking for working syscall(SYS_gettid)... yes
checking for which real time clock to use... cycle
checking for high performance thread local storage... __thread
checking for which virtual timer to use... clock_cputime_id
checking for static user preset events... no
checking for static PAPI preset events... yes
checking for whether to build static library... yes
checking for whether to build shared library... no
checking for static compile of tests and utilities... yes
checking for linking with papi shared library of tests and utilities... no
checking platform... linux-pe
checking for components to build... perf_event perf_event_uncore
checking for PAPI event CSV filename to use... papi_events.csv
configure: Compiling genpapifdef with gcc because cross compiling
configure: Generating fpapi.h
configure: Generating f77papi.h
configure: Generating f90papi.h
configure: Rules.pfm4_pe will be included in the generated Makefile
configure: creating ./config.status
config.status: creating Makefile
config.status: creating papi.pc
config.status: creating components/Makefile_comp_tests.target
config.status: creating testlib/Makefile.target
config.status: creating utils/Makefile.target
config.status: creating ctests/Makefile.target
config.status: creating ftests/Makefile.target
config.status: creating validation_tests/Makefile.target
config.status: creating config.h

运行make命令后:

(...)

mpicc -I../testlib -I../validation_tests -I.. -I.  -g -Wextra -DUSE_PTHREAD_MUTEXES  -Wall -O1  first.c ../testlib/libtestlib.a ../testlib/do_loops.o ../libpapi.a -ldl -static -o mpifirst 
/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)
/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)
/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)
/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)
/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)
/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)
../testlib/libtestlib.a: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
Makefile.recipies:230: recipe for target 'mpifirst' failed
make[2]: *** [mpifirst] Error 1
make[2]: Leaving directory '/home/lfpm1993/Desktop/papi/src/ctests'
Makefile.inc:240: recipe for target 'ctests' failed
make[1]: *** [ctests] Error 2
make[1]: Leaving directory '/home/lfpm1993/Desktop/papi/src'
Rules.pfm4_pe:42: recipe for target 'libpfm4/lib/libpfm.a' failed
make: *** [libpfm4/lib/libpfm.a] Error 2

file test_utils.o 的结果如下:

test_utils.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), not stripped

看起来这个文件类型是我尝试构建的正确类型。

有关如何解决问题的任何线索吗?

谢谢, Luís


Makefile.recipies:230: 目标 'mpifirst' 的制作失败对应于 Makefile 中的这一行:mpifirst: mpifirst.c $(TESTLIB) $(DOLOOPS) $(PAPILIB) $(MPICC) $(INCLUDE) $(MPFLAGS) $(CFLAGS) $(TOPTFLAGS) first.c $(TESTLIB) $(DOLOOPS) $(PAPILIB) $(LDFLAGS) -o mpifirst -lpthread - LuisM
1个回答

4

mpicc -I../testlib ... first.c ../testlib/libtestlib.a ...
/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): 通用 ELF (EM: 183) 中的重定位

这将调用错误的连接器(系统连接器),并且很可能也会使用错误的编译器来编译 first.c

当您运行时会发生什么:

mpicc -c  -I../testlib -I../validation_tests -I.. -I.  -DUSE_PTHREAD_MUTEXES first.c
file first.o

我猜它会显示ELF 64位LSB可重定位,x86-64,版本1(SYSV),未剥离,这解释了你的问题:你的libtestlib.a是为所需的架构编译的,但你的主程序不是。

我可以通过尝试将x86_64foo.oaarch64对象库链接来复现此精确错误消息。

以前这个是可以工作的。

可能您之前修改了PATH,以便mpicc找到目标的gcc。并且您忽略了适当设置PATH

(依赖于PATH和其他环境变量的Makefile是最糟糕的 - 它们在一个shell中工作,但在另一个shell中不起作用。)


雇用的俄罗斯人,你的答案真的很有启发性,它为我节省了很多时间。当你运行以下命令时会发生什么? mpicc -c -I../testlib -I../validation_tests -I.. -I. -DUSE_PTHREAD_MUTEXES first.c file first.o 我敢打赌它会说ELF 64位LSB可重定位,x86-64,版本1(SYSV),未剥离你说得完全正确,那是输出结果。我对mpicc很好奇,所以我查了一下: $ mpicc --print-multiarch x86_64-linux-gnu我不太知道如何更改三元组,但我会去研究的。无论如何,非常感谢你 :) - LuisM

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接