mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #997 from chriseth/linkingwithunderscores
Fix linking for libraries with underscores.
This commit is contained in:
commit
71a4074ad0
@ -40,6 +40,7 @@ Bugfixes:
|
|||||||
|
|
||||||
* JSON AST: nodes were added at wrong parent
|
* JSON AST: nodes were added at wrong parent
|
||||||
* Why3 translator: crash fix for exponentiation
|
* Why3 translator: crash fix for exponentiation
|
||||||
|
* Commandline Interface: linking libraries with underscores in their name.
|
||||||
* Type Checker: Fallback function cannot return data anymore.
|
* Type Checker: Fallback function cannot return data anymore.
|
||||||
* Code Generator: Fix crash when sha3() was used on unsupported types.
|
* Code Generator: Fix crash when sha3() was used on unsupported types.
|
||||||
|
|
||||||
|
@ -778,37 +778,43 @@ void CommandLineInterface::actOnInput()
|
|||||||
|
|
||||||
bool CommandLineInterface::link()
|
bool CommandLineInterface::link()
|
||||||
{
|
{
|
||||||
|
// Map from how the libraries will be named inside the bytecode to their addresses.
|
||||||
|
map<string, h160> librariesReplacements;
|
||||||
|
int const placeholderSize = 40; // 20 bytes or 40 hex characters
|
||||||
|
for (auto const& library: m_libraries)
|
||||||
|
{
|
||||||
|
string const& name = library.first;
|
||||||
|
// 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.
|
||||||
|
string replacement = "__";
|
||||||
|
for (size_t i = 0; i < placeholderSize - 4; ++i)
|
||||||
|
replacement.push_back(i < name.size() ? name[i] : '_');
|
||||||
|
replacement += "__";
|
||||||
|
librariesReplacements[replacement] = library.second;
|
||||||
|
}
|
||||||
for (auto& src: m_sourceCodes)
|
for (auto& src: m_sourceCodes)
|
||||||
{
|
{
|
||||||
auto end = src.second.end();
|
auto end = src.second.end();
|
||||||
for (auto it = src.second.begin(); it != end;)
|
for (auto it = src.second.begin(); it != end;)
|
||||||
{
|
{
|
||||||
while (it != end && *it != '_') ++it;
|
while (it != end && *it != '_') ++it;
|
||||||
auto insertStart = it;
|
if (it == end) break;
|
||||||
while (it != end && *it == '_') ++it;
|
if (end - it < placeholderSize)
|
||||||
auto nameStart = it;
|
|
||||||
while (it != end && *it != '_') ++it;
|
|
||||||
auto nameEnd = it;
|
|
||||||
while (it != end && *it == '_') ++it;
|
|
||||||
auto insertEnd = it;
|
|
||||||
|
|
||||||
if (insertStart == end)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (insertEnd - insertStart != 40)
|
|
||||||
{
|
{
|
||||||
cerr << "Error in binary object file " << src.first << " at position " << (insertStart - src.second.begin()) << endl;
|
cerr << "Error in binary object file " << src.first << " at position " << (end - src.second.begin()) << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string name(nameStart, nameEnd);
|
string name(it, it + placeholderSize);
|
||||||
if (m_libraries.count(name))
|
if (librariesReplacements.count(name))
|
||||||
{
|
{
|
||||||
string hexStr(toHex(m_libraries.at(name).asBytes()));
|
string hexStr(toHex(librariesReplacements.at(name).asBytes()));
|
||||||
copy(hexStr.begin(), hexStr.end(), insertStart);
|
copy(hexStr.begin(), hexStr.end(), it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cerr << "Reference \"" << name << "\" in file \"" << src.first << "\" still unresolved." << endl;
|
cerr << "Reference \"" << name << "\" in file \"" << src.first << "\" still unresolved." << endl;
|
||||||
|
it += placeholderSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user