Skip to content

linker: detect duplicate exported definitions without imports#6750

Merged
s-perron merged 1 commit into
KhronosGroup:mainfrom
Lurie97:fix_linker
Jul 22, 2026
Merged

linker: detect duplicate exported definitions without imports#6750
s-perron merged 1 commit into
KhronosGroup:mainfrom
Lurie97:fix_linker

Conversation

@Lurie97

@Lurie97 Lurie97 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

The duplicate-export check in GetImportExportPairs() only triggers when iterating over imports. If no module imports a symbol, the linker never looks up the export table for that name, so multiple modules can each export the same function and spvtools::Link() silently accepts them instead of reporting a One Definition Rule violation.

Add a standalone pass over the exports map before the import-matching loop to reject links where the same symbol name is exported by more than one module. This correctly handles LinkOnceODR symbols because they are already deduplicated into a single export entry by the preceding linkonce processing.

Fixes the piglit clLinkProgram test where two modules each define get_number() with Export linkage but neither imports it.

@Lurie97 Lurie97 closed this Jun 18, 2026
@Lurie97 Lurie97 reopened this Jun 18, 2026
@CLAassistant

CLAassistant commented Jun 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@s-perron s-perron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a test as well.

Comment thread source/link/linker.cpp Outdated
Comment thread source/link/linker.cpp Outdated
@Lurie97
Lurie97 force-pushed the fix_linker branch 2 times, most recently from 9cf29ef to 74eb0a5 Compare June 29, 2026 06:50
@s-perron
s-perron enabled auto-merge (squash) July 10, 2026 14:51
@Lurie97

Lurie97 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Hi @s-perron, Could you help review this MR? Thanks.

@s-perron

Copy link
Copy Markdown
Collaborator

The test FunctionVariants.FAddAsm is failing in the presubmits. You might need to merge in the latest from main.

auto-merge was automatically disabled July 17, 2026 06:31

Head branch was pushed to by a user without write access

@Lurie97

Lurie97 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

The FAddAsm failure was actually caused by this change, not a stale branch: the duplicate-export check
rejected the function-variants case (multiple same-name exports are valid there). Fixed by guarding the
check with a new allow_multiple_exports flag (only set in multitarget mode), and rebased onto latest
main.

Verified locally: full test_link suite passes (92/92), including FAddAsm and the new
MultipleDefinitionsNoImport test. PTAL, thanks!

@s-perron
s-perron enabled auto-merge (squash) July 17, 2026 15:29
auto-merge was automatically disabled July 20, 2026 03:17

Head branch was pushed to by a user without write access

@Lurie97

Lurie97 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@s-perron I've force-pushed to fix the check-format failure — it's a pure clang-format reformatting of the
GetImportExportPairs() call, no logic changes. Since I don't have write access, auto-merge got disabled and the
workflows need your approval to run. Could you approve the workflows and re-enable auto-merge (or merge) when
green? Thanks!

@s-perron
s-perron enabled auto-merge (squash) July 20, 2026 10:32
The duplicate-export check in GetImportExportPairs() only triggered while
iterating over imports, so when no module imported a symbol the linker
never inspected the export table for that name and silently accepted
multiple modules exporting the same symbol instead of reporting a One
Definition Rule violation.

Check the export table directly before the import-matching loop so
duplicates are always rejected. LinkOnceODR symbols are already
deduplicated into a single entry beforehand, and the function-variants
(multitarget) flow legitimately keeps one export per variant, so the
check is skipped in that mode via a new allow_multiple_exports flag.

Add a test where two modules export the same symbol but neither imports it.

Signed-off-by: jiajia Qian <jiajia.qian@nxp.com>
@Lurie97

Lurie97 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi @s-perron, the 2 pending workflows still need your approval to run — after the force-push, GitHub requires maintainer
approval again for the build checks (they're stuck on "Waiting for status"). Could you click "Approve and
run" on the workflows and re-enable auto-merge? Everything else is green. Thanks!

@s-perron
s-perron merged commit 3c96171 into KhronosGroup:main Jul 22, 2026
26 checks passed
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.

4 participants