<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>goc 专栏 :: yafeng 的博客</title><link>http://yafengabc.github.io/goc/index.html</link><description>用 Go 从零写一个不依赖 gcc、不依赖 libc的 C 编译器。本专栏记录 goc 的设计取舍、体积实测、项目状态与上手教程。</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Wed, 07 Oct 2026 01:20:00 +0800</lastBuildDate><atom:link href="http://yafengabc.github.io/goc/index.xml" rel="self" type="application/rss+xml"/><item><title>开发笔记：gocl 变参窄整型丢符号性</title><link>http://yafengabc.github.io/goc/devnotes/01-%E5%8F%98%E5%8F%82%E7%AA%84%E6%95%B4%E5%9E%8B%E4%B8%A2%E7%AC%A6%E5%8F%B7%E6%80%A7/index.html</link><pubDate>Tue, 06 Oct 2026 14:30:00 +0800</pubDate><guid>http://yafengabc.github.io/goc/devnotes/01-%E5%8F%98%E5%8F%82%E7%AA%84%E6%95%B4%E5%9E%8B%E4%B8%A2%E7%AC%A6%E5%8F%B7%E6%80%A7/index.html</guid><description>gocl（LLVM 后端）把所有经变参传递的 32 位整型的符号性丢掉。本文记录从「误诊为有符号除法」到「定位为变参8 字节槽未填满」的完整排查过程、根因、修复，以及两次误诊里学到的东西。</description></item><item><title>第 0 章：为什么再写一个 C 编译器</title><link>http://yafengabc.github.io/goc/00-%E4%B8%BA%E4%BB%80%E4%B9%88%E5%86%99goc/index.html</link><pubDate>Tue, 06 Oct 2026 12:10:00 +0800</pubDate><guid>http://yafengabc.github.io/goc/00-%E4%B8%BA%E4%BB%80%E4%B9%88%E5%86%99goc/index.html</guid><description>编译器套娃已经很多了，为什么还要用 Go 写一个 C 编译器？goc 的答案是三条取舍：不依赖 gcc、不依赖 libc、不假设 CPU 行为。本文讲清这个定位怎么决定了整个项目形态。</description></item><item><title>开发笔记：把 gocld 变成真正的链接器</title><link>http://yafengabc.github.io/goc/devnotes/02-%E6%8A%8Agocld%E5%8F%98%E6%88%90%E7%9C%9F%E6%AD%A3%E7%9A%84%E9%93%BE%E6%8E%A5%E5%99%A8/index.html</link><pubDate>Tue, 06 Oct 2026 17:10:00 +0800</pubDate><guid>http://yafengabc.github.io/goc/devnotes/02-%E6%8A%8Agocld%E5%8F%98%E6%88%90%E7%9C%9F%E6%AD%A3%E7%9A%84%E9%93%BE%E6%8E%A5%E5%99%A8/index.html</guid><description>让 goc -c 产出真正可重定位的目标文件（PE 的 COFF 与 Linux 的 ELF64），让 gocld 成为可独立运行的链接器。本文记录这次改造里踩到的字节级坑：字符串表 NUL 约定、Elf64_Sym 漏掉 st_other、section 索引 1-based、sh_link 偏移差 4 字节、deferred 分支跳过重定位生成，以及 goa 与 ELF 两套PC-relative 算术的对齐。</description></item><item><title>第 1 章：5 分钟跑起来</title><link>http://yafengabc.github.io/goc/01-%E4%BA%94%E5%88%86%E9%92%9F%E4%B8%8A%E6%89%8B/index.html</link><pubDate>Tue, 06 Oct 2026 12:20:00 +0800</pubDate><guid>http://yafengabc.github.io/goc/01-%E4%BA%94%E5%88%86%E9%92%9F%E4%B8%8A%E6%89%8B/index.html</guid><description>从零编译第一个 goc 程序：Windows 上装工具链、跑通 Hello World、输出汇编、交叉编译 Linux ELF，以及三个必踩的坑（goclib 路径、-o 语义、printf 宽度）。</description></item><item><title>开发笔记：让 gocld 链接 .rsrc 资源节</title><link>http://yafengabc.github.io/goc/devnotes/03-%E8%AE%A9gocld%E9%93%BE%E6%8E%A5rsrc%E8%B5%84%E6%BA%90%E8%8A%82/index.html</link><pubDate>Tue, 06 Oct 2026 20:40:00 +0800</pubDate><guid>http://yafengabc.github.io/goc/devnotes/03-%E8%AE%A9gocld%E9%93%BE%E6%8E%A5rsrc%E8%B5%84%E6%BA%90%E8%8A%82/index.html</guid><description>让 gocld 能读入、合并并写出 PE 的 .rsrc 资源节。本文记录这次实现里踩到的字节级坑：OffsetToData 是文件偏移而不是 RVA 造成的循环依赖、IMAGE_RESOURCE_DIRECTORY_ENTRY 两个字段共用最高位作标志、rd32 的符号扩展把 0x80000000 变成负数、名字字符串是节内绝对偏移而非紧跟 entry、以及名字池的 NUL 终止符。</description></item><item><title>第 2 章：写第一个 Windows GUI 程序</title><link>http://yafengabc.github.io/goc/02-%E7%AC%AC%E4%B8%80%E4%B8%AAgui%E7%A8%8B%E5%BA%8F/index.html</link><pubDate>Tue, 06 Oct 2026 12:30:00 +0800</pubDate><guid>http://yafengabc.github.io/goc/02-%E7%AC%AC%E4%B8%80%E4%B8%AAgui%E7%A8%8B%E5%BA%8F/index.html</guid><description>用 goc 写一个弹 MessageBox 的 Windows GUI 程序，编译出 37KB 的 exe，只依赖 kernel32 和 user32 两个 DLL——没有 msvcrt。附完整 API 说明与常见错误排查。</description></item><item><title>开发笔记：gocl（LLVM 后端）踩过的坑</title><link>http://yafengabc.github.io/goc/devnotes/04-gocl-llvm%E5%90%8E%E7%AB%AF%E8%B8%A9%E8%BF%87%E7%9A%84%E5%9D%91/index.html</link><pubDate>Wed, 07 Oct 2026 01:20:00 +0800</pubDate><guid>http://yafengabc.github.io/goc/devnotes/04-gocl-llvm%E5%90%8E%E7%AB%AF%E8%B8%A9%E8%BF%87%E7%9A%84%E5%9D%91/index.html</guid><description>把 goc 的 C 代码交给 LLVM 编译、再由自研链接器合成 exe，这条路上踩过的坑：libLLVM 的 FFI 约定、LLVM IR 的畸形输出、COFF 重定位丢失 addend 导致控制台全哑、printf 特化的架构缺口、PE 段级文件对齐、TLS 访问被当成 extern 全局、以及 AT&amp;T 前端的操作数方向不能一律翻转。</description></item><item><title>第 3 章：体积实测——goc、LLVM 后端、gcc 三方对照</title><link>http://yafengabc.github.io/goc/03-%E4%BD%93%E7%A7%AF%E5%AE%9E%E6%B5%8B/index.html</link><pubDate>Tue, 06 Oct 2026 12:40:00 +0800</pubDate><guid>http://yafengabc.github.io/goc/03-%E4%BD%93%E7%A7%AF%E5%AE%9E%E6%B5%8B/index.html</guid><description>全部自己跑出来的数字：Hello World 的 print 版 2048 字节、printf 版 6656 字节，gcc 是 38989 字节。附带发现 LLVM 后端反而更小，以及一套验证第二后端正确性的办法。</description></item><item><title>第 4 章：项目状态与 roadmap</title><link>http://yafengabc.github.io/goc/04-%E9%A1%B9%E7%9B%AE%E7%8A%B6%E6%80%81/index.html</link><pubDate>Tue, 06 Oct 2026 12:50:00 +0800</pubDate><guid>http://yafengabc.github.io/goc/04-%E9%A1%B9%E7%9B%AE%E7%8A%B6%E6%80%81/index.html</guid><description>goc 实测状态：Windows 腿全绿，C23 实用子集全部落地，LLVM 后端可用但仍是实验性。本文列出能做什么、不能做什么、正在进行什么，以及一个「26 个失败其实全是环境缺依赖」的例子。</description></item></channel></rss>