Skip to content

Link with custom libc #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and test
on: [pull_request]

jobs:
build:
check-ubuntu-Dockerfile:

runs-on: ubuntu-latest

Expand All @@ -13,4 +13,17 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
file: ./ubuntu-Dockerfile

# We cannot enable this CI job for now.
# check-debian-Dockerfile:
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v2
# - name: docker build
# uses: docker/build-push-action@v2
# with:
# context: .
# file: ./debian-Dockerfile
51 changes: 49 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,57 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/raw_write)

add_library(tls_secure tls_secure.cc)

add_executable(sloader sloader.cc dyn_loader.cc libc_mapping.cc sloader_dl.cc utils.cc sloader_static.map)
add_executable(sloader sloader.cc dyn_loader.cc libc_mapping.cc sloader_dl.cc
utils.cc sloader_static.map)
target_link_libraries(sloader glog tls_secure)
target_compile_options(sloader PUBLIC -Wall -Werror)
target_link_options(sloader PUBLIC -static -Wl,-verbose -T ${CMAKE_CURRENT_SOURCE_DIR}/sloader_static.map)
target_link_options(sloader PUBLIC -static -Wl,-verbose -T
${CMAKE_CURRENT_SOURCE_DIR}/sloader_static.map)

if(CUSTOM_LIBC_PATH)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=crtbegin.o
OUTPUT_VARIABLE CRT_BEGIN
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=crtend.o
OUTPUT_VARIABLE CRT_END
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libstdc++.a
OUTPUT_VARIABLE LIBSTDCXX
OUTPUT_STRIP_TRAILING_WHITESPACE)

add_executable(sloader_custom_libc sloader.cc dyn_loader.cc libc_mapping.cc
sloader_dl.cc utils.cc sloader_static.map)
target_link_libraries(
sloader_custom_libc
glog
${CUSTOM_LIBC_PATH}/lib/crt1.o
${CUSTOM_LIBC_PATH}/lib/crti.o
${CRT_BEGIN}
${LIBSTDCXX}
${CUSTOM_LIBC_PATH}/lib/libpthread.a
-Wl,--start-group
${CUSTOM_LIBC_PATH}/lib/libc.a
-lgcc
-lgcc_eh
-Wl,--end-group
${CRT_END}
${CUSTOM_LIBC_PATH}/lib/crtn.o
tls_secure)
target_compile_options(sloader_custom_libc PUBLIC -Wall -Werror)
target_link_options(
sloader_custom_libc
BEFORE
PUBLIC
-nostdlib
-nostartfiles
-static
-Wl,-verbose
-T
${CMAKE_CURRENT_SOURCE_DIR}/sloader_static.map)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake
${CMAKE_CURRENT_BINARY_DIR})
Expand Down
14 changes: 14 additions & 0 deletions debian-Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM debian:12.2
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && 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
# RUN pip3 install torch==1.13.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
COPY . /sloader
WORKDIR /sloader
# TODO
# RUN ./run-format.sh
RUN rm -rf build
RUN mkdir build
RUN cmake -GNinja -S . -B build
RUN cmake --build build
RUN cd build && ctest --output-on-failure -j $(nproc)
RUN ./make-sloader-itself.sh
4 changes: 3 additions & 1 deletion example/kernelvm/hello.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
void hoge();
int main(){ hoge(); }
int main() {
hoge();
}
4 changes: 3 additions & 1 deletion example/kernelvm/hoge.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#include <stdio.h>
void hoge(){ printf("hoge\n"); }
void hoge() {
printf("hoge\n");
}
2 changes: 1 addition & 1 deletion misc/clone_glibc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ then
pushd glibc
git remote add upstream https://sourceware.org/git/glibc.git
git fetch --all
git checkout origin/print-for-sloader
git checkout glibc-2.35
popd
fi

Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ add_test(NAME test_curl
COMMAND python3 ${cmake_current_source_dir}/compare_stdout.py
${cmake_binary_dir}/sloader curl -s www.example.com)

set_tests_properties(test_rustc test_top test_bash_plus test_curl test_python3_torch_ones
PROPERTIES WILL_FAIL TRUE)
set_tests_properties(test_rustc test_top test_bash_plus test_curl
test_python3_torch_ones PROPERTIES WILL_FAIL TRUE)

if(CUSTOM_LIBC_PATH)
add_custom_target(
Expand Down
File renamed without changes.