Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions source/link/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,18 @@ spv_result_t GetImportExportPairs(const MessageConsumer& consumer,
<< possible_export.second.name << "\".";
}

// Detect duplicate exported definitions (One Definition Rule violation).

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.

Can you point to the "One definition rule"? When talking about linking, the ODR rule is a C++ rule that says a function can have multiple declarations, but they must all be the same. When the linker sees two definitions, it is allowed to pick one at random, and it will not change the semantics of the program.

Also, a C++-like ODR feature in part of SPIR-V.

You might want to change the comment to say that you cannot have multiple strong definitions.

// The existing check inside the import-matching loop below only catches
// duplicates when there is a corresponding import. This standalone check
// catches the case where multiple modules export the same symbol but no
// module imports it.
for (const auto& exp : exports) {
if (exp.second.size() > 1u)
return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "Too many external references, " << exp.second.size()
<< ", were found for \"" << exp.first << "\".";
}

// Find the import/export pairs
for (const auto& import : imports) {
std::vector<LinkageSymbolInfo> possible_exports;
Expand Down