akawashiro / sloader

sloader is an ELF loader which aims to replace ld-linux.so of glibc.
GNU General Public License v3.0
144 stars 10 forks source link

Can't build and other questions. #41

Open fzakaria opened 1 year ago

fzakaria commented 1 year ago

Hello!

I am trying to build the repository but facing an issue with the libc_mapping.c file

FAILED: CMakeFiles/sloader.dir/libc_mapping.cc.o 
/usr/bin/c++ -DC10_USE_GLOG=1 -DGLOG_CUSTOM_PREFIX_SUPPORT -I/usr/local/google/home/fmzakari/code/github.com/akawashiro/sloader/build/glog -I/usr/local/google/home/fmzakari/code/github.com/akawashiro/sloader/build/glog/src -I/usr/local/google/home/fmzakari/code/github.com/akawashiro/sloader/raw_write -O2 -g -DNDEBUG -std=gnu++20 -Wall -Werror -MD -MT CMakeFiles/sloader.dir/libc_mapping.cc.o -MF CMakeFiles/sloader.dir/libc_mapping.cc.o.d -o CMakeFiles/sloader.dir/libc_mapping.cc.o -c /usr/local/google/home/fmzakari/code/github.com/akawashiro/sloader/libc_mapping.cc
/usr/local/google/home/fmzakari/code/github.com/akawashiro/sloader/libc_mapping.cc:306:53: error: ‘__dprintf_chk’ was not declared in this scope
  306 |     {"__dprintf_chk", reinterpret_cast<Elf64_Addr>(&__dprintf_chk)},
      |                                                     ^~~~~~~~~~~~~
/usr/local/google/home/fmzakari/code/github.com/akawashiro/sloader/libc_mapping.cc:310:60: error: ‘__explicit_bzero_chk’ was not declared in this scope; did you mean ‘explicit_bzero’?
  310 |     {"__explicit_bzero_chk", reinterpret_cast<Elf64_Addr>(&__explicit_bzero_chk)},
      |                                                            ^~~~~~~~~~~~~~~~~~~~
      |                                                            explicit_bzero
/usr/local/google/home/fmzakari/code/github.com/akawashiro/sloader/libc_mapping.cc:311:51: error: ‘__fdelt_chk’ was not declared in this scope
  311 |     {"__fdelt_chk", reinterpret_cast<Elf64_Addr>(&__fdelt_chk)},
      |                                                   ^~~~~~~~~~~
/usr/local/google/home/fmzakari/code/github.com/akawashiro/sloader/libc_mapping.cc:312:51: error: ‘__fgets_chk’ was not declared in this scope
  312 |     {"__fgets_chk", reinterpret_cast<Elf64_Addr>(&__fgets_chk)},
      |                                                   ^~~~~~~~~~~
/usr/local/google/home/fmzakari/code/github.com/akawashiro/sloader/libc_mapping.cc:313:60: error: ‘__fgets_unlocked_chk’ was not declared in this scope; did you mean ‘fgets_unlocked’?
  313 |     {"__fgets_unlocked_chk", reinterpret_cast<Elf64_Addr>(&__fgets_unlocked_chk)},

I can't seem to find these functions located anywhere which makes sense. I audited the Dockerfile which is included and run the same commands but I get the same failure.

  1. Is there a missing implementation that needs to be included?
  2. Why is there chibicc in the repo ? I can't find any use of it.
  3. I also installed apt-get install -y ninja-build cmake gcc g++ git python3 python3-distutils python3-dev python3-pip nasm clang-format libcap-dev tmux zsh neovim on my machine..

Thank you!

akawashiro commented 1 year ago

Hi,

  1. Is there a missing implementation that needs to be included?

Umm... I confirmed sudo docker build . --network=host still working. Which OS are you using? Can you show me the result of uname -a ? I want to make another Dockerfile of your OS.

  1. Why is there chibicc in the repo ? I can't find any use of it.

I use chibicc to check sloader is working. But now, I haven't use it anymore.

akawashiro commented 1 year ago

I moved unused script to misc directory in https://github.com/akawashiro/sloader/pull/42/files.

fzakaria commented 1 year ago
❯ uname -a
Linux my-machine 6.4.4-3rodete1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.4.4-3rodete1 (2023-09-05) x86_64 GNU/Linux
fzakaria commented 1 year ago

It did build with the Dockerfile actually but not on my local Debian... trying to find out why.

fzakaria commented 1 year ago

Should I re-run the generate script on my machine? I'm still a bit confused why I don't have these symbols hmm. Very cool project btw -- I'm trying to use it with another project I've written :)

akawashiro commented 1 year ago

I'm sorry for being late. I'm debugging on this branch using debian 12.2 image. https://github.com/akawashiro/sloader/pull/43

akawashiro commented 1 year ago

The error is reproduced https://gist.github.com/akawashiro/c7ad091abe2fef5cdc1d35c60b4dada8.

akawashiro commented 1 year ago

Should I re-run the generate script on my machine?

No, I think the cause of this error is the difference of libc of ubuntu and debian.

akawashiro commented 1 year ago

Sorry, I cannot fix this problem soon. Just tweaking libc_mapping.cc doesn't fix this.

I'm approaching this problem from completely different way which uses custom built glibc.

akawashiro commented 1 year ago

I confirmed this is due to the difference of glibc (glibc-2.36 and glibc-2.35).