From f13e9fb5682cc37ae7772b39205040243eab00ed Mon Sep 17 00:00:00 2001 From: Tie Liu Date: Fri, 9 Jun 2023 17:35:25 +0800 Subject: [PATCH] meson build for sysboost --- .gitignore | 1 + ABI_VERSION | 1 + Makefile | 29 +++++++++- README.en.md | 16 ------ README.md | 55 ++++++------------- VERSION | 1 + bin/meson.build | 0 libs/meson.build | 0 meson.build | 115 ++++++++++++++++------------------------ src/libhook/meson.build | 17 ++---- src/meson.build | 49 ++++++++++++++--- 11 files changed, 140 insertions(+), 144 deletions(-) create mode 100644 ABI_VERSION create mode 100644 VERSION create mode 100644 bin/meson.build create mode 100644 libs/meson.build diff --git a/.gitignore b/.gitignore index 2567bb5..973aad3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build *.pyc ~* .vscode/ +.idea/ diff --git a/ABI_VERSION b/ABI_VERSION new file mode 100644 index 0000000..d3827e7 --- /dev/null +++ b/ABI_VERSION @@ -0,0 +1 @@ +1.0 diff --git a/Makefile b/Makefile index 7c491c7..8912538 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,28 @@ sysboostd: clear cargo build +sysboost: + rm -rf build + meson build + +sysboost-debug: + rm -rf build + meson build --buildtype=debug + make -C sysboost + clean: + ninja -C build clean + make -C sysboost clean cargo clean +format: + meson --internal clangformat ./ ./build + cargo fmt + +static_template_debug: + readelf -W -a ./build/sysboost/src/static_template/static_template > static_template.elf + objdump -d ./build/sysboost/src/static_template/static_template > static_template.asm + test: sysboostd clear cp -f $(SYSBOOSTD) $(SYSBOOSTD_INSTALL_PATH) @@ -23,5 +42,11 @@ test: sysboostd test-debug: cargo test -- --nocapture -format: - cargo fmt +bash-test: static_template_debug + clear + ./build/sysboost/sysboost -static ./build/sysboost/src/static_template/sysboost_static_template bash/bash bash/libtinfo.so + readelf -W -a bash.rto > bash.rto.elf + objdump -d bash.rto > bash.rto.asm + +bash-gdb: + gdb --args ./build/sysboost/sysboost -static ./build/sysboost/src/static_template/static_template bash/bash bash/libtinfo.so \ No newline at end of file diff --git a/README.en.md b/README.en.md index a62a163..9bd75bf 100644 --- a/README.en.md +++ b/README.en.md @@ -1,23 +1,7 @@ -<<<<<<< HEAD -<<<<<<< HEAD # sysboost #### Description Sysboost converts dynamic links into static links by combining executable files and dynamic library files. This reduces the overhead and delay of dynamic links and improves the execution efficiency of programs. -======= -# native-turbo - -#### Description -Native-Turbo is the performance optimization framework of native microarchitecture of operating system. ->>>>>>> e2ad41a (Initial commit) - - -======= -# sysboost - -#### Description -Sysboost converts dynamic links into static links by combining executable files and dynamic library files. This reduces the overhead and delay of dynamic links and improves the execution efficiency of programs. ->>>>>>> 9a6e0d8 (Splitting the sysboost repository) #### Software Architecture Software architecture description diff --git a/README.md b/README.md index 6405e69..9bd75bf 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,36 @@ -<<<<<<< HEAD -<<<<<<< HEAD # sysboost -#### 介绍 +#### Description Sysboost converts dynamic links into static links by combining executable files and dynamic library files. This reduces the overhead and delay of dynamic links and improves the execution efficiency of programs. -======= -# native-turbo -#### 介绍 -<<<<<<< HEAD -Native-Turbo is the performance optimization framework of native microarchitecture of operating system. ->>>>>>> e2ad41a (Initial commit) -======= -Native-Turbo 是操作系统原生性能加速框架; 通过微架构优化和软硬件协同等技术, 提升大型应用性能; +#### Software Architecture +Software architecture description - ->>>>>>> 928a69a (native-turbo: add doc and architecture description) -======= -# sysboost - -#### 介绍 -Sysboost converts dynamic links into static links by combining executable files and dynamic library files. This reduces the overhead and delay of dynamic links and improves the execution efficiency of programs. ->>>>>>> 9a6e0d8 (Splitting the sysboost repository) - -#### 软件架构 -软件架构说明 - - -#### 安装教程 +#### Installation 1. xxxx 2. xxxx 3. xxxx -#### 使用说明 +#### Instructions 1. xxxx 2. xxxx 3. xxxx -#### 参与贡献 +#### Contribution -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +1. Fork the repository +2. Create Feat_xxx branch +3. Commit your code +4. Create Pull Request -#### 特技 +#### Gitee Feature -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md +2. Gitee blog [blog.gitee.com](https://blog.gitee.com) +3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) +4. The most valuable open source project [GVP](https://gitee.com/gvp) +5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) +6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file diff --git a/bin/meson.build b/bin/meson.build new file mode 100644 index 0000000..e69de29 diff --git a/libs/meson.build b/libs/meson.build new file mode 100644 index 0000000..e69de29 diff --git a/meson.build b/meson.build index d01208d..3dbbbaf 100644 --- a/meson.build +++ b/meson.build @@ -1,78 +1,57 @@ # SPDX-License-Identifier: MulanPSL-2.0 -sysboosts = [ - 'src', - 'tests' -] - -default_cflags = machine_args - -if get_option('buildtype').contains('debug') - default_cflags += [ '-pedantic', '-DPEDANTIC' ] +project('SYSBOOST', 'C', 'rust', + version: run_command(find_program('cat', 'more'), files('VERSION'), check: true).stdout().strip(), + license: 'MulanPSL', + default_options: [ + 'buildtype=release', + 'default_library=static', + 'warning_level=2', + ], + meson_version: '>= 0.49.2' +) + +# check for developer mode +debug_mode = false +if get_option('debug_mode').auto() + if meson.version().version_compare('>=0.53') # fs module available + fs = import('fs') + debug_mode = fs.is_dir('.git') + endif else - default_cflags += [ '-UPEDANTIC' ] + debug_mode = get_option('debug_mode').enabled() endif - -if cc.has_argument('-Wno-format-truncation') - default_cflags += '-Wno-format-truncation' +if debug_mode + message('## Building in Developer Mode ##') endif -default_ldflags = lk_args - -foreach src:sysboosts - build = true - sources = [] - includes = [] - cflags = default_cflags + ['-Wno-pointer-arith', '-Wno-pedantic'] - ldflags = default_ldflags - objs = [] - ext_deps = [] - deps = [] - - subdir(src) +# set up some global vars for compiler, platform, configuration, etc. +static_link_libraries = [] +cc = meson.get_compiler('c') +rustc = meson.get_compiler('rust') +si_source_root = meson.current_source_dir() +si_build_root = meson.current_build_dir() +si_static_libraries = [] +abi_version_file = files('ABI_VERSION') + +if host_machine.cpu_family().startswith('x86') + arch_subdir = 'x86' +elif host_machine.cpu_family().startswith('arm') or host_machine.cpu_family().startswith('aarch') + arch_subdir = 'arm' +elif host_machine.cpu_family().startswith('riscv') + arch_subdir = 'riscv' +endif - dep_objs = [] - foreach dep_name:deps - if not is_variable(dep_name) - build = false - message('Missing dependency "@0@" for app "@1@"'.format(dep_name, src)) - break - endif - dep_objs += [get_variable(dep_name)] - message('"@0@" add depend lib "@1@"'.format(src, dep_name)) - endforeach +machine_args = ['-Wall', '-Werror', '-Wextra', '-Wformat', '-D_GNU_SOURCE', + '-fno-jump-tables', '-Wl,-z,relro,-z,now', '-Bsymbolic', '-zcommon-page-size=2097152', '-zmax-page-size=2097152'] +lk_args = [] - if not build - continue - endif +# build sysboostd +subdir('libs') +subdir('bin') - link_libs = [] +# build sysboost +subdir('src') - if get_option('buildtype').contains('debug') - cflags += ['-DDEBUG', '-Og', '-g', '-rdynamic'] - ldflags += ['-rdynamic'] - else - cflags += ['-O2'] - endif - - if src == 'tests' - foreach tt:tests - path = join_paths(src, tt) - subdir(path) - endforeach - else - link_libs = si_static_libraries - cflags += ['-fpic', '-pie'] - executable('sysboost', sources, - install: true, - c_args: cflags, - link_args: ldflags + ['-Wl,--whole-archive', '/usr/lib64/liblzma.a', '-Wl,--no-whole-archive'], - link_whole: link_libs, - dependencies: ext_deps + dep_objs, - include_directories: includes) - foreach tl:tools - path = join_paths(src, tl) - subdir(path) - endforeach - endif -endforeach \ No newline at end of file +# build tests +subdir('tests') \ No newline at end of file diff --git a/src/libhook/meson.build b/src/libhook/meson.build index 9bc9044..b59660f 100644 --- a/src/libhook/meson.build +++ b/src/libhook/meson.build @@ -4,25 +4,14 @@ sources = files('dlsym_hook.c') cflags += ['-v'] ldflags += ['-ldl'] -link_libs = si_static_libraries includes = [] -deps += ['static_si_array', 'static_si_sys'] -dep_objs = [] -foreach dep_name:deps - if not is_variable(dep_name) - build = false - message('Missing dependency "@0@" for app "@1@"'.format(dep_name, src)) - break - endif - dep_objs += [get_variable(dep_name)] - message('"@0@" add depend lib "@1@"'.format(src, dep_name)) -endforeach +deps = [] libhook = shared_library('hook', sources, install: true, c_args: cflags, link_args: ldflags, - link_whole: link_libs, - dependencies: dep_objs, + link_with: link_libs, + dependencies: deps, include_directories: includes) diff --git a/src/meson.build b/src/meson.build index 490728f..3467340 100644 --- a/src/meson.build +++ b/src/meson.build @@ -6,7 +6,41 @@ elif arch_subdir == 'arm' cpu_arch = 'aarch64' endif -sources = files([ +tools = [ + 'static_template', + 'libhook' +] + +default_cflags = machine_args + ['-Wno-pointer-arith', '-Wno-pedantic'] +default_ldflags = lk_args + +ext_deps = [] +deps = static_link_libraries + ['libsi_sys.a', 'libsi_array.a'] +link_libs = si_static_libraries + +if get_option('buildtype').contains('debug') + default_cflags += [ '-pedantic', '-DPEDANTIC', '-Og', '-g', '-rdynamic' ] + default_ldflags += ['-rdynamic'] +else + default_cflags += [ '-UPEDANTIC', '-O2' ] +endif + +if cc.has_argument('-Wno-format-truncation') + default_cflags += '-Wno-format-truncation' +endif + +foreach tool:tools + name = tool + sources = [] + includes = [] + cflags = default_cflags + ldflags = default_ldflags + + subdir(name) +endforeach + + +core_sources = files([ 'main.c', 'elf_link_elf.c', 'elf_read_elf.c', @@ -19,9 +53,12 @@ sources = files([ 'elf_write_elf.c', ]) -tools = [ - 'static_template', - 'libhook' -] +cflags += ['-fpic', '-pie'] -deps += ['static_si_array', 'static_si_sys'] \ No newline at end of file +executable('sysboost', core_sources, + install: true, + c_args: default_cflags, + link_args: default_ldflags + ['-Wl,--whole-archive', '/usr/lib64/liblzma.a', '-Wl,--no-whole-archive'], + link_with: link_libs, + dependencies: deps, + include_directories: includes) \ No newline at end of file -- Gitee