Skip to content

Commit

Permalink
update 2024年 05月 07日 星期二 20:45:52 CST
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrysisa committed May 7, 2024
1 parent c787eed commit 05b1e41
Show file tree
Hide file tree
Showing 160 changed files with 1,344 additions and 275 deletions.
2 changes: 2 additions & 0 deletions content/posts/sysprog/c-compiler-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ repost:
# See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
---

> 編譯器最佳化篇將以 gcc / llvm 為探討對象,簡述編譯器如何運作,以及如何實現最佳化,佐以探究 C 編譯器原理和案例分析,相信可以釐清許多人對 C 編譯器的誤解,從而開發出更可靠、更高效的程式。
<!--more-->
14 changes: 9 additions & 5 deletions content/posts/sysprog/c-undefined-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ i = i++ + ++i;

从这个角度看,UB 其实就是不遵守语言规范 (等价于 API 的限制) 的行为,编译器对于语言规范的实现一般来说是不考虑 UB 的 (等价于 API 的内部实现),所以因为 UB 造成的结果需要程序员自行承担 (等价于不遵守限制乱用 API 需要自己承担责任)。所以单纯考虑 UB 是没啥意义的,因为它只是结果的具体表现,应该从语言规范和编译器的角度考虑。

除此之外,因为编译器作为语言规范的实作,它在最佳化时会一般只考虑符合语言规范的部分,简而言之,编译器可能会将 UB 部分的代码移除掉 (越激进的优化越有可能)。
除此之外,因为编译器作为语言规范的实作,它在最佳化时会一般 **只考虑符合语言规范** 的部分,简而言之,编译器可能会将 UB 部分的代码移除掉 (越激进的优化越有可能)。因为它认为源程序已经是符合语言规范的,所以会移除掉在符合规范情况下显得不必要的逻辑
{{< /admonition >}}

```c
Expand Down Expand Up @@ -357,12 +357,16 @@ Note that what exactly is considered undefined differs slightly between C and C+
{{< image src="https://image.slidesharecdn.com/bkk16503-160212222433/75/BKK16-503-Undefined-Behavior-and-Compiler-Optimizations-Why-Your-Program-Stopped-Working-With-A-Newer-Compiler-24-2048.jpg" >}}
{{< image src="https://image.slidesharecdn.com/bkk16503-160212222433/75/BKK16-503-Undefined-Behavior-and-Compiler-Optimizations-Why-Your-Program-Stopped-Working-With-A-Newer-Compiler-25-2048.jpg" >}}
- [x] LWN [Fun with NULL pointers](https://lwn.net/Articles/342330/)
- [ ] LWN [Fun with NULL pointers](https://lwn.net/Articles/342330/)
- gcc [PR68853](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68853)
- Wikidepia: [Linux kernel oops](https://en.wikipedia.org/wiki/Linux_kernel_oops)
> There is one little problem with that reasoning, though: NULL (zero) can actually be a valid pointer address. By default, the very bottom of the virtual address space (the "zero page," along with a few pages above it) is set to disallow all access as a way of catching null-pointer bugs (like the one described above) in both user and kernel space. But it is possible, using the mmap() system call, to put real memory at the bottom of the virtual address space.
> This is where the next interesting step in the chain of failures happens: the GCC compiler will, by default, optimize the NULL test out. The reasoning is that, since the pointer has already been dereferenced (and has not been changed), it cannot be NULL. So there is no point in checking it. Once again, this logic makes sense most of the time, but not in situations where NULL might actually be a valid pointer.
> A NULL pointer was dereferenced before being checked, the check was optimized out by the compiler
- gcc [PR68853](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68853)
- Wikidepia: [Linux kernel oops](https://en.wikipedia.org/wiki/Linux_kernel_oops)
{{< image src="https://upload.wikimedia.org/wikipedia/commons/6/6a/Linux-2.6-oops-parisc.jpg" >}}
### Pointer arithmetic that wraps
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ <h1 id="error-emoji"></h1>
document.getElementById('error-emoji').appendChild(document.createTextNode(emojiArray[Math.floor(Math.random() * emojiArray.length)]));
})();
</script></main><footer class="footer">
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.2">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
</div><div class="footer-line copyright" itemscope itemtype="http://schema.org/CreativeWork"><i class="fa-regular fa-copyright fa-fw" aria-hidden="true"></i>
<span itemprop="copyrightYear">2021 - 2024</span><span class="author" itemprop="copyrightHolder">
<a href="https://github.com/ccrysisa"target="_blank" rel="external nofollow noopener noreferrer">ccrysisa</a></span><span class="license footer-divider"><a rel="license external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div><div class="footer-line statistics"></div><div class="footer-line visitor">
Expand Down
2 changes: 1 addition & 1 deletion docs/categories/c/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
<a href="/posts/c-specification/" class="archive-item-link">C 语言规格书 重点提示</a>
<span class="archive-item-date" title='2024-01-06 16:07:25'>01-06</span>
</article></div></main><footer class="footer">
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.2">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
</div><div class="footer-line copyright" itemscope itemtype="http://schema.org/CreativeWork"><i class="fa-regular fa-copyright fa-fw" aria-hidden="true"></i>
<span itemprop="copyrightYear">2021 - 2024</span><span class="author" itemprop="copyrightHolder">
<a href="https://github.com/ccrysisa"target="_blank" rel="external nofollow noopener noreferrer">ccrysisa</a></span><span class="license footer-divider"><a rel="license external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div><div class="footer-line statistics"></div><div class="footer-line visitor">
Expand Down
4 changes: 3 additions & 1 deletion docs/categories/c/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<pubDate>Wed, 24 Apr 2024 21:09:59 &#43;0800</pubDate>
<author>ccrysisa</author>
<guid>https://ccrysisa.github.io/posts/c-compiler-optimization/</guid>
<description><![CDATA[]]></description>
<description><![CDATA[<blockquote>
<p>編譯器最佳化篇將以 gcc / llvm 為探討對象,簡述編譯器如何運作,以及如何實現最佳化,佐以探究 C 編譯器原理和案例分析,相信可以釐清許多人對 C 編譯器的誤解,從而開發出更可靠、更高效的程式。</p>
</blockquote>]]></description>
</item>
<item>
<title>你所不知道的 C 语言: 未定义/未指定行为篇</title>
Expand Down
2 changes: 1 addition & 1 deletion docs/categories/concurrency/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<a href="/posts/concurrency-concepts/" class="archive-item-link">并行程序设计: 概念</a>
<span class="archive-item-date" title='2024-03-08 17:29:25'>03-08</span>
</article></div></main><footer class="footer">
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.2">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
</div><div class="footer-line copyright" itemscope itemtype="http://schema.org/CreativeWork"><i class="fa-regular fa-copyright fa-fw" aria-hidden="true"></i>
<span itemprop="copyrightYear">2021 - 2024</span><span class="author" itemprop="copyrightHolder">
<a href="https://github.com/ccrysisa"target="_blank" rel="external nofollow noopener noreferrer">ccrysisa</a></span><span class="license footer-divider"><a rel="license external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div><div class="footer-line statistics"></div><div class="footer-line visitor">
Expand Down
2 changes: 1 addition & 1 deletion docs/categories/csapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<a href="/posts/csapp-ch2/" class="archive-item-link">CS:APP 第 2 章重点提示和练习</a>
<span class="archive-item-date" title='2024-04-19 15:33:40'>04-19</span>
</article></div></main><footer class="footer">
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.2">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
</div><div class="footer-line copyright" itemscope itemtype="http://schema.org/CreativeWork"><i class="fa-regular fa-copyright fa-fw" aria-hidden="true"></i>
<span itemprop="copyrightYear">2021 - 2024</span><span class="author" itemprop="copyrightHolder">
<a href="https://github.com/ccrysisa"target="_blank" rel="external nofollow noopener noreferrer">ccrysisa</a></span><span class="license footer-divider"><a rel="license external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div><div class="footer-line statistics"></div><div class="footer-line visitor">
Expand Down
2 changes: 1 addition & 1 deletion docs/categories/draft/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<a href="/posts/hello_world/" class="archive-item-link">Hello, World</a>
<span class="archive-item-date" title='2023-12-23 20:23:12'>12-23</span>
</article></div></main><footer class="footer">
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.2">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
</div><div class="footer-line copyright" itemscope itemtype="http://schema.org/CreativeWork"><i class="fa-regular fa-copyright fa-fw" aria-hidden="true"></i>
<span itemprop="copyrightYear">2021 - 2024</span><span class="author" itemprop="copyrightHolder">
<a href="https://github.com/ccrysisa"target="_blank" rel="external nofollow noopener noreferrer">ccrysisa</a></span><span class="license footer-divider"><a rel="license external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div><div class="footer-line statistics"></div><div class="footer-line visitor">
Expand Down
2 changes: 1 addition & 1 deletion docs/categories/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ <h3 class="card-item-title">
<a href="/posts/nju-osdi/" class="archive-item-link">南京大学 操作系统: 设计与实现 重点提示</a>
</article></div>
</div></div></div></main><footer class="footer">
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.2">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
</div><div class="footer-line copyright" itemscope itemtype="http://schema.org/CreativeWork"><i class="fa-regular fa-copyright fa-fw" aria-hidden="true"></i>
<span itemprop="copyrightYear">2021 - 2024</span><span class="author" itemprop="copyrightHolder">
<a href="https://github.com/ccrysisa"target="_blank" rel="external nofollow noopener noreferrer">ccrysisa</a></span><span class="license footer-divider"><a rel="license external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div><div class="footer-line statistics"></div><div class="footer-line visitor">
Expand Down
2 changes: 1 addition & 1 deletion docs/categories/linux-kernel-internals/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
<a href="/categories/linux-kernel-internals/page/2/">2</a>
</span>
</li></ul></div></main><footer class="footer">
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.2">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
</div><div class="footer-line copyright" itemscope itemtype="http://schema.org/CreativeWork"><i class="fa-regular fa-copyright fa-fw" aria-hidden="true"></i>
<span itemprop="copyrightYear">2021 - 2024</span><span class="author" itemprop="copyrightHolder">
<a href="https://github.com/ccrysisa"target="_blank" rel="external nofollow noopener noreferrer">ccrysisa</a></span><span class="license footer-divider"><a rel="license external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div><div class="footer-line statistics"></div><div class="footer-line visitor">
Expand Down
4 changes: 3 additions & 1 deletion docs/categories/linux-kernel-internals/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<pubDate>Wed, 24 Apr 2024 21:09:59 &#43;0800</pubDate>
<author>ccrysisa</author>
<guid>https://ccrysisa.github.io/posts/c-compiler-optimization/</guid>
<description><![CDATA[]]></description>
<description><![CDATA[<blockquote>
<p>編譯器最佳化篇將以 gcc / llvm 為探討對象,簡述編譯器如何運作,以及如何實現最佳化,佐以探究 C 編譯器原理和案例分析,相信可以釐清許多人對 C 編譯器的誤解,從而開發出更可靠、更高效的程式。</p>
</blockquote>]]></description>
</item>
<item>
<title>你所不知道的 C 语言: 未定义/未指定行为篇</title>
Expand Down
2 changes: 1 addition & 1 deletion docs/categories/linux-kernel-internals/page/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
<a href="/categories/linux-kernel-internals/page/2/">2</a>
</span>
</li></ul></div></main><footer class="footer">
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.2">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
<div class="footer-container"><div class="footer-line powered"><a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreferrer" title="Hugo 0.121.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/hugo-fixit/FixIt" target="_blank" rel="external" title="FixIt v0.2.18-lts.5"><img class="fixit-icon" src="/fixit.min.svg" alt="FixIt logo" />&nbsp;FixIt</a>
</div><div class="footer-line copyright" itemscope itemtype="http://schema.org/CreativeWork"><i class="fa-regular fa-copyright fa-fw" aria-hidden="true"></i>
<span itemprop="copyrightYear">2021 - 2024</span><span class="author" itemprop="copyrightHolder">
<a href="https://github.com/ccrysisa"target="_blank" rel="external nofollow noopener noreferrer">ccrysisa</a></span><span class="license footer-divider"><a rel="license external nofollow noopener noreferrer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div><div class="footer-line statistics"></div><div class="footer-line visitor">
Expand Down
Loading

0 comments on commit 05b1e41

Please sign in to comment.