aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-09-06 18:52:31 +0800
committerGitHub <noreply@github.com>2016-09-06 18:52:31 +0800
commit71a4074ad03845e9651fe80fd16337958f847dc9 (patch)
tree75cd1677a2b94208c59d1c1fd6632459bcbb52e3
parentf687635e4743a1e12d01fb082a4f8a76a759ab48 (diff)
parent8c315a18c9ed7ad8b1fdec53d21e425137e89079 (diff)
downloaddexon-solidity-71a4074ad03845e9651fe80fd16337958f847dc9.tar.gz
dexon-solidity-71a4074ad03845e9651fe80fd16337958f847dc9.tar.zst
dexon-solidity-71a4074ad03845e9651fe80fd16337958f847dc9.zip
Merge pull request #997 from chriseth/linkingwithunderscores
Fix linking for libraries with underscores.
-rw-r--r--Changelog.md1
-rw-r--r--solc/CommandLineInterface.cpp40
2 files changed, 24 insertions, 17 deletions
diff --git a/Changelog.md b/Changelog.md
index 27f88cd2..216b5cf4 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -40,6 +40,7 @@ Bugfixes:
* JSON AST: nodes were added at wrong parent
* Why3 translator: crash fix for exponentiation
+ * Commandline Interface: linking libraries with underscores in their name.
* Type Checker: Fallback function cannot return data anymore.
* Code Generator: Fix crash when sha3() was used on unsupported types.
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index fbef56f0..f0a34632 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -778,37 +778,43 @@ void CommandLineInterface::actOnInput()
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)
{
auto end = src.second.end();
for (auto it = src.second.begin(); it != end;)
{
while (it != end && *it != '_') ++it;
- auto insertStart = it;
- while (it != end && *it == '_') ++it;
- 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)
+ if (it == end) break;
+ if (end - it < placeholderSize)
{
- 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;
}
- string name(nameStart, nameEnd);
- if (m_libraries.count(name))
+ string name(it, it + placeholderSize);
+ if (librariesReplacements.count(name))
{
- string hexStr(toHex(m_libraries.at(name).asBytes()));
- copy(hexStr.begin(), hexStr.end(), insertStart);
+ string hexStr(toHex(librariesReplacements.at(name).asBytes()));
+ copy(hexStr.begin(), hexStr.end(), it);
}
else
cerr << "Reference \"" << name << "\" in file \"" << src.first << "\" still unresolved." << endl;
+ it += placeholderSize;
}
}
return true;