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

时间:2018-07-23 10:16:47

标签: linux cross-compiling elf

这以前曾经起作用。我不知道发生了什么变化,但问题是我不能再跑步了。我正在使用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 =是--with-shared-lib =否--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

文件test_utils.o给出:

  

test_utils.o:可重定位的ELF 64位LSB,ARM aarch64,版本1(SYSV),未剥离

在我看来,这是我要构建的文件的正确类型。

有任何解决方法的线索吗?

谢谢, 路易斯

1 个答案:

答案 0 :(得分:1)

mpicc -I../testlib ... first.c ../testlib/libtestlib.a ...
/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)

这调用了错误的链接器(系统链接器),很可能也调用了错误的编译器来编译first.c

跑步时会发生什么”

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

我敢打赌,它说ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped,这可以解释您的问题:libtestlib.a是为所需的体系结构编译的,但您的主程序不是。

通过尝试将x86_64 foo.oaarch64对象的库链接,可以重现此确切的错误消息。

  

以前曾经工作过。

可能您之前已经修改了PATH,以便mpicc找到gcc作为目标。以及您忽略了如何正确设置PATH

(依赖Makefile和其他环境变量的{PATH s最糟糕-它们在一个shell中工作,而在另一个shell中工作。)