taviso / 123elf

A native port of Lotus 1-2-3 to Linux.
1.17k stars 59 forks source link

ubuntu x64 ncurses lib missing #2

Closed onoraba closed 2 years ago

onoraba commented 2 years ago

Hi

I've tried to build on

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal

First build binutils with --prefix=/home/user/opt --enable-targets=all And then

$ make
cc -m32 -ggdb3 -O0 -Wno-multichar  -m32 -ggdb3 -O0 -Wno-multichar -B. -Wl,-b,coff-i386  coffsyrup.c  -lncurses -o coffsyrup
./ld: cannot find -lncurses: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [<builtin>: coffsyrup] Error 1

Installing every ncurses* pkg with 32-bit versions didn't help

# dpkg -l | grep curses | awk '{print $2}'
lib32ncurses6
libncurses-dev:amd64
libncurses5-dev:amd64
libncurses6:amd64
libncursesw5-dev:amd64
libncursesw6:amd64
mtr-tiny
ncurses-base
ncurses-bin
ncurses-term
pinentry-curses

Changing Makefile also didn't help LDLIBS = -lncurses -L/usr/lib/x86_64-linux-gnu

$ make
cc -m32 -ggdb3 -O0 -Wno-multichar  -m32 -ggdb3 -O0 -Wno-multichar -B. -Wl,-b,coff-i386  coffsyrup.c  -lncurses -L/usr/lib/x86_64-linux-gnu -o coffsyrup
./ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libncurses.so.6 when searching for libncurses.so.6
./ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libncurses.so.6 when searching for libncurses.so.6
./ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libtinfo.so when searching for -ltinfo
./ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libtinfo.a when searching for -ltinfo
./ld: cannot find -ltinfo: No such file or directory
./ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libtinfo.so when searching for -ltinfo
./ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 when searching for libgcc_s.so.1
collect2: error: ld returned 1 exit status
make: *** [<builtin>: coffsyrup] Error 1

Even with LDLIBS = -lncurses -L/usr/lib32

$ make
cc -m32 -ggdb3 -O0 -Wno-multichar  -m32 -ggdb3 -O0 -Wno-multichar -B. -Wl,-b,coff-i386  coffsyrup.c  -lncurses -L/usr/lib32 -o coffsyrup
./ld: cannot find -lncurses: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [<builtin>: coffsyrup] Error 1
onoraba commented 2 years ago

Building binutils with --enable-tui didn't help

taviso commented 2 years ago

Hmm -- I think it wants the static version, maybe it's lib32ncurses-dev?

I'll try to get better build instructions for Ubuntu this weekend, I was mostly using Fedora while hacking on this!

onoraba commented 2 years ago

maybe it's lib32ncurses-dev

thanks, after installing I get new error

$ make
cc -m32 -ggdb3 -O0 -Wno-multichar  -m32 -ggdb3 -O0 -Wno-multichar -B. -Wl,-b,coff-i386  coffsyrup.c  -lncurses -o coffsyrup
./ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib32/Scrt1.o: in function `_start':
(.text+0x1c): undefined reference to `__libc_csu_fini'
./ld: (.text+0x23): undefined reference to `__libc_csu_init'
./ld: /tmp/cckQdK5o.o: in function `main':
/home/user/123/123elf/coffsyrup.c:382: undefined reference to `__stack_chk_fail_local'
./ld: coffsyrup: hidden symbol `__stack_chk_fail_local' isn't defined
./ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make: *** [<builtin>: coffsyrup] Error 1
stmuk commented 2 years ago

I had to # apt install libncurses5-dev:i386 on Ubuntu 20.04.

I've not yet built the binary due to linking errors, but I got further with adding -fno-stack-protector /lib32/libc_nonshared.a to CFLAGS. The latter fixed undefined reference to __libc_csu_fini (not sure if it's the correct way of doing this) and the former undefined reference to `__stack_chk_fail_local'

I'm now stuck on

cc -m32 -ggdb3 -O0 -Wno-multichar -fno-stack-protector /lib32/libc_nonshared.a  -B. -Wl,-b,coff-i386  123.o dl_init.o main.o forceplt.o wrappers.o patch.o  -lncurses -o 123
./ld: 123.o:nrcreate.c:(.text+0xb60b4): undefined reference to `close_range'
./ld: 123.o:nrcreate.c:(.text+0xb61ce): undefined reference to `close_range'
./ld: 123.o:nrfixup.c:(.text+0xb6ca5): undefined reference to `close_range'
./ld: 123.o:nrfixup.c:(.text+0xb6e52): undefined reference to `close_range'
./ld: forceplt.o: in function `__require_ref':
(.text+0x5b): undefined reference to `close_range'
./ld: (.text+0xec): undefined reference to `fstat'
./ld: (.text+0x209): undefined reference to `mknod'
./ld: (.text+0x358): undefined reference to `stat'
./ld: wrappers.o: in function `__unix_stat':
/home/steve/sandbox/123elf/wrappers.c:134: undefined reference to `stat'
./ld: wrappers.o: in function `__unix_fstat':
/home/steve/sandbox/123elf/wrappers.c:148: undefined reference to `fstat'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: 123] Error 1
onoraba commented 2 years ago

yep, added -fno-stack-protector /lib32/libc_nonshared.a to CFLAGS

and stuck on

$ make
cc -m32 -ggdb3 -O0 -Wno-multichar -fno-stack-protector /lib32/libc_nonshared.a -B. -Wl,-b,coff-i386  123.o dl_init.o main.o forceplt.o wrappers.o patch.o  -lpanel -lncurses -dynamic-linker /usr/lib32/ld-linux.so.2 -o 123
./ld: 123.o:nrcreate.c:(.text+0xb60b4): undefined reference to `close_range'
./ld: 123.o:nrcreate.c:(.text+0xb61ce): undefined reference to `close_range'
./ld: 123.o:nrfixup.c:(.text+0xb6ca5): undefined reference to `close_range'
./ld: 123.o:nrfixup.c:(.text+0xb6e52): undefined reference to `close_range'
./ld: forceplt.o: in function `__require_ref':
(.text+0x5b): undefined reference to `close_range'
./ld: (.text+0xec): undefined reference to `fstat'
./ld: (.text+0x209): undefined reference to `mknod'
./ld: (.text+0x358): undefined reference to `stat'
./ld: wrappers.o: in function `__unix_stat':
/home/user/123/123elf/wrappers.c:134: undefined reference to `stat'
./ld: wrappers.o: in function `__unix_fstat':
/home/user/123/123elf/wrappers.c:148: undefined reference to `fstat'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: 123] Error 1
taviso commented 2 years ago

Oops - that looks like a bug, close_range should be a localized. Let me quickly push that change and see if that fixes it.

stmuk commented 2 years ago

That fixes close_range

taviso commented 2 years ago

Hmm, I think I just need to add stat, mknod and fstat to forceplt.s -- can you see if that does anything? (Note: you might need to make clean after changing it)

Nevermind, they're already in there - very confusing! It might take me a few hours before I can get to my Ubuntu machine and repro, sorry!

taviso commented 2 years ago

Okay, I think I've found the problem -- give me five minutes to commit something.

taviso commented 2 years ago

It might work now -- although I'm still confused about how a few things work, can you see if it makes any progress?

stmuk commented 2 years ago

Not quite yet...


cc -lc -m32 -ggdb3 -O0 -Wno-multichar -fno-stack-protector -B. -Wl,-b,coff-i386 -no-pie  123.o dl_init.o main.o forceplt.o wrappers.o patch.o  -lncurses -o 123
./ld: 123.o: warning: the use of `tempnam' is dangerous, better use `mkstemp'
./ld: 123.o:time_comm.c:(.text+0xdf104): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
./ld: 123.o: warning: gtty is not implemented and will always fail
./ld: 123.o: warning: stty is not implemented and will always fail
./ld: 123.o:crt1.s:(.data+0x1f684): multiple definition of `sys_errlist'
./ld: 123.o:crt1.s:(.data+0x1f8c0): multiple definition of `sys_nerr'
./ld: forceplt.o: in function `__require_ref':
(.text+0xe7): undefined reference to `fstat'
./ld: (.text+0x204): undefined reference to `mknod'
./ld: (.text+0x353): undefined reference to `stat'
./ld: wrappers.o: in function `__unix_stat':
/home/steve/sandbox/123elf/wrappers.c:126: undefined reference to `stat'
./ld: wrappers.o: in function `__unix_fstat':
/home/steve/sandbox/123elf/wrappers.c:138: undefined reference to `fstat'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: 123] Error 1
onoraba commented 2 years ago

same here

cc -lc -m32 -ggdb3 -O0 -Wno-multichar -fno-stack-protector -B. -Wl,-b,coff-i386 -no-pie  123.o dl_init.o main.o forceplt.o wrappers.o patch.o  -lncurses -o 123
./ld: 123.o: warning: the use of `tempnam' is dangerous, better use `mkstemp'
./ld: 123.o:time_comm.c:(.text+0xdf104): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
./ld: 123.o: warning: gtty is not implemented and will always fail
./ld: 123.o: warning: stty is not implemented and will always fail
./ld: 123.o:crt1.s:(.data+0x1f684): multiple definition of `sys_errlist'
./ld: 123.o:crt1.s:(.data+0x1f8c0): multiple definition of `sys_nerr'
./ld: forceplt.o: in function `__require_ref':
(.text+0xe7): undefined reference to `fstat'
./ld: (.text+0x204): undefined reference to `mknod'
./ld: (.text+0x353): undefined reference to `stat'
./ld: wrappers.o: in function `__unix_stat':
/home/user/123/123elf/wrappers.c:126: undefined reference to `stat'
./ld: wrappers.o: in function `__unix_fstat':
/home/user/123/123elf/wrappers.c:138: undefined reference to `fstat'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: 123] Error 1
taviso commented 2 years ago

Hmm, okay - can you try running this manually to see if it works:

cc forceplt.o -lc -m32 -ggdb3 -O0 -Wno-multichar -fno-stack-protector -B. -Wl,-b,coff-i386 -no-pie  123.o dl_init.o main.o wrappers.o patch.o  -lncurses -o 123

It must be a link order issue!

taviso commented 2 years ago

I think I've finally got it - I installed focal in a VM, and it seems to work now!

stmuk commented 2 years ago

I can confirm that works for me. It's nice seeing 123 greater than 80x25!