diff --git a/articles/20230526-section-gc-part1.md b/articles/20230526-section-gc-part1.md index 954eb332b9f5219df657fee95a765a92324fbafb..614bf701acdb1e559f4a52d2b5453049620742a2 100644 --- a/articles/20230526-section-gc-part1.md +++ b/articles/20230526-section-gc-part1.md @@ -1,14 +1,22 @@ -> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.1 - [toc codeinline pangu]
+> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces urls refs autocorrect]
> Author: 谭源
> Date: 2022/05/26
> Revisor: Falcon
> Project: [RISC-V Linux 内核剖析](https://gitee.com/tinylab/riscv-linux)
> Sponsor: PLCT Lab, ISCAS -# Section GC 分析 —— 原理简介 +# Section GC 分析 - Part 1 原理简介 ## 概述 +本文为 [解决 Linux 内核 Section GC 失败问题][006] 系列文章的一部分。 + +- [Section GC 分析 - Part 1 原理简介][001] +- [Section GC 分析 - Part 2 gold 源码解析][002] +- [Section GC 分析 - Part 3 引用建立过程][003] +- [解决 Linux 内核 Section GC 失败问题 - Part 1][004] +- [解决 Linux 内核 Section GC 失败问题 - Part 2][005] + 这篇文章将简单介绍 `--gc-sections`。 GCC 的 `--gc-sections` 选项可以在链接时对未使用到的函数和变量进行裁剪。 @@ -156,3 +164,10 @@ Section GC 是一种二进制文件的编译和链接时裁剪方式,它在编 ## 参考资料 - Tiny Linux Kernel Project: Section Garbage Collection Patchset + +[001]: 20230526-section-gc-part1.md +[002]: 20230526-section-gc-part2.md +[003]: 20230615-section-gc-part3.md +[004]: 20230730-section-gc-no-more-keep-part1.md +[005]: 20230928-section-gc-no-more-keep-part2.md +[006]: https://summer-ospp.ac.cn/org/prodetail/2341f0584 diff --git a/articles/20230526-section-gc-part2.md b/articles/20230526-section-gc-part2.md index 3edbb6db778dfe0018f98de945f4635523f770b6..5351c7c81716d9c73eeeebd5379189d781f19aca 100644 --- a/articles/20230526-section-gc-part2.md +++ b/articles/20230526-section-gc-part2.md @@ -1,17 +1,25 @@ -> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.1 - [spaces comments codeinline pangu]
+> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces urls]
> Author: 谭源
> Date: 2022/05/26
> Revisor: Falcon
> Project: [RISC-V Linux 内核剖析](https://gitee.com/tinylab/riscv-linux)
> Sponsor: PLCT Lab, ISCAS -# Section GC 分析 —— gold 源码解析 +# Section GC 分析 - Part 2 gold 源码解析 ## 概述 +本文为 [解决 Linux 内核 Section GC 失败问题][006] 系列文章的一部分。 + +- [Section GC 分析 - Part 1 原理简介][001] +- [Section GC 分析 - Part 2 gold 源码解析][002] +- [Section GC 分析 - Part 3 引用建立过程][003] +- [解决 Linux 内核 Section GC 失败问题 - Part 1][004] +- [解决 Linux 内核 Section GC 失败问题 - Part 2][005] + ld.gold 是 GNU binutils 套件的一个组成部分,是 ld.bfd(通常简称为 ld)的一个替代品,设计上更关注性能和链接大型应用的能力。 -上一篇文章我们介绍了 `--gc-sections` 的用法,这篇文章将结合 gold,进一步介绍链接器遍历引用并删除未使用 section 的过程。我们将分析 binutils 的 2.40 版本源代码。 +上一篇文章[001]我们介绍了 `--gc-sections` 的用法,这篇文章将结合 gold,进一步介绍链接器遍历引用并删除未使用 section 的过程。我们将分析 binutils 的 2.40 版本源代码。 ## 准备工作 @@ -360,3 +368,10 @@ gold 链接器的代码比较清晰,可以很快的明白每个函数的作用 ## 参考资料 - Tiny Linux Kernel Project: Section Garbage Collection Patchset + +[001]: 20230526-section-gc-part1.md +[002]: 20230526-section-gc-part2.md +[003]: 20230615-section-gc-part3.md +[004]: 20230730-section-gc-no-more-keep-part1.md +[005]: 20230928-section-gc-no-more-keep-part2.md +[006]: https://summer-ospp.ac.cn/org/prodetail/2341f0584 diff --git a/articles/20230615-section-gc-part3.md b/articles/20230615-section-gc-part3.md index 9e2534587e5a2525aeaed2c98c8d39cfa2bed60a..115c3fdeaeed90f2de8cb4c21299411ead2b5661 100644 --- a/articles/20230615-section-gc-part3.md +++ b/articles/20230615-section-gc-part3.md @@ -1,14 +1,22 @@ -> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc1 - [spaces toc codeinline urls]
+> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces]
> Author: 谭源
> Date: 2022/06/15
> Revisor: Falcon
> Project: [RISC-V Linux 内核剖析](https://gitee.com/tinylab/riscv-linux)
> Sponsor: PLCT Lab, ISCAS -# Section GC 分析 —— 引用建立过程 +# Section GC 分析 - Part 3 引用建立过程 ## 概述 +本文为 [解决 Linux 内核 Section GC 失败问题][009] 系列文章的一部分。 + +- [Section GC 分析 - Part 1 原理简介][004] +- [Section GC 分析 - Part 2 gold 源码解析][001] +- [Section GC 分析 - Part 3 引用建立过程][006] +- [解决 Linux 内核 Section GC 失败问题 - Part 1][007] +- [解决 Linux 内核 Section GC 失败问题 - Part 2][008] + [上一篇文章][001] 我们介绍了在开启 `--gc-sections` 选项后,gold 链接器删除未使用到的 section 的过程。 这篇文章我们将结合 `ld.bfd` 链接器(即默认使用的 `ld`)源码,探索链接器建立引用关系的过程。 @@ -321,3 +329,8 @@ Relocation section '.rela.eh_frame' at offset 0x2a8 contains 4 entries: [001]: 20230526-section-gc-part2.md [002]: https://hansimov.gitbook.io/csapp/part2/ch07-linking/7.5-symbols-and-symbol-tables [003]: https://hansimov.gitbook.io/csapp/part2/ch07-linking/7.7-relocation +[004]: 20230526-section-gc-part1.md +[006]: 20230615-section-gc-part3.md +[007]: 20230730-section-gc-no-more-keep-part1.md +[008]: 20230928-section-gc-no-more-keep-part2.md +[009]: https://summer-ospp.ac.cn/org/prodetail/2341f0584 diff --git a/articles/20230730-section-gc-no-more-keep-part1.md b/articles/20230730-section-gc-no-more-keep-part1.md index a7702763f1914aacf4c89306ea67e82c314b3076..60c34ba17f2520fe081ddfa558545200d8b984c1 100644 --- a/articles/20230730-section-gc-no-more-keep-part1.md +++ b/articles/20230730-section-gc-no-more-keep-part1.md @@ -1,4 +1,4 @@ -> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc1 - [spaces autocorrect]
+> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces]
> Author: Yuan Tan
> Date: 20230730
> Revisor: Falcon
@@ -6,9 +6,17 @@ > Proposal: [通过编译器解决因链接过程 KEEP 操作引起的 Section GC 失败问题][004]
> Sponsor: PLCT Lab, ISCAS -# 解决 Linux 内核 Section GC 失败问题 +# 解决 Linux 内核 Section GC 失败问题 - Part 1 -## 背景简介 +## 概述 + +本文为 [解决 Linux 内核 Section GC 失败问题](https://summer-ospp.ac.cn/org/prodetail/2341f0584) 系列文章的一部分。 + +- [Section GC 分析 - Part 1 原理简介](20230526-section-gc-part1.md) +- [Section GC 分析 - Part 2 gold 源码解析](20230526-section-gc-part2.md) +- [Section GC 分析 - Part 3 引用建立过程](20230615-section-gc-part3.md) +- [解决 Linux 内核 Section GC 失败问题 - Part 1](20230730-section-gc-no-more-keep-part1.md) +- [解决 Linux 内核 Section GC 失败问题 - Part 2](20230928-section-gc-no-more-keep-part2.md) 前面几篇文章介绍了 Section GC 的使用方法和原理,现在我们来研究 Linux 内核中的 Section GC 失败问题。 @@ -225,7 +233,7 @@ ld: removing unused section '.riscv.attributes' in file '/usr/lib/gcc-cross/risc 在 `example2.c` 中,`.pushsection pushed_section,aR` 使用 `R` flag 强制保留了 `pushed_section`。 -`.long ((1b) - .)` 这是一个用于计算偏移量的指令。1b 是对先前定义的标记(label)的引用,表示 `标记 1` 的地址;`.` 表示当前位置的地址。因此,`(1b) - .` 将计算存在于 `fun()` 中的 `标记 1` 和当前位置之间的偏移量。 +`.long ((1b) -.)` 这是一个用于计算偏移量的指令。1b 是对先前定义的标记(label)的引用,表示 `标记 1` 的地址;`.` 表示当前位置的地址。因此,`(1b) -.` 将计算存在于 `fun()` 中的 `标记 1` 和当前位置之间的偏移量。 这里 `pushed_section` 引用了 `section_pusher()`,让 `section_pusher()` 成为了 `pushed_section` 的子节,形成了错误的依赖关系。不仅 `pushed_section` 会被强制保留,`section_pusher()` 也会被强制保留。 diff --git a/articles/20230928-section-gc-no-more-keep-part2.md b/articles/20230928-section-gc-no-more-keep-part2.md index 88ebc299346b68c5e0da4163ad340dba35512a82..70dd37b92fdcfe8affe20fd03a1de8b10d2ab424 100644 --- a/articles/20230928-section-gc-no-more-keep-part2.md +++ b/articles/20230928-section-gc-no-more-keep-part2.md @@ -1,4 +1,4 @@ -> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [codeblock pangu]
+> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces toc urls]
> Author: Yuan Tan
> Date: 20230929
> Revisor: Falcon
@@ -7,7 +7,15 @@ # 解决 Linux 内核 Section GC 失败问题 - Part 2 -## 背景简介 +## 概述 + +本文为 [解决 Linux 内核 Section GC 失败问题][008] 系列文章的一部分。 + +- [Section GC 分析 - Part 1 原理简介][003] +- [Section GC 分析 - Part 2 gold 源码解析][004] +- [Section GC 分析 - Part 3 引用建立过程][005] +- [解决 Linux 内核 Section GC 失败问题 - Part 1][006] +- [解决 Linux 内核 Section GC 失败问题 - Part 2][007] 前面几篇文章介绍了 Section GC 的使用方法和原理,以及 Linux 内核中的 Section GC 失败问题。 @@ -258,3 +266,9 @@ $ nm build/riscv64/virt/linux/v6.6-rc2/vmlinux | grep "T __riscv_sys" | grep -v [001]: https://sourceware.org/binutils/docs/as/Section.html [002]: https://sourceware.org/pipermail/binutils/2023-July/128521.html +[003]: 20230526-section-gc-part1.md +[004]: 20230526-section-gc-part2.md +[005]: 20230615-section-gc-part3.md +[006]: 20230730-section-gc-no-more-keep-part1.md +[007]: 20230928-section-gc-no-more-keep-part2.md +[008]: https://summer-ospp.ac.cn/org/prodetail/2341f0584