Skip to content

linker: detect duplicate exported definitions without imports#6750

Open
Lurie97 wants to merge 1 commit into
KhronosGroup:mainfrom
Lurie97:fix_linker
Open

linker: detect duplicate exported definitions without imports#6750
Lurie97 wants to merge 1 commit into
KhronosGroup:mainfrom
Lurie97:fix_linker

Conversation

@Lurie97

@Lurie97 Lurie97 commented Jun 18, 2026

Copy link
Copy Markdown

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
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 an error.

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.

The existing size > 1 check in the import-matching loop is now
redundant and has been removed.

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

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

Signed-off-by: jiajia Qian <jiajia.qian@nxp.com>
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.

3 participants