Skip to content

Commit 0cf9e18

Browse files
committed
refactor(example): 板子的内存布局不再由这个例子陈述
它此前带着一份链接脚本 —— OpenSBI 把控制权交到哪里、多少栈、堆在哪 —— 挂在一个 关于目标的条件后面。那个条件是诚实的部分:它们是关于**一台机器**的陈述,不是关于 这个程序的。 ⭐ 而这恰恰说明它们也不属于这里。openkal-opensbi 是知道那台机器的包,它现在用自己的 构建程序供给这份地图,到达每个使用者的链接线 —— 与它供给 kal_* 定义的方式相同。 于是这个目录所主张的「同一份源码、不同的机器、什么都不用改」对构建文件也成立。 ⚠️ 两份并存时实测(板级事实**可传递**地到达使用者,而这个例子是使用者): ld.lld: error: section .eh_frame file range overlaps with .debug_str_offsets ld.lld: error: section .debug_str file range overlaps with .eh_frame_hdr 两份脚本都被应用了,而诊断一个字都没提「有两份」。 复验四个目标全部产出;裸机(qemu+OpenSBI)、Linux、Windows(wine)三个跑通, 输出逐字相同。
1 parent 9110462 commit 0cf9e18

2 files changed

Lines changed: 28 additions & 140 deletions

File tree

examples/same-source/build.mcpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import mcpp;
2-
#include <cstring>
32

4-
int main() {
5-
// ⭐⭐ THE LINKER SCRIPT IS FOR THE MACHINE WITH NO OPERATING SYSTEM, AND
6-
// ONLY FOR IT. THAT CONDITION IS WHAT MAKES THIS ONE PROJECT INSTEAD OF TWO.
7-
//
8-
// The claim the design document makes is that a program above openkal is
9-
// built without regard to which implementation is beneath — same source,
10-
// different machine, nothing edited. A directory that could only be built
11-
// one way would illustrate that claim rather than demonstrate it.
12-
//
13-
// So: `mcpp run` puts this on the host over openkal-linux, and
14-
// `mcpp run --target riscv64-none-elf` puts the SAME source on riscv64 over
15-
// OpenSBI. Both print the same four lines. The only thing that differs is
16-
// the memory layout, which is a statement about the machine — and it is
17-
// stated here, once, behind the condition that says which machine.
18-
if (std::strcmp(mcpp::target_os(), "none") == 0) {
19-
// A relative path in `ldflags` would resolve against the build
20-
// directory; `link-script` resolves against the package root.
21-
mcpp::link_script("link.ld");
22-
}
23-
mcpp::rerun_if_changed("link.ld");
24-
mcpp::rerun_if_env_changed("MCPP_TARGET_OS");
25-
return 0;
26-
}
3+
// ⚠️ THIS FILE STATES NOTHING, AND ITS EMPTINESS IS WHAT THE EXAMPLE IS ABOUT.
4+
//
5+
// Until 2026-08-23 it carried a linker script for the machine with no operating
6+
// system — where OpenSBI hands control over, how much stack, where the heap is
7+
// — behind a condition on the target. The condition was the honest part: those
8+
// are statements about a MACHINE and not about this program.
9+
//
10+
// ⭐ Which is exactly why they do not belong here either. `openkal-opensbi` is
11+
// the package that knows that machine, and it supplies the map the same way it
12+
// supplies its `kal_*` definitions: through its own build program, reaching
13+
// every consumer's link line. A program adds nothing and gets a layout that
14+
// works, and the claim this directory makes — same source, different machine,
15+
// nothing edited — becomes true of the build files as well as of the source.
16+
//
17+
// ⚠️ Measured while both copies existed, because a board fact reaches its
18+
// consumers TRANSITIVELY and this example is a consumer:
19+
//
20+
// ld.lld: error: section .eh_frame file range overlaps with
21+
// .debug_str_offsets
22+
// ld.lld: error: section .debug_str file range overlaps with .eh_frame_hdr
23+
//
24+
// Two scripts, both applied, and a diagnostic that says nothing about there
25+
// being two. ⇒ A program that also states a board fact states it twice.
26+
//
27+
// The file remains rather than being deleted: a build program is how this
28+
// example would say anything at all, and its absence would read as "this was
29+
// never considered" rather than "there is nothing to say".
30+
int main() { return 0; }

examples/same-source/link.ld

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)