I am attempting to replicate the following behaviour in CMake and need a little assistance...
I am compiling using gcc then linking using ld explicity. The original makefile carries out the following:
arm-linux-gcc -MD -Wa,-mcpu=arm7tdmi -Dgcc -c init.S
arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c serial.c
arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c timer.c
arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c amd.c
arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c intel.c
arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c at25f1024.c
arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c sst25vf020.c
arm-linux-gcc -MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -c main.c
arm-linux-ld -q --defsym ROBASE=0x00000000 -T init.lds -o init.elf init.o serial.o timer.o amd.o intel.o at25f1024.o sst25vf020.o main.o
My CMakefileLists.txt looks like this
cmake_minimum_required(VERSION 2.8)
project(bootStage2)
#add_definitions(ROBASE
set(CMAKE_C_FLAGS "-MD -Wall -fno-common -fshort-enums -mcpu=arm7tdmi -fno-builtin -mapcs -O2 -Wl,-q -Wl,--defsym=ROBASE=0x00000000 -T ${bootStage2_SOURCE_DIR}/init.lds")
#add_definitions(ROBASE=0x00000000)
set(SRCFILES
serial.c
timer.c
amd.c
intel.c
at25f1024.c
sst25vf020.c
main.c
)
set(CMAKE_init.elf_LINK_EXECUTABLE "/usr/bob/arm920t/usr/bin/arm-linux-ld")
add_executable( init.elf ${SRCFILES})
SET_TARGET_PROPERTIES(init.elf PROPERTIES LINKER_LANGUAGE C)
add_dependencies( init.elf
assemble_S
)
add_custom_target(assemble_S
COMMAND /usr/bob/arm920t/usr/bin/arm-linux-gcc -MD -Wa,-mcpu=arm7tdmi -Dgcc -c init.S
COMMENT "Assembling init.S"
WORKING_DIRECTORY ${bootStage2_SOURCE_DIR}
If I don't define the linker exe then CMake attempts to use gcc to link and seg faults on linking.
The cmake output complains that there are no files to link against when I tell it to use arm-linux-ld, I'm sure there is a better way of doing this does anyone have any useful hints?
Cheers,
Chris.
The way we found when we have faced this problem some years ago was the following:
We replaced the link-template in cmake (we used our own linker, but it also should work with only adding arguments):
set(CMAKE_CXX_LINK_EXECUTABLE "${LINKER} ... <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_C_LINK_EXECUTABLE ${CMAKE_CXX_LINK_EXECUTABLE})
The ... I omitted our custom arguments. The key here is the <>-elements which are filled in by cmake for each target to be linked.
See also here.
Related
I'm trying to do a Yocto build of libstt.so from the Coqui project, with TFLite as the backend, for the Snapdragon 210 which has an armv7ahf processor. I've been using the meta-tensorflow OpenEmbedded layer as a starting point.
Getting Bazel compiled and working with the Yocto cross-compilation toolchain was heinously complicated, but that's happily behind me now, and my layer has progressed to building libstt.so itself.
However, towards the end of the build in the linking phase I get this R_ARM_TLS_LE32 relocation not permitted in shared object error:
ld: bazel-out/arm-opt/bin/tensorflow/lite/kernels/libeigen_support.pic.a(eigen_support.pic.o)(.text._ZNK6tflite13eigen_support12_GLOBAL__N_122EigenThreadPoolWrapper15CurrentThreadIdEv+0x2c): R_ARM_TLS_LE32 relocation not permitted in shared object
bazel-out/arm-opt/bin/tensorflow/lite/kernels/libeigen_support.pic.a(eigen_support.pic.o): In function `tflite::eigen_support::(anonymous namespace)::EigenThreadPoolWrapper::CurrentThreadId() const':
eigen_support.cc:(.text._ZNK6tflite13eigen_support12_GLOBAL__N_122EigenThreadPoolWrapper15CurrentThreadIdEv+0x2c): dangerous relocation: unsupported relocation
I gather that R_ARM_TLS_LE32 is an ELF static Thread Local Storage relocation code, and that eigen_support is incorrectly being compiled with static code that the linker won't accept? But I'm definitely out of my depth here.
The build is being initiated with:
bazel build \
--config=monolithic \
--verbose_explanations --verbose_failures \
--action_env ANDROID_NDK_API_LEVEL=21 \
--config=android \
--config=android_arm \
--define runtime=tflite \
--cxxopt="-fpermissive" \
--cxxopt="-std=c++14" \
--cpu="${BAZEL_TARGET_CPU}" \
-c opt \
--copt="-D_GLIBCXX_USE_CXX11_ABI=0" \
--copt=-fvisibility=hidden \
--copt=-O3 \
--copt=-D_GLIBCXX_USE_C99 \
--crosstool_top=#local_config_yocto_compiler//:toolchain \
--host_crosstool_top=#bazel_tools//tools/cpp:toolchain \
--subcommands --explain=${T}/explain.log \
//native_client:libstt.so
}
eigen_support.pic.o itself is built with the following command (from the error log, formatted for ease of reading). Can you help me figure out why it's compiling wrong?
arm-oe-linux-gnueabi-gcc
-fstack-protector
-g0
-O2
-DNDEBUG
-ffunction-sections
-fdata-sections
-D_PYTHON_INCLUDE_TARGET
-MD
-MF bazel-out/arm-opt/bin/tensorflow/lite/kernels/_objs/eigen_support/eigen_support.pic.d
'-frandom-seed=bazel-out/arm-opt/bin/tensorflow/lite/kernels/_objs/eigen_support/eigen_support.pic.o'
-fPIC
-DEIGEN_MPL2_ONLY
'-DEIGEN_MAX_ALIGN_BYTES=64'
'-DEIGEN_HAS_TYPE_TRAITS=0'
-iquote .
-iquote bazel-out/arm-opt/bin
-iquote external/gemmlowp
-iquote bazel-out/arm-opt/bin/external/gemmlowp
-iquote external/eigen_archive
-iquote bazel-out/arm-opt/bin/external/eigen_archive
-iquote external/local_config_sycl
-iquote bazel-out/arm-opt/bin/external/local_config_sycl
-iquote external/ruy
-iquote bazel-out/arm-opt/bin/external/ruy
-iquote external/cpuinfo
-iquote bazel-out/arm-opt/bin/external/cpuinfo
-iquote external/clog
-iquote bazel-out/arm-opt/bin/external/clog
-Ibazel-out/arm-opt/bin/external/clog/_virtual_includes/clog
-isystem external/eigen_archive
-isystem bazel-out/arm-opt/bin/external/eigen_archive
-DTFLITE_WITH_RUY_GEMV
-w
-w
-fPIC
-D_GLIBCXX_USE_C99
-D_PYTHON_INCLUDE_TARGET
'-march=armv7-a'
'-mfpu=neon'
'-mfloat-abi=hard'
-Wl,-O1
'-Wl,--hash-style=gnu'
-Wl,--as-needed
-Wl,-z,relro,-z,now,-z,noexecstack
-fstack-protector-strong
-pie -fPIE '-D_FORTIFY_SOURCE=2'
-Wa,--noexecstack
-Wformat -Wformat-security '-Werror=format-security'
'--sysroot=/home/gbw/sc20_linux/poky/build/tmp-glibc/work/armv7ahf-neon-oe-linux-gnueabi/coqui/v0.10.0-alpha.9-r0/bazel/output_base/external/yocto_compiler/recipe-sysroot'
-O2
-Wa,--noexecstack
-fexpensive-optimizations
-frename-registers
-fomit-frame-pointer
-ftree-vectorize
-finline-functions
'-finline-limit=64'
'-Wno-error=maybe-uninitialized'
'-Wno-error=unused-result'
-fvisibility-inlines-hidden
'-std=c++14'
'-std=c++14' -fpermissive
'-std=c++14'
-DFARMHASH_NO_CXX_STRING
-Wno-sign-compare
-O3
-fno-exceptions
'-Wno-error=reorder'
-Wno-builtin-macro-redefined
'-D__DATE__="redacted"'
'-D__TIMESTAMP__="redacted"'
'-D__TIME__="redacted"'
-no-canonical-prefixes
-fno-canonical-system-headers
-c tensorflow/lite/kernels/eigen_support.cc
-o bazel-out/arm-opt/bin/tensorflow/lite/kernels/_objs/eigen_support/eigen_support.pic.o)
The issue was due to the -fPIE compiler flag being added by a bazelrc file that I didn't notice. Removing -fPIE fixed the error.
I have variable CC_OPTIONS has value set like below
-arch arm64 -mcpu=abc1 -c --debug -O2 -static -fstack-protector -ffreestanding -nostartfiles -std=c11
I wanted to extract -mcpu=abc1 from CC_OPTIONS
Tried below approach, but getting more than what i wanted.
string(REGEX REPLACE ".*mcpu=(.*)\ .*" "\\1" CPU_TYPE "${CC_OPTIONS}")
any suggestions?
If you use if(MATCHES) you can get character groups of the match using CMAKE_MATCH_<n>
set(MY_VAR "-arch arm64 -mcpu=abc1 -c --debug -O2 -static -fstack-protector -ffreestanding -nostartfiles -std=c11")
if (MY_VAR MATCHES "^([^ ]+ +)*(-mcpu=[^ ]+)( +[^ ]+)*$")
message(STATUS "Found match: ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "mismatch")
endif()
Like that:
cmake_minimum_required (VERSION 2.8.11)
project (HELLO)
set(CC_OPTIONS "-arch arm64 -mcpu=abc1 -c --debug -O2 -static -fstack-protector -ffreestanding -nostartfiles -std=c11")
message(${CC_OPTIONS})
string(REGEX MATCH "\\-mcpu=[^ $]+" CPU_TYPE ${CC_OPTIONS})
message(${CPU_TYPE})
Example:
$ cmake .
-arch arm64 -mcpu=abc1 -c --debug -O2 -static -fstack-protector -ffreestanding -nostartfiles -std=c11
-mcpu=abc1
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ja/cmake
I am building TensorFlow with bazel, CUDA supported, on AWS GPU instance. I got:
error: unknown warning option '-Wno-invalid-partial-specialization'
Build options:
bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package --verbose_failures
Detailed error message:
ERROR: /home/ubuntu/.cache/bazel/_bazel_ubuntu/ad1e09741bb4109fbc70ef8216b59ee2/external/boringssl/BUILD:91:1: C++ compilation of rule '#boringssl//:crypto' failed: clang failed: error executing command
(cd /home/ubuntu/.cache/bazel/_bazel_ubuntu/ad1e09741bb4109fbc70ef8216b59ee2/execroot/tensorflow && \
exec env - \
CLANG_CUDA_COMPILER_PATH=/usr/bin/clang \
COMPUTECPP_TOOLKIT_PATH=/usr/local/computecpp \
CUDA_TOOLKIT_PATH=/usr/local/cuda \
CUDNN_INSTALL_PATH=/usr/local/cuda-8.0 \
HOST_CXX_COMPILER=/usr/bin/g++ \
HOST_C_COMPILER=/usr/bin/gcc \
PWD=/proc/self/cwd \
PYTHON_BIN_PATH=/usr/bin/python \
PYTHON_LIB_PATH=/usr/local/lib/python2.7/dist-packages \
TF_CUDA_CLANG=1 \
TF_CUDA_COMPUTE_CAPABILITIES=3.5,5.2 \
TF_CUDA_VERSION=8.0 \
TF_CUDNN_VERSION='' \
TF_NEED_CUDA=1 \
TF_NEED_OPENCL=1 \
/usr/bin/clang '-march=native' -MD -MF bazel-out/local_linux-opt/bin/external/boringssl/_objs/crypto/external/boringssl/src/crypto/sha/sha512.pic.d -iquote external/boringssl -iquote bazel-out/local_linux-opt/genfiles/external/boringssl -iquote external/bazel_tools -iquote bazel-out/local_linux-opt/genfiles/external/bazel_tools -isystem external/boringssl/src/include -isystem bazel-out/local_linux-opt/genfiles/external/boringssl/src/include -isystem external/bazel_tools/tools/cpp/gcc3 -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -fPIC -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -Wno-invalid-partial-specialization -fno-omit-frame-pointer -no-canonical-prefixes -DNDEBUG -g0 -O2 -ffunction-sections -fdata-sections -Wa,--noexecstack '-D_XOPEN_SOURCE=700' -Wall -Werror '-Wformat=2' -Wsign-compare -Wmissing-field-initializers -Wwrite-strings -Wshadow -fno-common '-std=c11' -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes -c external/boringssl/src/crypto/sha/sha512.c -o bazel-out/local_linux-opt/bin/external/boringssl/_objs/crypto/external/boringssl/src/crypto/sha/sha512.pic.o): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
error: unknown warning option '-Wno-invalid-partial-specialization' [-Werror,-Wunknown-warning-option]
Target //tensorflow/tools/pip_package:build_pip_package failed to build
I am trying to compile an application with Cmake.
Almost at the end of the state: 100%
I got:
/../lib/gcc/arm-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/bin/ld: warning: libIMGegl.so, needed by /arm-linux-gnueabi/lib/libEGL.so, not found (try using -rpath or -rpath-link)
and then a lot of messages of
undefined reference to 'something'
Where can I added -rpath or -rpath-link
This is my CMAKE FLAG:
set(CMAKE_C_FLAGS "-O2 -mcpu=cortex-a9 -mfpu=vfp -mfloat-abi=softfp -g -mtune=xscale -msoft-float -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -fomit-frame-pointer -fno-strict-aliasing ${CMAKE_ARM_LINUX_FLAGS}" CACHE INTERNAL "")
i have download srp-2.1.2 package and just try to compile it under ubuntu.
but it is not going to be compiled completely.
please tell me how to compile it under ubuntu .
error-
root#ubuntu:~/Desktop/srp-2.1.2/libsrp# make
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_client.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_conf.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_conv.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_getpass.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_sha.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_math.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_misc.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_pw.c
t_pw.c: In function ‘t_changepw’:
t_pw.c:468: warning: ignoring return value of ‘link’, declared with attribute warn_unused_result
t_pw.c:470: warning: ignoring return value of ‘link’, declared with attribute warn_unused_result
t_pw.c: In function ‘t_deletepw’:
t_pw.c:540: warning: ignoring return value of ‘link’, declared with attribute warn_unused_result
t_pw.c:542: warning: ignoring return value of ‘link’, declared with attribute warn_unused_result
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_read.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_server.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c t_truerand.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c cstr.c
cstr.c:24: warning: initialization from incompatible pointer type
cstr.c:24: warning: initialization from incompatible pointer type
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c srp.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c rfc2945_client.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c rfc2945_server.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c srp6_client.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c srp6_server.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c yp_misc.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c yp_tpasswd.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c yp_tconf.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c nsw_tpasswd.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c nsw_tconf.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c nsswitch.c
rm -f libsrp.a
ar cru libsrp.a t_client.o t_conf.o t_conv.o t_getpass.o t_sha.o t_math.o t_misc.o t_pw.o
t_read.o t_server.o t_truerand.o cstr.o srp.o rfc2945_client.o rfc2945_server.o
srp6_client.o srp6_server.o yp_misc.o yp_tpasswd.o yp_tconf.o nsw_tpasswd.o nsw_tconf.o
nsswitch.o
ranlib libsrp.a
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c tconf.c
tconf.c: In function ‘main’:
tconf.c:188: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
tconf.c:202: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
tconf.c:230: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
tconf.c:263: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
gcc -fPIC -O -o tconf tconf.o libsrp.a -lcrypto -ldl -lnsl
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c clitest.c
clitest.c: In function ‘main’:
clitest.c:51: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
clitest.c:53: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
clitest.c:57: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
clitest.c:61: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
clitest.c:74: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
clitest.c:79: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
gcc -fPIC -O -o clitest clitest.o libsrp.a -lcrypto -ldl -lnsl
clitest.o: In function `main':
clitest.c:(.text+0x56): warning: the `gets' function is dangerous and should not be used.
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c srvtest.c
srvtest.c: In function ‘main’:
srvtest.c:77: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
srvtest.c:103: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
srvtest.c:109: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
srvtest.c:118: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
gcc -fPIC -O -o srvtest srvtest.o libsrp.a -lcrypto -ldl -lnsl
srvtest.o: In function `main':
srvtest.c:(.text+0x15a): warning: the `gets' function is dangerous and should not be used.
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c getpwtest.c
gcc -fPIC -O -o getpwtest getpwtest.o libsrp.a -lcrypto -ldl -lnsl
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c srptest.c
gcc -fPIC -O -o srptest srptest.o libsrp.a -lcrypto -ldl -lnsl
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c srpbench.c
gcc -fPIC -O -o srpbench srpbench.o libsrp.a -lcrypto -ldl -lnsl
gcc -DHAVE_CONFIG_H -I. -I. -I. -fPIC -O -c srp6bench.c
srp6bench.c: In function ‘do_srp6preparam’:
srp6bench.c:197: warning: incompatible implicit declaration of built-in function ‘exit’
srp6bench.c: In function ‘usage’:
srp6bench.c:214: warning: incompatible implicit declaration of built-in function ‘exit’
srp6bench.c: In function ‘main’:
srp6bench.c:246: warning: incompatible implicit declaration of built-in function ‘exit’
gcc -fPIC -O -o srp6bench srp6bench.o libsrp.a -lcrypto -ldl -lnsl `
-
please tell me where is the problem as soon as possible
thanks
hi robsn thanks for this answer.
ok after compiling libsrp by using make it is going to create libsrp.a .please tell me can i use this libsrp.a as a shared library and how?.i want to use libsrp in a c# file under ubuntu by using dllimport.
`
I was able to reproduce this behaviour (the initially posted problem, see my comment). A temporary solution to get it compiled is:
make a safe copy of /usr/include/stdio.h
edit the original stdio.h:
On line 651 (extern _IO_ssize_t getline...) replace 'getline' with 'parseline'
compile srp
revert edits.
I only see warnings (no errors) which should not be a problem. Didn't it compile completely?
If your last posted line...
gcc -fPIC -O -o srp6bench srp6bench.o libsrp.a -lcrypto -ldl -lnsl `
...went well you should have a file called 'srp6bench'.
(Sorry for posting an answer but my reputation doesn't allow comments on others posts yet.)