Skip to content

A library's modules are declared whatever order its symbol table lists them in - #834

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-shared-library-decls-order
Nov 13, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-shared-library-decls-order

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

test-compile-shared-import-chain-rtti-skipped failed every run on Ubuntu 26.04 (WSL) with can't find type by name: Profiler. It passed on Windows and on CI's Ubuntu 22.04.

Cause

A -shared library of several modules carries one __decls_<module> per module, and their declarations name each other's classes: rtti_middle's State holds rtti_bottom's Profiler.

mlirGenImportSharedLib parsed them in the order the library's symbol table lists them, and gave up at the first one that named a class not yet declared. That order isn't something the program controls:

  • A DLL's export table sorts by name, and rtti_bottom < rtti_middle.
  • An ELF symbol table follows the linker's layout. Ubuntu 26.04's binutils 2.46 put __decls_rtti_middle before __decls_rtti_bottom; 22.04's did not.

So the same failure happens on Windows whenever a module sorts by name before a module it depends on.

Fix

The import collects the library's declaration texts first, then parses them in passes. A module whose declarations fail is read again after the others, and the import fails only if a pass declares none of the remaining ones; the last pass's errors explain why. Generic declarations still come first.

Test

import-chain-decl-order (compile, compile -shared, JIT -shared) is rtti_skipped_import.ts with its modules named the other way round: order_a_saves, order_m_state, order_z_profiler. Before this change it failed on Windows with the same "can't find type by name: Profiler" (checked with the previous compiler build).

Verified locally

  • Windows x64 ctest: 7027/7027 passed.
  • Linux (WSL, Ubuntu 26.04) ctest: 7008/7008 passed, including rtti-skipped.

🤖 Generated with Claude Code

…s them in

A -shared library of several modules carries a __decls_<module> for each, and they name each
other's classes (one module's State holds the Profiler another declares). The importer parsed
them in the order the library's symbol table listed them and gave up at the first that named a
class not declared yet: "can't find type by name: Profiler". A DLL lists them by name, an ELF
shared object as the linker laid it out - which is how test-compile-shared-import-chain-rtti-
skipped failed with Ubuntu 26.04's binutils (rtti_middle listed before rtti_bottom) and passed
with 22.04's and on Windows (rtti_bottom < rtti_middle by name).

Now a module's declarations that fail are read again after the others; only a pass that declares
none of them fails the import.

Test: import-chain-decl-order, rtti_skipped_import.ts with the modules named the other way round
(order_a_saves, order_m_state, order_z_profiler), which failed on Windows too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit bedf63a into main Nov 13, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-shared-library-decls-order branch November 13, 2026 00:31
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