218 lines
6.4 KiB
JSON
218 lines
6.4 KiB
JSON
|
|
{
|
|||
|
|
"topic": "go-build-strip",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"schema_version": "1.0.0",
|
|||
|
|
"generated": "2026-09-02T21:20:00+08:00",
|
|||
|
|
"questions": [
|
|||
|
|
{
|
|||
|
|
"id": "sc-001",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 2,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"-s"
|
|||
|
|
],
|
|||
|
|
"question": "Go 编译标志 -s 的作用是什么?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "启用安全模式",
|
|||
|
|
"B": "剥离符号表(函数名、变量名等调试符号)",
|
|||
|
|
"C": "启用静态编译",
|
|||
|
|
"D": "开启优化"
|
|||
|
|
},
|
|||
|
|
"answer": "B",
|
|||
|
|
"explanation": "-s 标志剥离符号表(函数名、变量名等调试符号),-w 标志剥离 DWARF 调试信息。-s -w 组合体积最小化,最适合发布部署。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "sc-002",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 3,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"-w"
|
|||
|
|
],
|
|||
|
|
"question": "Go 编译标志 -w 的作用是什么?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "剥离符号表",
|
|||
|
|
"B": "剥离 DWARF 调试信息(gdb/lldb 所需的详细信息)",
|
|||
|
|
"C": "启用警告",
|
|||
|
|
"D": "开启 Web 支持"
|
|||
|
|
},
|
|||
|
|
"answer": "B",
|
|||
|
|
"explanation": "-w 标志剥离 DWARF 调试信息,这是 gdb/lldb 等调试器所需的详细信息。剥离后无法用 gdb 调试。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "sc-003",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 3,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"体积"
|
|||
|
|
],
|
|||
|
|
"question": "使用 -s 标志编译后,二进制体积大约能减少多少?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "5-10%",
|
|||
|
|
"B": "20-30%",
|
|||
|
|
"C": "50-60%",
|
|||
|
|
"D": "70-80%"
|
|||
|
|
},
|
|||
|
|
"answer": "B",
|
|||
|
|
"explanation": "使用 -s 标志剥离符号表后,二进制体积大约能减少 20-30%。实际节省取决于程序复杂度。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "sc-004",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 4,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"panic"
|
|||
|
|
],
|
|||
|
|
"question": "使用 -s 标志后,panic 堆栈输出会有什么变化?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "完全看不到函数名",
|
|||
|
|
"B": "函数名还在,但完整源码路径丢失",
|
|||
|
|
"C": "没有变化",
|
|||
|
|
"D": "只显示地址"
|
|||
|
|
},
|
|||
|
|
"answer": "B",
|
|||
|
|
"explanation": "使用 -s 剥离符号表后,函数名还在,但完整源码路径丢失。例如从 /home/user/app/main.go:42 变成 main.go:42。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "sc-005",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 3,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"pprof"
|
|||
|
|
],
|
|||
|
|
"question": "剥离符号表后,go tool pprof 会显示什么?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "完整的函数名",
|
|||
|
|
"B": "只有地址(如 0x4a3b20)",
|
|||
|
|
"C": "错误信息",
|
|||
|
|
"D": "没有变化"
|
|||
|
|
},
|
|||
|
|
"answer": "B",
|
|||
|
|
"explanation": "剥离符号表后 pprof 只显示地址(如 0x4a3b20),无法定位到具体函数。线上排查性能问题时非常痛苦。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "sc-006",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 2,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"生产环境"
|
|||
|
|
],
|
|||
|
|
"question": "生产环境发布 Go 程序时应该使用什么编译标志?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "不加任何标志",
|
|||
|
|
"B": "-s -w",
|
|||
|
|
"C": "只用 -w",
|
|||
|
|
"D": "只用 -s"
|
|||
|
|
},
|
|||
|
|
"answer": "B",
|
|||
|
|
"explanation": "生产环境发布应该使用 -s -w 组合,体积最小化,最适合发布部署。同时可以结合 -ldflags 注入版本号等构建信息。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "sc-007",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 4,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"-ldflags"
|
|||
|
|
],
|
|||
|
|
"question": "go build -ldflags=\"-s -w -X main.Version=1.0\" 中 -X 的作用是什么?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "设置编译器参数",
|
|||
|
|
"B": "在剥离调试信息的同时注入编译时变量",
|
|||
|
|
"C": "启用交叉编译",
|
|||
|
|
"D": "设置输出文件名"
|
|||
|
|
},
|
|||
|
|
"answer": "B",
|
|||
|
|
"explanation": "-X 用于在编译时注入变量值,可以同时剥离调试信息(-s -w)和注入版本号、构建时间等信息。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "sc-008",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 3,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"调试"
|
|||
|
|
],
|
|||
|
|
"question": "以下哪种场景不应该使用 -s 标志?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "生产环境部署",
|
|||
|
|
"B": "CI/CD 构建产物",
|
|||
|
|
"C": "本地开发调试",
|
|||
|
|
"D": "嵌入式/IoT"
|
|||
|
|
},
|
|||
|
|
"answer": "C",
|
|||
|
|
"explanation": "本地开发调试需要完整调试信息,不应该使用 -s 标志。生产环境部署、CI/CD 构建产物、嵌入式/IoT 都适合使用 -s -w。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "sc-009",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 4,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"addr2line"
|
|||
|
|
],
|
|||
|
|
"question": "使用 -s -w 后线上出问题,如何通过地址反查行号?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "go tool pprof",
|
|||
|
|
"B": "go tool addr2line",
|
|||
|
|
"C": "go tool trace",
|
|||
|
|
"D": "go tool vet"
|
|||
|
|
},
|
|||
|
|
"answer": "B",
|
|||
|
|
"explanation": "如果保留了构建时生成的 debug info 备份,可以用 go tool addr2line 通过地址反查行号。这是 -s -w 后排查问题的方法之一。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "sc-010",
|
|||
|
|
"type": "single_choice",
|
|||
|
|
"difficulty": 2,
|
|||
|
|
"tags": [
|
|||
|
|
"Go",
|
|||
|
|
"编译",
|
|||
|
|
"语言对比"
|
|||
|
|
],
|
|||
|
|
"question": "以下哪种语言有类似 Go -s -w 的功能?",
|
|||
|
|
"options": {
|
|||
|
|
"A": "Python",
|
|||
|
|
"B": "Rust(strip = true in Cargo.toml)",
|
|||
|
|
"C": "JavaScript",
|
|||
|
|
"D": "Shell"
|
|||
|
|
},
|
|||
|
|
"answer": "B",
|
|||
|
|
"explanation": "Rust 在 Cargo.toml 中设置 strip = true 可以剥离调试信息,类似 Go 的 -s -w。C/C++ 有 strip 命令,Java 有 ProGuard/R8。",
|
|||
|
|
"source": null,
|
|||
|
|
"related": []
|
|||
|
|
}
|
|||
|
|
]
|
|||
|
|
}
|