Skip to content

cgen: emit interface type-table index as a real symbol under -usecache (fix undefined _IError_None___index)#27381

Open
medvednikov wants to merge 4 commits into
masterfrom
fix-27330-usecache-iface-index
Open

cgen: emit interface type-table index as a real symbol under -usecache (fix undefined _IError_None___index)#27381
medvednikov wants to merge 4 commits into
masterfrom
fix-27330-usecache-iface-index

Conversation

@medvednikov

Copy link
Copy Markdown
Member

Description

Fixes #27330.

Multiple FreeBSD/clang reports failed at link time with:

undefined symbol: _IError_None___index

Root cause

interface_table() emits the interface type-table index for each concrete variant. With -usecache, modules like builtin are compiled separately in build_module mode, where the index is emitted as a forward reference to a real symbol:

extern const u32 _IError_None___index;

Commit 60ac6ce06 ("cgen: linux tcc fix") changed the main (non-build_module) branch to emit the index as a compile-time enum:

enum { _IError_None___index = 1 };   // no linker symbol!

instead of the previous const u32 _IError_None___index = 1;. An enum constant has no linker symbol, so the cached builtin object's extern const u32 reference had no definition anywhere — undefined symbol at link time. This reproduces with any -usecache build (even fn main(){ println('hello world') }); FreeBSD/clang's stricter linker surfaced it.

Fix

Restore a real, externally-linked const u32 ..._index = N; definition in the main program when -usecache is active, while keeping the tcc-friendly enum form for ordinary single-build compilations (which need no cross-TU symbol). This is exactly the pre-60ac6ce06 behavior for the usecache case, scoped so the tcc fix is preserved everywhere else.

Verification

  • Reproduced on macOS arm64: v -usecache -o - hello.v previously emitted enum { _IError_None___index = 1 };; with the fix it emits const u32 _IError_None___index = 1;, and the undefined symbol: _IError_None___index / _IError_MessageError_index link errors are gone.
  • Non-usecache builds are unchanged (still emit the enum form); hello world and an error-handling program build and run normally; the compiler self-compiles.
  • Added regression test vlib/v/tests/usecache_interface_index_symbol_test.v asserting the -usecache codegen emits the real const u32 symbol (and that plain builds keep the enum).

Note: a separate, pre-existing -usecache issue on -fno-common toolchains (duplicate g_autostr_* tentative-definition globals) is not addressed here — it is independent of the interface-index symbol and out of scope for this issue.

…e (fix undefined `_IError_None___index`)

With -usecache, modules like `builtin` are compiled separately in build_module
mode, where the interface type-table index is emitted as
`extern const u32 _<I>_<T>___index;` and referenced. Commit 60ac6ce changed
the main (non-build_module) branch to emit the index as a compile-time
`enum { ..._index = N };` instead of `const u32 ..._index = N;`. An enum
constant has no linker symbol, so the `extern const u32` reference from the
cached `builtin` object had no definition, failing at link time:

    undefined symbol: _IError_None___index

This reproduces with any -usecache build (e.g. `hello world`); FreeBSD/clang
reported it first.

Restore a real, externally-linked `const u32 ..._index = N;` definition when
`-usecache` is active, while keeping the tcc-friendly `enum` form for ordinary
single-build compilations (which need no cross-TU symbol).

Fixes #27330
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@medvednikov

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9776fa596

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v/gen/c/cgen.v Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be5327d59f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v/gen/c/cgen.v Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd1e6b1a66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v/gen/c/cgen.v Outdated
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.

linker: undefined symbol _IError_None___index on FreeBSD/clang

1 participant