Skip to content

Commit

Permalink
LibC: Add libc.so
Browse files Browse the repository at this point in the history
We now compile everything with -static flag so libc.a would be use
  • Loading branch information
itamar8910 authored and awesomekling committed Dec 14, 2020
1 parent 09ccdc6 commit 58c583f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ function(serenity_libc target_name fs_name)
serenity_generated_sources(${target_name})
endfunction()

function(serenity_libc_shared target_name fs_name)
serenity_install_headers("")
serenity_install_sources("Libraries/LibC")
add_library(${target_name} SHARED ${SOURCES})
install(TARGETS ${target_name} DESTINATION usr/lib)
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
target_link_directories(LibC PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
serenity_generated_sources(${target_name})
endfunction()

function(serenity_bin target_name)
add_executable(${target_name} ${SOURCES})
install(TARGETS ${target_name} RUNTIME DESTINATION bin)
Expand Down Expand Up @@ -210,6 +220,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -g1 -fno-exceptions -fno-rtti -Wno-a
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffile-prefix-map=${CMAKE_SOURCE_DIR}=.")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -DSANITIZE_PTRS")
set(CMAKE_CXX_FLAGS_WITHOUT_STATIC ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
add_link_options(--sysroot ${CMAKE_BINARY_DIR}/Root)

include_directories(Libraries/LibC)
Expand Down
2 changes: 1 addition & 1 deletion Demos/DynamicObject/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(SOURCES
../../Libraries/LibC/crt0_shared.cpp
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostartfiles -pie -fpic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_WITHOUT_STATIC} -nostartfiles -pie -fpic")

serenity_bin(DynamicObjectDemo)
target_link_libraries(DynamicObjectDemo SampleLib LibCShared)
Expand Down
2 changes: 1 addition & 1 deletion Demos/DynamicObject/SampleLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(SOURCES
lib.cpp
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -fpic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_WIHTOUT_STATIC} -nostdlib -fpic")

add_library(SampleLib SHARED ${SOURCES})
target_link_libraries(SampleLib LibCShared)
Expand Down
7 changes: 5 additions & 2 deletions Libraries/LibC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@ serenity_libc(LibC c)
target_link_libraries(LibC crt0)
add_dependencies(LibC LibM)

add_library(LibCShared SHARED ${SOURCES})
install(TARGETS LibCShared DESTINATION usr/lib)
set(SOURCES ${SOURCES} "crt0_shared.cpp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib")
serenity_libc_shared(LibCShared c)
#add_library(LibCShared SHARED ${SOURCES})
#install(TARGETS LibCShared DESTINATION usr/lib)
4 changes: 3 additions & 1 deletion Libraries/LibC/crt0_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ int _start(int argc, char** argv, char** env)
__environ_is_malloced = false;

__libc_init();
_init();
// _init();

int status = main(argc, argv, environ);
return status;
}
}

void* __dso_handle = nullptr;

0 comments on commit 58c583f

Please sign in to comment.