From 4477af6058cf81eccb71b7ce47e96e8e82e47763 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 18 Nov 2025 00:18:55 +0800 Subject: [PATCH] fix broken font rendering in rust 1.91 Rust 1.91 (or perhaps, more accurately llvm?) changed how link ordering works. Previously, modules would be linked in the order they were referenced (e.g. pub mod b; pub mod a; would result in b being at a lower address than a in the resulting binary). However, apparently, this has changed and now someone in their infinite wisdom decided that modules should be alphabetized before linking. I'm really not sure why the arbitrary ordering of the human alphabet is superior to any other system, and also, if you really wanted things alphabetized, you could just alphabetize them in your reference order. Previously the fonts were laid out in a way that tried to minimize cache thrashing by co-locating certain sets of fonts together. Now they are just sprayed around through the arbitrary and not terribly useful permutation funtion of the english alphabet. Rant off. This changes the specification of the fonts in the code generator to be in alphabetical order, making the screen once again legible. --- libs/blitstr2/codegen/config.json | 88 +++++++++++++------------- libs/blitstr2/codegen/config_editor.rb | 60 +++++++++--------- libs/blitstr2/codegen/lib/templates.go | 6 ++ libs/blitstr2/src/fontmap.rs | 50 ++++++++------- loader/src/fonts.rs | 14 ++-- 5 files changed, 115 insertions(+), 103 deletions(-) diff --git a/libs/blitstr2/codegen/config.json b/libs/blitstr2/codegen/config.json index d15a63bd8..bd5c1ccdf 100644 --- a/libs/blitstr2/codegen/config.json +++ b/libs/blitstr2/codegen/config.json @@ -1,6 +1,6 @@ { "comment": [ - "Config for use with main.go. Before making changes here, see config_editor.rb." + "Config for use with main.go. Before making changes here, see config_editor.rb. NOTE: the glyph set list MUST be alphabetized since Rust 1.91" ], "loadermod": [ "../../../loader/src/fonts.rs" @@ -9,6 +9,21 @@ "../src/fontmap.rs" ], "glyphSets": [ + { + "name": "Bold", + "sprites": "src_data/latin_bold.png", + "size": 15, + "cols": 16, + "gutter": 1, + "border": 1, + "legal": "src_data/chicago_legal.txt", + "index": "src_data/latin_index.json", + "indexType": "json-grid-coord", + "glyphTrim": "proportional", + "rustout": "../src/fonts/bold.rs", + "loaderout": "../../../loader/src/fonts/bold.rs", + "small": true + }, { "name": "Emoji", "sprites": "src_data/basic_emoji.png", @@ -24,21 +39,6 @@ "loaderout": "../../../loader/src/fonts/emoji.rs", "small": true }, - { - "name": "zh", - "sprites": "src_data/hanzi.png", - "size": 16, - "cols": 30, - "gutter": 2, - "border": 2, - "legal": "src_data/hanzi_legal.txt", - "index": "src_data/hanzi.codepoints", - "indexType": "txt-row-major", - "glyphTrim": "CJK", - "rustout": "../src/fonts/zh.rs", - "loaderout": "../../../loader/src/fonts/zh.rs", - "small": false - }, { "name": "ja", "sprites": "src_data/Izumi16.png", @@ -69,21 +69,6 @@ "loaderout": "../../../loader/src/fonts/kr.rs", "small": false }, - { - "name": "Bold", - "sprites": "src_data/latin_bold.png", - "size": 15, - "cols": 16, - "gutter": 1, - "border": 1, - "legal": "src_data/chicago_legal.txt", - "index": "src_data/latin_index.json", - "indexType": "json-grid-coord", - "glyphTrim": "proportional", - "rustout": "../src/fonts/bold.rs", - "loaderout": "../../../loader/src/fonts/bold.rs", - "small": true - }, { "name": "Mono", "sprites": "src_data/latin_mono.png", @@ -114,6 +99,21 @@ "loaderout": "../../../loader/src/fonts/regular.rs", "small": true }, + { + "name": "Small", + "sprites": "src_data/latin_small.png", + "size": 12, + "cols": 16, + "gutter": 1, + "border": 1, + "legal": "src_data/geneva_legal.txt", + "index": "src_data/latin_index.json", + "indexType": "json-grid-coord", + "glyphTrim": "proportional", + "rustout": "../src/fonts/small.rs", + "loaderout": "../../../loader/src/fonts/small.rs", + "small": true + }, { "name": "Tall", "sprites": "src_data/latin_tall.png", @@ -130,19 +130,19 @@ "small": true }, { - "name": "Small", - "sprites": "src_data/latin_small.png", - "size": 12, - "cols": 16, - "gutter": 1, - "border": 1, - "legal": "src_data/geneva_legal.txt", - "index": "src_data/latin_index.json", - "indexType": "json-grid-coord", - "glyphTrim": "proportional", - "rustout": "../src/fonts/small.rs", - "loaderout": "../../../loader/src/fonts/small.rs", - "small": true + "name": "zh", + "sprites": "src_data/hanzi.png", + "size": 16, + "cols": 30, + "gutter": 2, + "border": 2, + "legal": "src_data/hanzi_legal.txt", + "index": "src_data/hanzi.codepoints", + "indexType": "txt-row-major", + "glyphTrim": "CJK", + "rustout": "../src/fonts/zh.rs", + "loaderout": "../../../loader/src/fonts/zh.rs", + "small": false } ] } \ No newline at end of file diff --git a/libs/blitstr2/codegen/config_editor.rb b/libs/blitstr2/codegen/config_editor.rb index 1eaa14e7b..046744c68 100755 --- a/libs/blitstr2/codegen/config_editor.rb +++ b/libs/blitstr2/codegen/config_editor.rb @@ -20,7 +20,7 @@ latin_index_outfile = "src_data/latin_index.json" config = { comment: [ - "Config for use with main.go. Before making changes here, see config_editor.rb.", + "Config for use with main.go. Before making changes here, see config_editor.rb. NOTE: the glyph set list MUST be alphabetized since Rust 1.91", ], loadermod: [ "../../../../../loader/src/fonts.rs", @@ -29,6 +29,16 @@ config = { "../../fontmap.rs", ], glyphSets: [ + { + name: "Bold", + sprites: "src_data/latin_bold.png", size: 15, cols: 16, gutter: 1, border: 1, + legal: "src_data/chicago_legal.txt", + index: latin_index_outfile, + indexType: "json-grid-coord", + glyphTrim: "proportional", + rustout: "../fonts/bold.rs", + loaderout: "../../../../../loader/src/fonts/bold.rs", + }, { name: "Emoji", sprites: "src_data/basic_emoji.png", size: 16, cols: 30, gutter: 2, border: 2, @@ -39,16 +49,6 @@ config = { rustout: "../fonts/emoji.rs", loaderout: "../../../../../loader/src/fonts/emoji.rs", }, - { - name: "zh", - sprites: "src_data/hanzi.png", size: 16, cols: 30, gutter: 2, border: 2, - legal: "src_data/hanzi_legal.txt", - index: "src_data/hanzi.codepoints", - indexType: "txt-row-major", - glyphTrim: "CJK", - rustout: "../fonts/zh.rs", - loaderout: "../../../../../loader/src/fonts/zh.rs", - }, { name: "ja", sprites: "src_data/Izumi16.png", size: 16, cols: 30, gutter: 2, border: 2, @@ -69,16 +69,6 @@ config = { rustout: "../fonts/kr.rs", loaderout: "../../../../../loader/src/fonts/kr.rs", }, - { - name: "Bold", - sprites: "src_data/latin_bold.png", size: 15, cols: 16, gutter: 1, border: 1, - legal: "src_data/chicago_legal.txt", - index: latin_index_outfile, - indexType: "json-grid-coord", - glyphTrim: "proportional", - rustout: "../fonts/bold.rs", - loaderout: "../../../../../loader/src/fonts/bold.rs", - }, { name: "Mono", sprites: "src_data/latin_mono.png", size: 15, cols: 16, gutter: 1, border: 1, @@ -99,6 +89,16 @@ config = { rustout: "../fonts/regular.rs", loaderout: "../../../../../loader/src/fonts/regular.rs", }, + { + name: "Small", + sprites: "src_data/latin_small.png", size: 12, cols: 16, gutter: 1, border: 1, + legal: "src_data/geneva_legal.txt", + index: latin_index_outfile, + indexType: "json-grid-coord", + glyphTrim: "proportional", + rustout: "../fonts/small.rs", + loaderout: "../../../../../loader/src/fonts/small.rs", + }, { name: "Tall", sprites: "src_data/latin_tall.png", size: 19, cols: 30, gutter: 1, border: 1, @@ -110,15 +110,15 @@ config = { loaderout: "../../../../../loader/src/fonts/tall.rs", }, { - name: "Small", - sprites: "src_data/latin_small.png", size: 12, cols: 16, gutter: 1, border: 1, - legal: "src_data/geneva_legal.txt", - index: latin_index_outfile, - indexType: "json-grid-coord", - glyphTrim: "proportional", - rustout: "../fonts/small.rs", - loaderout: "../../../../../loader/src/fonts/small.rs", - } + name: "zh", + sprites: "src_data/hanzi.png", size: 16, cols: 30, gutter: 2, border: 2, + legal: "src_data/hanzi_legal.txt", + index: "src_data/hanzi.codepoints", + indexType: "txt-row-major", + glyphTrim: "CJK", + rustout: "../fonts/zh.rs", + loaderout: "../../../../../loader/src/fonts/zh.rs", + }, ] } diff --git a/libs/blitstr2/codegen/lib/templates.go b/libs/blitstr2/codegen/lib/templates.go index c06e67fc0..2846aebb3 100644 --- a/libs/blitstr2/codegen/lib/templates.go +++ b/libs/blitstr2/codegen/lib/templates.go @@ -171,6 +171,10 @@ const loadermodTemplate = `#![cfg_attr(rustfmt, rustfmt_skip)] // DO NOT MAKE EDITS HERE because this file is automatically generated. // The order of these modules affects the link order in the loader, which is referred to in the graphics engine. // To make changes, see /libs/blitstr2/codegen/main.go + +// NOTE: this list must be in alphabetical order since Rust 1.91.0. If it is not alphabetized, +// the linker will re-order them into allphabetical order, messing up the offsets. + {{range $f := .FontDir}} #[cfg(not(feature = "bao1x"))] pub mod {{$f.Name}};{{end}} @@ -184,6 +188,8 @@ const fontmapTemplate = `#![cfg_attr(rustfmt, rustfmt_skip)] #[cfg(not(feature = "bao1x"))] pub const FONT_BASE: usize = 0x2053_0000; +// NOTE: this list must be in alphabetical order since Rust 1.91.0. If it is not alphabetized, +// the linker will re-order them into allphabetical order, messing up the offsets. {{range $f := .FontDir}}#[cfg(not(feature = "bao1x"))] pub const {{$f.Name}}: usize = 0x{{$f.Len}}; {{end}} diff --git a/libs/blitstr2/src/fontmap.rs b/libs/blitstr2/src/fontmap.rs index 98df8c1c5..e9f31b977 100644 --- a/libs/blitstr2/src/fontmap.rs +++ b/libs/blitstr2/src/fontmap.rs @@ -6,42 +6,44 @@ #[cfg(not(feature = "bao1x"))] pub const FONT_BASE: usize = 0x2053_0000; +// NOTE: this list must be in alphabetical order since Rust 1.91.0. If it is not alphabetized, +// the linker will re-order them into allphabetical order, messing up the offsets. #[cfg(not(feature = "bao1x"))] -pub const EMOJI_OFFSET: usize = 0x0; -#[cfg(not(feature = "bao1x"))] -pub const EMOJI_LEN: usize = 0xab00; -#[cfg(not(feature = "bao1x"))] -pub const ZH_OFFSET: usize = 0xab00; -#[cfg(not(feature = "bao1x"))] -pub const ZH_LEN: usize = 0x3fea0; -#[cfg(not(feature = "bao1x"))] -pub const JA_OFFSET: usize = 0x4a9a0; -#[cfg(not(feature = "bao1x"))] -pub const JA_LEN: usize = 0x56920; -#[cfg(not(feature = "bao1x"))] -pub const KR_OFFSET: usize = 0xa12c0; -#[cfg(not(feature = "bao1x"))] -pub const KR_LEN: usize = 0x61600; -#[cfg(not(feature = "bao1x"))] -pub const BOLD_OFFSET: usize = 0x1028c0; +pub const BOLD_OFFSET: usize = 0x0; #[cfg(not(feature = "bao1x"))] pub const BOLD_LEN: usize = 0x19e0; #[cfg(not(feature = "bao1x"))] -pub const MONO_OFFSET: usize = 0x1042a0; +pub const EMOJI_OFFSET: usize = 0x19e0; +#[cfg(not(feature = "bao1x"))] +pub const EMOJI_LEN: usize = 0xab00; +#[cfg(not(feature = "bao1x"))] +pub const JA_OFFSET: usize = 0xc4e0; +#[cfg(not(feature = "bao1x"))] +pub const JA_LEN: usize = 0x56920; +#[cfg(not(feature = "bao1x"))] +pub const KR_OFFSET: usize = 0x62e00; +#[cfg(not(feature = "bao1x"))] +pub const KR_LEN: usize = 0x61600; +#[cfg(not(feature = "bao1x"))] +pub const MONO_OFFSET: usize = 0xc4400; #[cfg(not(feature = "bao1x"))] pub const MONO_LEN: usize = 0x19e0; #[cfg(not(feature = "bao1x"))] -pub const REGULAR_OFFSET: usize = 0x105c80; +pub const REGULAR_OFFSET: usize = 0xc5de0; #[cfg(not(feature = "bao1x"))] pub const REGULAR_LEN: usize = 0x19e0; #[cfg(not(feature = "bao1x"))] -pub const TALL_OFFSET: usize = 0x107660; -#[cfg(not(feature = "bao1x"))] -pub const TALL_LEN: usize = 0x6780; -#[cfg(not(feature = "bao1x"))] -pub const SMALL_OFFSET: usize = 0x10dde0; +pub const SMALL_OFFSET: usize = 0xc77c0; #[cfg(not(feature = "bao1x"))] pub const SMALL_LEN: usize = 0x19e0; #[cfg(not(feature = "bao1x"))] +pub const TALL_OFFSET: usize = 0xc91a0; +#[cfg(not(feature = "bao1x"))] +pub const TALL_LEN: usize = 0x6780; +#[cfg(not(feature = "bao1x"))] +pub const ZH_OFFSET: usize = 0xcf920; +#[cfg(not(feature = "bao1x"))] +pub const ZH_LEN: usize = 0x3fea0; +#[cfg(not(feature = "bao1x"))] pub const FONT_TOTAL_LEN: usize = 0x10f7c0; diff --git a/loader/src/fonts.rs b/loader/src/fonts.rs index e808820c9..d2185bae2 100644 --- a/loader/src/fonts.rs +++ b/loader/src/fonts.rs @@ -3,21 +3,25 @@ // The order of these modules affects the link order in the loader, which is referred to in the graphics engine. // To make changes, see /libs/blitstr2/codegen/main.go +// NOTE: this list must be in alphabetical order since Rust 1.91.0. If it is not alphabetized, +// the linker will re-order them into allphabetical order, messing up the offsets. + + +#[cfg(not(feature = "bao1x"))] +pub mod bold; #[cfg(not(feature = "bao1x"))] pub mod emoji; #[cfg(not(feature = "bao1x"))] -pub mod zh; -#[cfg(not(feature = "bao1x"))] pub mod ja; #[cfg(not(feature = "bao1x"))] pub mod kr; #[cfg(not(feature = "bao1x"))] -pub mod bold; -#[cfg(not(feature = "bao1x"))] pub mod mono; #[cfg(not(feature = "bao1x"))] pub mod regular; #[cfg(not(feature = "bao1x"))] +pub mod small; +#[cfg(not(feature = "bao1x"))] pub mod tall; #[cfg(not(feature = "bao1x"))] -pub mod small; +pub mod zh;