Linking error for compiling Cython on aarch64 - c

I am trying to make an executable on aarch64 using cython.
I know these flags are excessive, I tried compiling it on my x86_64 system and it worked with just gcc -I/usr/include/python3.9 -lpython3.9 sample.c but on aarch64 it gives these long linking errors.
If anyone has managed to make an executable on arm64 using cython that would also help.
root#f6753f1e6043:~# cython sample.pyx --embed -X language_level=3
root#f6753f1e6043:~# python3-config --ldflags --libs --cflags --embed
-L/usr/lib/python3.8/config-3.8-aarch64-linux-gnu -L/usr/lib -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm
-lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm
-I/usr/include/python3.8 -I/usr/include/python3.8 -Wno-unused-result -Wsign-compare -g -fdebug-prefix-map=/build/python3.8-pqDzXG/python3.8-3.8.10=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall
root#f6753f1e6043:~# gcc $(python3-config --ldflags --libs --cflags --embed) sample.c
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__Pyx_PyObject_GetAttrStr':
/root/sample.c:1489: undefined reference to `PyObject_GetAttr'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__Pyx_copy_spec_to_module':
/root/sample.c:1258: undefined reference to `PyObject_GetAttrString'
/usr/bin/ld: /root/sample.c:1261: undefined reference to `_Py_NoneStruct'
/usr/bin/ld: /tmp/ccBjCsrj.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_Py_NoneStruct' which may bind externally can not be used when making a shared object; recompile with -fPIC
/root/sample.c:1261:(.text.unlikely+0xbc): dangerous relocation: unsupported relocation
/usr/bin/ld: /root/sample.c:1261: undefined reference to `_Py_NoneStruct'
/usr/bin/ld: /root/sample.c:1262: undefined reference to `PyDict_SetItemString'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `_Py_DECREF':
/usr/include/python3.8/object.h:478: undefined reference to `_Py_Dealloc'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__Pyx_copy_spec_to_module':
/root/sample.c:1265: undefined reference to `PyExc_AttributeError'
/usr/bin/ld: /tmp/ccBjCsrj.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `PyExc_AttributeError' which may bind externally can not be used when making a shared object; recompile with -fPIC
/root/sample.c:1265:(.text.unlikely+0xfc): dangerous relocation: unsupported relocation
/usr/bin/ld: /root/sample.c:1265: undefined reference to `PyExc_AttributeError'
/usr/bin/ld: /root/sample.c:1265: undefined reference to `PyErr_ExceptionMatches'
/usr/bin/ld: /root/sample.c:1266: undefined reference to `PyErr_Clear'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__Pyx_check_single_interpreter':
/root/sample.c:1237: undefined reference to `PyThreadState_Get'
/usr/bin/ld: /root/sample.c:1237: undefined reference to `PyInterpreterState_GetID'
/usr/bin/ld: /root/sample.c:1250: undefined reference to `PyExc_ImportError'
/usr/bin/ld: /tmp/ccBjCsrj.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `PyExc_ImportError' which may bind externally can not be used when making a shared object; recompile with -fPIC
/root/sample.c:1250:(.text.unlikely+0x17c): dangerous relocation: unsupported relocation
/usr/bin/ld: /root/sample.c:1250: undefined reference to `PyExc_ImportError'
/usr/bin/ld: /root/sample.c:1250: undefined reference to `PyErr_SetString'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__pyx_pymod_create':
/root/sample.c:1278: undefined reference to `PyObject_GetAttrString'
/usr/bin/ld: /root/sample.c:1280: undefined reference to `PyModule_NewObject'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `_Py_DECREF':
/usr/include/python3.8/object.h:478: undefined reference to `_Py_Dealloc'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `__pyx_pymod_create':
/root/sample.c:1283: undefined reference to `PyModule_GetDict'
/usr/bin/ld: /tmp/ccBjCsrj.o: in function `_Py_DECREF':
/usr/include/python3.8/object.h:478: undefined reference to `_Py_Dealloc'
/usr/bin/ld: /tmp/ccBjCsrj.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `__stack_chk_guard##GLIBC_2.17' which may bind externally can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /tmp/ccBjCsrj.o(.text.unlikely+0x2e0): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `__stack_chk_guard##GLIBC_2.17'
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

Related

ld finds library when run stand along but cant find when building executable

I am trying to build a program that requires the linking of libndctl. However, ld fails to find the library, and the build errors out at the linking stage stating (this used to build without error some time before):
Command:
g++ tatp_db.cc tatp_nvm.cc ../include/txopt.cc -lpmem -lpthread -o tatp_nvm -std=c++11 -static
Error:
/usr/bin/ld: /usr/local/lib/libpmem.a(libpmem_all.o): in function `pmem2_device_dax_alignment':
memset_t_avx512f.c:(.text+0xb527): undefined reference to `ndctl_new'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb59e): undefined reference to `ndctl_namespace_get_dax'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb5b5): undefined reference to `ndctl_dax_get_align'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb5ce): undefined reference to `ndctl_unref'
/usr/bin/ld: /usr/local/lib/libpmem.a(libpmem_all.o): in function `pmem2_device_dax_size':
memset_t_avx512f.c:(.text+0xb62f): undefined reference to `ndctl_new'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb6a9): undefined reference to `ndctl_namespace_get_dax'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb6c0): undefined reference to `ndctl_dax_get_size'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb700): undefined reference to `ndctl_unref'
/usr/bin/ld: /usr/local/lib/libpmem.a(libpmem_all.o): in function `pmem2_region_namespace':
memset_t_avx512f.c:(.text+0xc3ab): undefined reference to `ndctl_bus_get_first'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc3c0): undefined reference to `ndctl_region_get_first'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc3d5): undefined reference to `ndctl_namespace_get_first'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc3f2): undefined reference to `ndctl_namespace_get_dax'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc41e): undefined reference to `ndctl_dax_get_daxctl_region'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc463): undefined reference to `daxctl_dev_get_first'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc475): undefined reference to `daxctl_dev_get_devname'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc4e1): undefined reference to `daxctl_dev_get_next'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc512): undefined reference to `ndctl_namespace_get_btt'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc529): undefined reference to `ndctl_btt_get_block_device'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc53b): undefined reference to `ndctl_namespace_get_pfn'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc552): undefined reference to `ndctl_pfn_get_block_device'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc564): undefined reference to `ndctl_namespace_get_block_device'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc5d1): undefined reference to `ndctl_namespace_get_next'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc5ec): undefined reference to `ndctl_region_get_next'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc607): undefined reference to `ndctl_bus_get_next'
/usr/bin/ld: /usr/local/lib/libpmem.a(libpmem_all.o): in function `pmem2_get_region_id':
memset_t_avx512f.c:(.text+0xc64f): undefined reference to `ndctl_new'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc6f8): undefined reference to `ndctl_region_get_id'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc70a): undefined reference to `ndctl_unref'
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: all] Error 1
I tried fixing this by manually adding -lndctl to the build command
g++ tatp_db.cc tatp_nvm.cc ../include/txopt.cc -lpmem -lpthread -lndctl -o tatp_nvm -std=c++11 -static
Error:
/usr/bin/ld: cannot find -lndctl
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: all] Error 1
I see that the library exists in /usr/lib/ and when running ld stand-alone (/usr/bin/ld -lndctl --verbose) it finds the library. Does anyone know what causes this to happen and a fix?
Command:
g++ tatp_db.cc tatp_nvm.cc ../include/txopt.cc -lpmem -lpthread -o tatp_nvm -std=c++11 -static
That command is wrong: you said yourself that this binary requires libndtcl, yet you aren't listing that library on the command line, so of course its symbols end up being unresolved.
I tried fixing this by manually adding -lndctl to the build command
That is the correct fix.
/usr/bin/ld: cannot find -lndctl
I see that the library exists in /usr/lib/
There are a few likely root causes:
If you are linking a 64-bit executable (which seems likely), /usr/lib/libndctl* may exist, but is a 32-bit binary.
You need a 64-bit version (usually found in /usr/lib64) and that version is not present.
You have only libndctl.so*, but not libndtcl.a (the latter is required for -static link).
To fix, you would need to install libndctl-dev or similar package.

mcsema using error,has someone use mcsema successful

I flow the Official website to build mcsema using native build approach.Everything seems OK.Since my ida is on Windows,so I use the command of
%IDA_ROOT%\ida64.exe -S"C:\Users\dkl\Desktop\source\mcsema\tools\mcsema_disass\ida7\get_cfg.py --output
C:\Users\dkl\Desktop\output.cfg --arch amd64 --os linux" C:\Users\dkl\Desktop\work\t2\a.out
to generate output.cfg ,that is OK
then
mcsema-lift-11.0 --arch amd64 --os linux --cfg ./output.cfg --output ./output.bc
that is OK,then
remill-clang-11 -o ./output ./output.bc -lpthread -lm -ldl -llzma -Wl,--section-start=.section_1ff00000=0x1ff00000
COUNTER A ERROR
root#DESKTOP-CS6BMJI:/mnt/c/Users/dkl/Desktop# mcsema-lift-11.0 --arch amd64 --os linux --cfg ./output.cfg --output ./output.bc
root#DESKTOP-CS6BMJI:/mnt/c/Users/dkl/Desktop# remill-clang-11 -o ./output ./output.bc -lpthread -lm -ldl -llzma -Wl,--section-start=.section_1ff00000=0x1ff00000
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
/usr/bin/ld: /tmp/output-3e1099.o: in function sub_401020': llvm-link:(.text+0x152): undefined reference to __remill_jump'
/usr/bin/ld: /tmp/output-3e1099.o: in function sub_401040__start': llvm-link:(.text+0x2cb): undefined reference to __remill_function_call'
/usr/bin/ld: /tmp/output-3e1099.o: in function sub_401160___libc_csu_init': llvm-link:(.text+0x939): undefined reference to __remill_function_call'
/usr/bin/ld: /tmp/output-3e1099.o: in function sub_401000__init_proc': llvm-link:(.text+0xe2d): undefined reference to __remill_function_call'
/usr/bin/ld: /tmp/output-3e1099.o: in function ext_404040_printf': llvm-link:(.text+0x10da): undefined reference to __remill_function_call'
/usr/bin/ld: /tmp/output-3e1099.o:(.rodata+0x2138): undefined reference to `__mcsema_attach_call'
remill-clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
root#DESKTOP-CS6BMJI:/mnt/c/Users/dkl/Desktop#

Undefined reference. But can't find the specific library name

I'm going to assemble a program. But errors followed.
gcc -no-pie final.s -ldl -lm -lz -lrt -lpthread -lcrypt -lgmp -m64
/usr/bin/ld: error in /tmp/ccjXcZiN.o(.eh_frame); no .eh_frame_hdr table will be created.
/tmp/ccjXcZiN.o: In function `S_0x404C5A':
(.text+0x775): undefined reference to `have_libloaded'
/tmp/ccjXcZiN.o: In function `BB_73':
(.text+0x78f): undefined reference to `libhandle'
/tmp/ccjXcZiN.o: In function `BB_74':
(.text+0x79c): undefined reference to `load_library_errmsg'
/tmp/ccjXcZiN.o: In function `S_0x404CA0':
(.text+0x7bf): undefined reference to `have_libloaded'
collect2: error: ld returned 1 exit status
I know that there're some other libraries needed on the machine. But i can't search for the specific library name.

C Programming of Libharu on Debian

I having a lot of problems setting up my programming environment on Debian. I am trying to write a C program to create pdf documents. I have installed libharu by issuing the following command
sudo apt-get install libhpdf-dev
I can find hpdf.h in /usr/include folder. I am trying to make sure that the program is installed properly by using a sample code (http://libharu.sourceforge.net/demo/text_demo.c) I found on the internet.
I tried compiling the program by issuing the following command:
gcc pdf.c and was treated to a long list of errors:
/usr/bin/ld: /tmp/ccR8ovya.o: in function `main':
pdf.c:(.text+0xb4): undefined reference to `HPDF_New'
/usr/bin/ld: pdf.c:(.text+0xf1): undefined reference to `HPDF_Free'
/usr/bin/ld: pdf.c:(.text+0x107): undefined reference to `HPDF_AddPage'
/usr/bin/ld: pdf.c:(.text+0x117): undefined reference to `HPDF_Page_GetHeight'
/usr/bin/ld: pdf.c:(.text+0x12a): undefined reference to `HPDF_Page_GetWidth'
/usr/bin/ld: pdf.c:(.text+0x145): undefined reference to `HPDF_Page_SetLineWidth'
/usr/bin/ld: pdf.c:(.text+0x18c): undefined reference to `HPDF_Page_Rectangle'
/usr/bin/ld: pdf.c:(.text+0x198): undefined reference to `HPDF_Page_Stroke'
/usr/bin/ld: pdf.c:(.text+0x1b0): undefined reference to `HPDF_GetFont'
/usr/bin/ld: pdf.c:(.text+0x1cf): undefined reference to `HPDF_Page_SetFontAndSize'
/usr/bin/ld: pdf.c:(.text+0x1e2): undefined reference to `HPDF_Page_TextWidth'
/usr/bin/ld: pdf.c:(.text+0x1f5): undefined reference to `HPDF_Page_BeginText'
/usr/bin/ld: pdf.c:(.text+0x23d): undefined reference to `HPDF_Page_TextOut'
/usr/bin/ld: pdf.c:(.text+0x249): undefined reference to `HPDF_Page_EndText'
/usr/bin/ld: pdf.c:(.text+0x255): undefined reference to `HPDF_Page_BeginText'
/usr/bin/ld: pdf.c:(.text+0x270): undefined reference to `HPDF_Page_SetFontAndSize'
/usr/bin/ld: pdf.c:(.text+0x29f): undefined reference to `HPDF_Page_TextOut'
/usr/bin/ld: pdf.c:(.text+0x2ab): undefined reference to `HPDF_Page_EndText'
/usr/bin/ld: pdf.c:(.text+0x2b7): undefined reference to `HPDF_Page_BeginText'
/usr/bin/ld: pdf.c:(.text+0x2df): undefined reference to `HPDF_Page_MoveTextPos'
/usr/bin/ld: pdf.c:(.text+0x320): undefined reference to `HPDF_GetFont'
/usr/bin/ld: pdf.c:(.text+0x33f): undefined reference to `HPDF_Page_SetFontAndSize'
/usr/bin/ld: pdf.c:(.text+0x364): undefined reference to `HPDF_Page_ShowText'
/usr/bin/ld: pdf.c:(.text+0x37c): undefined reference to `HPDF_Page_MoveTextPos'
/usr/bin/ld: pdf.c:(.text+0x397): undefined reference to `HPDF_Page_SetFontAndSize'
/usr/bin/ld: pdf.c:(.text+0x3aa): undefined reference to `HPDF_Page_ShowText'
/usr/bin/ld: pdf.c:(.text+0x3c2): undefined reference to `HPDF_Page_MoveTextPos'
/usr/bin/ld: pdf.c:(.text+0x3f1): undefined reference to `HPDF_Page_EndText'
/usr/bin/ld: pdf.c:(.text+0x407): undefined reference to `HPDF_SaveToFile'
/usr/bin/ld: pdf.c:(.text+0x413): undefined reference to `HPDF_Free'
collect2: error: ld returned 1 exit status
It seems that the compiler is having problem finding hpdf.h.
The answer was in the website.
gcc -o testpdf -O2 -Wall testpdf.c -lhpdf -lz
http://libharu.sourceforge.net/compile_your_program.html

Word Embedding Compression by Binarization (Tissier) // C-Binaries

For my bachelor thesis I want to apply this algorithm proposed here: Binarization by Tissier
I cloned the repository and tried to run cd near-lossless-binarization in the corrsponding directory.
However there comes up an error I don't know how to solve.
cd near-lossless-binarization && make
gcc binarize.c -o binarize -ansi -pedantic -Wall -Wextra -Wno-unused-result -Ofast -funroll-loops -lblas -lm
/usr/bin/ld: /tmp/ccxe5d0J.o: in function `apply_regularizarion_gradient':
binarize.c:(.text+0xddc): undefined reference to `cblas_sgemm'
/usr/bin/ld: binarize.c:(.text+0xf9e): undefined reference to `cblas_sgemm'
/usr/bin/ld: /tmp/ccxe5d0J.o: in function `apply_reconstruction_gradient':
binarize.c:(.text+0x1059): undefined reference to `cblas_sgemm'
/usr/bin/ld: binarize.c:(.text+0x12fb): undefined reference to `cblas_sgemm'
/usr/bin/ld: binarize.c:(.text+0x1800): undefined reference to `cblas_sgemm'
/usr/bin/ld: /tmp/ccxe5d0J.o:binarize.c:(.text+0x1e71): more undefined references to `cblas_sgemm' follow
collect2: Error: ld gab 1 as end-Status returned
Seems like there is an issue inside the corresponding file.
I already opened an issue in the repo, but need answers pretty soon..
Hoped to find anyone with C experience here who may solve my problem.
Requirements named in the repo are fulfilled.

Resources