feat(sccf): 添加SCCF节类型查找功能并修复重复节添加问题

新增了sccf_sect_by_type函数用于按类型查找SCCF节,避免重复添加相同类型的节。

同时新增了sccfdump工具用于解析和显示SCCF文件内容,包括头部信息、节表、
符号表、重定位表以及十六进制内容转储功能,并支持中英文双语界面。

fix(builder): 注释掉未使用的缓冲区创建代码

由于emit stage为SCCF时不需要将构建器转换为缓冲区,注释掉相关代码以避免
不必要的内存分配和数据复制操作。
This commit is contained in:
zzy
2026-05-25 10:40:18 +08:00
parent 28f65f8775
commit c4467b8420
3 changed files with 358 additions and 6 deletions

View File

@@ -64,6 +64,16 @@ void sccf_builder_add_section(sccf_builder_t *builder,
scc_vec_push(builder->sccf.sect_datas, *sect_data);
}
static inline usize sccf_sect_by_type(const sccf_t *sccf, sccf_enum_t type) {
const sccf_header_t *hdr = &sccf->header;
for (usize i = 0; i < (usize)hdr->sect_header_num; ++i) {
sccf_sect_header_t *sh = &scc_vec_at(sccf->sect_headers, i);
if (sh->sccf_sect_type == type)
return i;
}
return (usize)hdr->sect_header_num;
}
const sccf_t *sccf_builder_to_sccf(sccf_builder_t *builder) {
if (builder->entry_symbol_name == nullptr) {
builder->sccf.header.entry_point = 0;
@@ -81,7 +91,9 @@ const sccf_t *sccf_builder_to_sccf(sccf_builder_t *builder) {
}
sccf_sect_header_t sect_header;
if (scc_vec_size(builder->strtab)) {
if (scc_vec_size(builder->strtab) &&
sccf_sect_by_type(&builder->sccf, SCCF_SECT_STRTAB) ==
builder->sccf.header.sect_header_num) {
sect_header = (sccf_sect_header_t){
.name = ".strtab",
.info = 0,
@@ -94,7 +106,9 @@ const sccf_t *sccf_builder_to_sccf(sccf_builder_t *builder) {
(void *)&builder->strtab);
}
if (scc_vec_size(builder->symtab)) {
if (scc_vec_size(builder->symtab) &&
sccf_sect_by_type(&builder->sccf, SCCF_SECT_SYMTAB) ==
builder->sccf.header.sect_header_num) {
sect_header = (sccf_sect_header_t){
.name = ".symtab",
.info = 0,
@@ -107,7 +121,9 @@ const sccf_t *sccf_builder_to_sccf(sccf_builder_t *builder) {
(void *)&builder->symtab);
}
if (scc_vec_size(builder->relocs)) {
if (scc_vec_size(builder->relocs) &&
sccf_sect_by_type(&builder->sccf, SCCF_SECT_RELOCS) ==
builder->sccf.header.sect_header_num) {
sect_header = (sccf_sect_header_t){
.name = ".relocs",
.info = 0,