Skip to content

Truncate linkerObject at the beginning, not end #3918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion libevmasm/LinkerObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ string LinkerObject::toHex() const
{
size_t pos = ref.first * 2;
string const& name = ref.second;
// truncate the beginning of fully qualified library path, so
// we keep the library name
size_t from = name.size() > 36 ? name.size() - 36 : 0;
hex[pos] = hex[pos + 1] = hex[pos + 38] = hex[pos + 39] = '_';
for (size_t i = 0; i < 36; ++i)
hex[pos + 2 + i] = i < name.size() ? name[i] : '_';
hex[pos + 2 + i] = i < name.size() ? name[i + from] : '_';
}
return hex;
}
Expand Down
5 changes: 4 additions & 1 deletion solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,9 +1057,12 @@ bool CommandLineInterface::link()
// Library placeholders are 40 hex digits (20 bytes) that start and end with '__'.
// This leaves 36 characters for the library name, while too short library names are
// padded on the right with '_' and too long names are truncated.
// Truncate the beginning of fully qualified library path, so
// we keep the library name
string replacement = "__";
size_t from = name.size() > 36 ? name.size() - 36 : 0;
for (size_t i = 0; i < placeholderSize - 4; ++i)
replacement.push_back(i < name.size() ? name[i] : '_');
replacement.push_back(i < name.size() ? name[i + from] : '_');
replacement += "__";
librariesReplacements[replacement] = library.second;
}
Expand Down