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

Lui*_*isM 5 linux elf cross-compiling

这以前有用过。我不知道发生了什么,问题是我不能再跑了。我正在使用 Ubuntu 16.04 x86-64 对 aarch64 架构与 ARM cpu 进行交叉编译。

\n\n

这就是我正在运行的配置:

\n\n
\n

./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 虚拟定时器=clock_cputime_id --with-perf-events

\n
\n\n

运行配置的日志:

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

运行 make 后:

\n\n

(...)

\n\n
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 \n/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)\n/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)\n/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)\n/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)\n/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)\n/usr/bin/ld: ../testlib/libtestlib.a(test_utils.o): Relocations in generic ELF (EM: 183)\n../testlib/libtestlib.a: error adding symbols: File in wrong format\ncollect2: error: ld returned 1 exit status\nMakefile.recipies:230: recipe for target 'mpifirst' failed\nmake[2]: *** [mpifirst] Error 1\nmake[2]: Leaving directory '/home/lfpm1993/Desktop/papi/src/ctests'\nMakefile.inc:240: recipe for target 'ctests' failed\nmake[1]: *** [ctests] Error 2\nmake[1]: Leaving directory '/home/lfpm1993/Desktop/papi/src'\nRules.pfm4_pe:42: recipe for target 'libpfm4/lib/libpfm.a' failed\nmake: *** [libpfm4/lib/libpfm.a] Error 2\n
Run Code Online (Sandbox Code Playgroud)\n\n

文件 test_utils.o 给出:

\n\n
\n

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

\n
\n\n

在我看来,它是我正在尝试构建的文件的正确类型。

\n\n

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

\n\n

谢谢\nLu\xc3\xads

\n

Emp*_*ian 4

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

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

当你跑步时会发生什么”

mpicc -c  -I../testlib -I../validation_tests -I.. -I.  -DUSE_PTHREAD_MUTEXES first.c
file first.o
Run Code Online (Sandbox Code Playgroud)

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

我可以通过尝试链接对象x86_64 foo.o库来重现这个确切的错误消息aarch64

这以前有用过。

可能您PATH之前已进行过修改,以便mpicc找到gcc目标。以及您如何忽略了适当的设置PATH

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