facebookincubator / cinder

Cinder is Meta's internal performance-oriented production version of CPython.
https://trycinder.com
Other
3.43k stars 122 forks source link

undefined reference to shm_open #1

Closed kmod closed 3 years ago

kmod commented 3 years ago

I get a couple of these errors when linking the final executable:

$ g++ -pthread   -lrt   -Xlinker -export-dynamic -o python Programs/python.o libpython3.8_static.a -lcrypt -lpthread -ldl  -lutil -lm   -lm 
/usr/bin/ld: libpython3.8_static.a(virtmem.o): in function `asmjit::VirtMem_openAnonymousMemory(int*, bool) [clone .part.0]':
/home/kmod/cinder/ThirdParty/asmjit/src/asmjit/core/virtmem.cpp:330: undefined reference to `shm_open'
/usr/bin/ld: /home/kmod/cinder/ThirdParty/asmjit/src/asmjit/core/virtmem.cpp:332: undefined reference to `shm_unlink'
collect2: error: ld returned 1 exit status

Adding -lrt to the makefile LIBS variable solved this for me. This is on Ubuntu 20.04.

zitterbewegung commented 3 years ago

Are you able to run oss-build-and-test.sh ? If you are what is the output of that?

kmod commented 3 years ago

Same issue:

$ ./oss-build-and-test.sh
[snip]
g++ -pthread   -lrt   -Xlinker -export-dynamic -o Programs/_testembed Programs/_testembed.o libpython3.8_static.a -lcrypt -pthread -ldl  -lutil -lm   -lm 
/usr/bin/ld: libpython3.8_static.a(virtmem.o): in function `asmjit::VirtMem_openAnonymousMemory(int*, bool) [clone .part.0]': /home/kmod/cinder/ThirdParty/asmjit/src/asmjit/core/virtmem.cpp:330: undefined reference to `shm_open'
/usr/bin/ld: /home/kmod/cinder/ThirdParty/asmjit/src/asmjit/core/virtmem.cpp:332: undefined reference to `shm_unlink'
collect2: error: ld returned 1 exit status
make: *** [Makefile:895: Programs/_testembed] Error 1
make: *** Waiting for unfinished jobs....
/usr/bin/ld: libpython3.8_static.a(virtmem.o): in function `asmjit::VirtMem_openAnonymousMemory(int*, bool) [clone .part.0]':
/home/kmod/cinder/ThirdParty/asmjit/src/asmjit/core/virtmem.cpp:330: undefined reference to `shm_open'
/usr/bin/ld: /home/kmod/cinder/ThirdParty/asmjit/src/asmjit/core/virtmem.cpp:332: undefined reference to `shm_unlink'
collect2: error: ld returned 1 exit status
make: *** [Makefile:765: python] Error 1
gosella commented 3 years ago

Maybe I can help with this issue. I've got a similar problem and I think I fixed by doing some changes to the Makefile.pre.in:

diff --git a/Makefile.pre.in b/Makefile.pre.in
index b2d5908..7158b2a 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -119,13 +119,7 @@ PY_CXXFLAGS_NODIST=$(CONFIGURE_CXXFLAGS_NODIST) $(CXXFLAGS_NODIST) -I$(srcdir)/I
 # environment variables
 PY_CPPFLAGS=   $(BASECPPFLAGS) -I. -I$(srcdir)/Include -I$(srcdir)/ThirdParty/fmt-6.1.1/include -I$(srcdir)/ThirdParty/i386-dis $(CONFIGURE_CPPFLAGS) $(CPPFLAGS) -DFMT_HEADER_ONLY=1
 PY_LDFLAGS_NODIST=$(CONFIGURE_LDFLAGS_NODIST) $(LDFLAGS_NODIST)
-OS_NAME := $(shell uname -s)
-ifeq ($(OS_NAME), Darwin)
-   LRT_FLAG=
-else
-   LRT_FLAG=-lrt
-endif
-PY_LDFLAGS=    $(CONFIGURE_LDFLAGS) $(LDFLAGS) $(LRT_FLAG)
+PY_LDFLAGS=    $(CONFIGURE_LDFLAGS) $(LDFLAGS)

 NO_AS_NEEDED=  @NO_AS_NEEDED@
 SGI_ABI=   @SGI_ABI@
@@ -256,6 +250,10 @@ INSTSONAME=    @INSTSONAME@

 LIBS=      @LIBS@
+OS_NAME := $(shell uname -s)
+ifneq ($(OS_NAME), Darwin)
+   LIBS += -lrt
+endif
 LIBM=      @LIBM@
 LIBC=      @LIBC@
 SYSLIBS=   $(LIBM) $(LIBC)

After applying the changes, I did a make distclean && ./configure && make -j.

The problem is that the -lrt is been added at the start of the g++ command (i.e., g++ -pthread -lrt ...) but it should appear near the end.

I'm sorry I don't have the time to make a proper PR and to find out if this really fixes the build on Ubuntu 20.04 (as some modules apparently still can't be build and I don't know if it is related to my changes or they couldn't be build from the start) but it's progress :-)

kobalicek commented 3 years ago

It would also be possible to define ASMJIT_NO_JIT (ironic name I know) to disable JitRuntime & VirtMem on AsmJit side if Cinder uses its own virtual memory management.