fix(TPC/includes): 泛型特化 linkonce_odr + None 全局 common + includes 前缀

- TPC HandlesFunctions/HandlesClassDef: 泛型特化类方法(类名含 '[')设
  linkonce_odr,消除 GSList[NameEntry].__before_init__ 等 duplicate symbol
- TPC HandlesAssign: None 初值模块级全局用 common linkage,合并 _g_gen 等
  跨模块同名全局重复定义
- includes: binascii/hashlib 裸调用加 stdlib./string. 前缀(malloc/free/memset/memcpy)
- llvmlite: FunctionPrint 泛型特化方法输出 define linkonce_odr;__module 调整
- 删除 wiki/01-overview.md
This commit is contained in:
TermiNexus committed 2026-08-12 18:18:22 +08:00
1 parent b4567ffb9a
commit 8ccf5d2c18
10 files changed
+70 -384

No files matched your search

+5 -1
View File
@@ -1520,7 +1520,11 @@ class AssignHandle(BaseHandle):
init_val: ir.Constant | None = self._eval_global_const(Node.value, VarType, Gen)
if init_val:
GlobalVar.initializer = init_val
elif isinstance(VarType, ir.BaseStructType):
elif isinstance(VarType, ir.BaseStructType) or (isinstance(Node.value, ast.Constant) and Node.value.value is None):
# None 初值全局(如各 Handles 模块的 _g_gen: t.CVoid|t.CPtr = None):
# 多模块同名定义用 common linkage 让链接器合并(避免
# ld.lld duplicate symbol)。common 无 initializer,合并为零值,
# 符合 None(=null) 语义。
GlobalVar.linkage = 'common'
else:
GlobalVar.initializer = Gen._zero_value_for_type(VarType)
+6
View File
@@ -1379,6 +1379,12 @@ class ClassHandle(BaseHandle):
func: ir.Function = existing_func
else:
func = Gen._get_or_declare_function(MangledName, FuncType)
# 泛型特化类(ClassName 含 '[',如 GSList[NameEntry])的 __before_init__
# 在多模块各自特化生成同名定义(external linkage)→ ld.lld duplicate
# symbol warning。__before_init__ 由相同模板+类型参数合成,定义相同,
# 设 linkonce_odr 让链接器合并重复定义。
if '[' in ClassName:
func.linkage = 'linkonce_odr'
Gen.functions[NewFuncName] = func
EntryBlock: ir.Block = func.append_basic_block(name="entry")
saved_builder: ir.IRBuilder = Gen.builder
+7
View File
@@ -1551,9 +1551,16 @@ class FunctionHandle(BaseHandle):
if MangledName == FuncName or FuncName not in Gen._export_extern_funcs:
Gen.functions[FuncName] = func
func.attributes.add('noredzone')
# 泛型特化类方法(如 GSList[NameEntry].__before_init__):多个模块各自
# 特化会生成同名定义(external linkage)→ ld.lld duplicate symbol warning。
# 特化方法代码由相同模板+类型参数生成,定义相同,设 linkonce_odr 让
# 链接器合并重复定义(linkonce_odr 的 alwaysinline 不适用,仅改 linkage)。
is_spec_generic_method: bool = '[' in FuncName
if IsInlineFunc:
func.linkage = 'linkonce_odr'
func.attributes.add('alwaysinline')
if is_spec_generic_method:
func.linkage = 'linkonce_odr'
if hasattr(self, '_cdefine_funcs') and FuncName in self._cdefine_funcs:
func.linkage = 'linkonce_odr'
func.attributes.add('alwaysinline')