udo-munk / z80pack

A Zilog Z80 and Intel 8080 systems emulation
MIT License
158 stars 37 forks source link

Error building imsaisim on FreeBSD #267

Closed denverh2000 closed 1 year ago

denverh2000 commented 1 year ago

I'm getting the following at what looks like the end of the build on FreeBSD 13.1: cc sim0.o sim1.o sim1a.o sim2.o sim3.o sim4.o sim5.o sim6.o sim7.o simctl.o simint.o memory.o iosim.o simfun.o simglb.o simbdos.o am9511.o floatcnv.o ova.o unix_terminal.o unix_network.o config.o imsai-sio2.o imsai-hal.o imsai-fif.o cromemco-dazzler.o cromemco-88ccc.o cromemco-d+7a.o imsai-vio.o netsrv.o generic-at-modem.o libtelnet.o rtc.o -L../../frontpanel -L/usr/local/lib -lfrontpanel -ljpeg -lGL -lGLU -lX11 -lthr -o ../imsaisim /usr/local/bin/x86_64-unknown-freebsd13.1-ld: am9511.o: undefined reference to symbol 'log10@@FBSD_1.0' /usr/local/bin/x86_64-unknown-freebsd13.1-ld: /lib/libm.so.5: error adding symbols: DSO missing from command line cc: error: linker command failed with exit code 1 (use -v to see invocation) *** Error code 1

I did find the patch for generic-at-modem.c, which is how I got this far. Both cromemcosim and altairsim seem to build Ok.

denverh2000 commented 1 year ago

Adding -lm to the Makefile fixes this problem, but when running the simulator and clicking to operate a switch it crashes with a bus error. The Altair sim works fine though.

udo-munk commented 1 year ago

The am9511 APU code needs log10(), so linking with -lm is required.

For the bus error you need to build with -g3 and run under debugger, looking at the backtrace then should give us an idea where and why it crashes.

Then, I don't know which patch for generic-at-modem.c you mean? This should build ok as is in the repository. Are you building the master or the dev branch? I would suggest dev branch because it includes fixes for many things.

denverh2000 commented 1 year ago

The generic-at-modem.c patch is from issue #238, "build fix for FreeBSD". I switched to the dev branch and everything except imsaisim built and ran ok. I had to make two changes to imsaisim/srcsim/Makefile.bsd to include -lm, and add a missing path to iodevices.

Here's what I got from running imsaisim using gdb, after compiling with -g3: Thread 2 received signal SIGBUS, Bus error. Object-specific hardware error. [Switching to LWP 105972 of process 20404] 0x0000000808511d87 in llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value, llvm::Type, llvm::Twine const&, llvm::Instruction*) () from /usr/local/llvm15/lib/libLLVM-15.so (gdb)

udo-munk commented 1 year ago

In the dev branch there is no Makefile.bsd anymore, just Makefile because everything was moved to use GNU make. The OS dependend section for BSD might need -lm, currently it is:

EXEC = $(SIM) ifeq ($(TARGET_OS),BSD) PLAT_INCS = -I/usr/local/include PLAT_LDFLAGS = -L/usr/local/lib PLAT_LIBS = -lthr endif

For some reason it dies somewhere in libllvm it seems, you could provide the output from bt command, so that we can see where it comes from the emulation code.

denverh2000 commented 1 year ago

Ok, I see what happened when I thought I was cloning the dev branch: even if I'm looking at the dev branch with my browser, the "code" button doesn't reflect that.

Here's the backtrace: (gdb) bt

0 0x0000000808511d87 in llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value, llvm::Type, llvm::Twine const&, llvm::Instruction*) () from /usr/local/llvm15/lib/libLLVM-15.so

1 0x0000000808428846 in ?? () from /usr/local/llvm15/lib/libLLVM-15.so

2 0x000000080846eab4 in LLVMBuildBitCast () from /usr/local/llvm15/lib/libLLVM-15.so

3 0x0000000803b7a9f9 in ?? () from /usr/local/lib/dri/crocus_dri.so

4 0x0000000803b786f0 in ?? () from /usr/local/lib/dri/crocus_dri.so

5 0x0000000803b78652 in ?? () from /usr/local/lib/dri/crocus_dri.so

6 0x0000000803b4391d in ?? () from /usr/local/lib/dri/crocus_dri.so

7 0x0000000803afd862 in ?? () from /usr/local/lib/dri/crocus_dri.so

8 0x0000000803afbcff in ?? () from /usr/local/lib/dri/crocus_dri.so

9 0x0000000803b05eba in ?? () from /usr/local/lib/dri/crocus_dri.so

10 0x0000000803a96c50 in ?? () from /usr/local/lib/dri/crocus_dri.so

11 0x0000000803a91540 in ?? () from /usr/local/lib/dri/crocus_dri.so

12 0x0000000803a9115b in ?? () from /usr/local/lib/dri/crocus_dri.so

13 0x0000000803a9108a in ?? () from /usr/local/lib/dri/crocus_dri.so

14 0x00000008037d5664 in ?? () from /usr/local/lib/dri/crocus_dri.so

15 0x00000008037d5a2c in ?? () from /usr/local/lib/dri/crocus_dri.so

16 0x0000000803606e59 in ?? () from /usr/local/lib/dri/crocus_dri.so

17 0x00000008035d3b98 in ?? () from /usr/local/lib/dri/crocus_dri.so

18 0x00000008036d8662 in ?? () from /usr/local/lib/dri/crocus_dri.so

19 0x00000008006b3366 in lpSwitch::drawForPick() () from /usr/local/lib/libfrontpanel.so

20 0x00000008006a9b00 in Lpanel::pick(int, int, int, int) () from /usr/local/lib/libfrontpanel.so

21 0x00000008006b076d in Lpanel::procEvents() () from /usr/local/lib/libfrontpanel.so

22 0x00000008006ae361 in lp_mainloop_thread(void*) () from /usr/local/lib/libfrontpanel.so

23 0x0000000800bd583a in thread_start (curthread=0x801612700)

at /usr/src/lib/libthr/thread/thr_create.c:292

24 0x0000000000000000 in ?? ()

Backtrace stopped: Cannot access memory at address 0x7fffdfffe000 (gdb)

If I need to use a different version of llvm, I do have other versions installed, but I have no idea how to force an something to use a specific version.

denverh2000 commented 1 year ago

From imsaisim using the dev branch: Thread 2 received signal SIGBUS, Bus error. Object-specific hardware error. [Switching to LWP 106931 of process 26395] 0x0000000808311d87 in llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value, llvm::Type, llvm::Twine const&, llvm::Instruction*) () from /usr/local/llvm15/lib/libLLVM-15.so (gdb) bt

0 0x0000000808311d87 in llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value, llvm::Type, llvm::Twine const&, llvm::Instruction*) () from /usr/local/llvm15/lib/libLLVM-15.so

1 0x0000000808228846 in ?? () from /usr/local/llvm15/lib/libLLVM-15.so

2 0x000000080826eab4 in LLVMBuildBitCast () from /usr/local/llvm15/lib/libLLVM-15.so

3 0x000000080397a9f9 in ?? () from /usr/local/lib/dri/crocus_dri.so

4 0x00000008039786f0 in ?? () from /usr/local/lib/dri/crocus_dri.so

5 0x0000000803978652 in ?? () from /usr/local/lib/dri/crocus_dri.so

6 0x000000080394391d in ?? () from /usr/local/lib/dri/crocus_dri.so

7 0x00000008038fd862 in ?? () from /usr/local/lib/dri/crocus_dri.so

8 0x00000008038fbcff in ?? () from /usr/local/lib/dri/crocus_dri.so

9 0x0000000803905eba in ?? () from /usr/local/lib/dri/crocus_dri.so

10 0x0000000803896c50 in ?? () from /usr/local/lib/dri/crocus_dri.so

11 0x0000000803891540 in ?? () from /usr/local/lib/dri/crocus_dri.so

12 0x000000080389115b in ?? () from /usr/local/lib/dri/crocus_dri.so

13 0x000000080389108a in ?? () from /usr/local/lib/dri/crocus_dri.so

14 0x00000008035d5664 in ?? () from /usr/local/lib/dri/crocus_dri.so

15 0x00000008035d5a2c in ?? () from /usr/local/lib/dri/crocus_dri.so

16 0x0000000803406e59 in ?? () from /usr/local/lib/dri/crocus_dri.so

17 0x00000008033d3b98 in ?? () from /usr/local/lib/dri/crocus_dri.so

18 0x00000008034d8662 in ?? () from /usr/local/lib/dri/crocus_dri.so

19 0x0000000000468af6 in lpSwitch::drawForPick() ()

20 0x000000000046d160 in Lpanel::pick(int, int, int, int) ()

21 0x0000000000465f10 in Lpanel::procEvents() ()

22 0x0000000000463c13 in lp_mainloop_thread(void*) ()

23 0x00000008009f183a in thread_start (curthread=0x801412700) at /usr/src/lib/libthr/thread/thr_create.c:292

24 0x0000000000000000 in ?? ()

Backtrace stopped: Cannot access memory at address 0x7fffdfffe000 (gdb)

udo-munk commented 1 year ago

Nothing suspect to see, the thread for the front panel gets started and then works on the event loop. No idea about the problem in libllvm, it tries to address memory which is outside the scope of the process, so bus error.

sneakywumpus commented 1 year ago

Try software rendering:

env LIBGL_ALWAYS_SOFTWARE=1 imsaisim

some Mesa DRI drivers have problems with OpenGL selections (GL_SELECT render mode)

denverh2000 commented 1 year ago

Yes, that works, thanks. This is very impressive.

udo-munk commented 1 year ago

One questions is left, should I add -lm to PLAT_LIBS = -lthr in Makefile for building?

sneakywumpus commented 1 year ago

Should be added, since the manual page of log10() on FreeBSD specifies the libm library. Strange thing is, that the builds on my FreeBSD 13.1-stable VM from a few months ago didn't need -lm.

udo-munk commented 1 year ago

OK, done