Skip to content

Add @dllname decorator for custom exported symbol names - #320

Merged
ASDAlexander77 merged 1 commit into
mainfrom
dllname-attribute
Sep 13, 2026
Merged

Add @dllname decorator for custom exported symbol names#320
ASDAlexander77 merged 1 commit into
mainfrom
dllname-attribute

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

  • New @dllname("custom_name") decorator sets the symbol an exported function, method, accessor or variable gets in a shared library / DLL. For example @dllname("custom_add") export function add(...) is exported as custom_add instead of M.add.
  • Functions, methods and get/set accessors: the decorator becomes a dllname attribute that LowerToLLVM forwards as an LLVM function attribute, and ExportFixPass renames the function (all uses follow the rename).
  • Variables: LLVM globals carry no string attributes, so TypeScriptToLLVMLoweringPass renames the global symbol and all its uses before lowering. A dynamic-import copy in an importer is not renamed.
  • Importers: DeclarationPrinter emits @dllname(...) into __decls for functions, variables, methods and accessors, and every runtime symbol lookup (dynamic import of functions/variables, static/constructor methods, vtable slots, accessors, indexers) resolves the custom name.

Test plan

  • New test-compile-shared-export-import-dllname: renamed function, intra-library call, renamed variable changed through a library function, renamed static/instance methods, renamed getter/setter
  • All 268 shared-library ctest tests pass (gc/rc/none, compile and JIT)
  • DeclarationPrinterTest.* 59/59 pass, including 5 new dllname cases
  • llvm-objdump -p on the built DLL shows custom_add, custom_counter, calc_twice, calc_scale, calc_get_double, calc_set_double and no M.add/M.counter/M.Calc.* entries for them

🤖 Generated with Claude Code

- Introduced DLL_NAME attribute for functions, methods, variables, and accessors.
- Updated relevant classes and methods to handle DLL_NAME during export and import.
- Added tests to ensure correct handling of @dllname in declarations.
@ASDAlexander77
ASDAlexander77 merged commit 29b3311 into main Sep 13, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the dllname-attribute branch September 13, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant