musl-libc 安装与调试
musl-libc 官网:http://musl.libc.org
1、下载与安装
下载源码并解压
编译参数
./configure [option]... [VAR=VALUE]...
option | 说明 |
--help | 帮助 |
--prefix=DIR | 指定安装目录。默认为/usr/local/musl |
--host=HOST | 设置目标程序运行的CPU平台
一般不需要设置,除非你想要
交叉编译 默认与宿主机一样
|
--enable-FEATURE[=yes|no] | yes: 开启FEATURE
no: 关闭FEATURE |
--enable-static[=yes|no] | 是否生成静态库 |
--enable-shared[=yes|no] | 是否生成动态库 |
--enable-warnings[=yes|no] | 是否开启编译器警告 |
--enable-debug[=yes|no] | 是否带上debug 符号 |
与enable-FEATURE对应的选项,还有disable-FEATURE,disable-FEATURE相当于enable-FEATURE=no
示例:将musl 安装到/usr/local/musl 下,添加调试符号
./configure --prefix=/usr/local/musl CFLAGS='-O2 -v' --enable-debug && make && make install
2、查看musl-gcc 编译器
root@test:/data/musl-1.2.5# ls -al /usr/bin/gcc-musl lrwxrwxrwx 1 root root 28 5月 7 23:36 /usr/bin/gcc-musl -> /usr/local/musl/bin/musl-gcc root@test:/data/musl-1.2.5# cat /usr/bin/gcc-musl #!/bin/sh exec "${REALGCC:-gcc}" -static -g3 "$@" -specs "/usr/local/musl/lib/musl-gcc.specs"
本质上使用的还是gcc,添加了编译参数变成musl-gcc 想了解可以查看 /usr/local/musl/lib/musl-gcc.specs
3、编写第一个程序并调试
root@test:/data/musl_test# cat main.c int main() { return 1; } root@test:/data/musl_test# gcc-musl main.c -g -o test root@test:/data/musl_test# ls -al 总用量 64 drwxr-xr-x 2 root root 4096 5月 10 00:00 . drwxr-xr-x 5 root root 4096 5月 7 23:35 .. -rw-r--r-- 1 root root 31 5月 7 23:35 main.c -rwxr-xr-x 1 root root 50208 5月 10 00:00 test
gdb 调试
root@test:/data/musl_test# gdb ./test GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./test... (gdb) starti Starting program: /data/shiqi/musl_test/test Program stopped. 0x000000000040102f in _start () (gdb) layout asm
进入musl-libc
退出顺序 注册的退出方法->libc退出方法->std退出(关闭)->系统调用退出
人生还有意义。那一定是还在找存在的理由
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2022-05-10 SQL having 子句
2021-05-10 systemctld 启动理解