diff options
author | chriseth <chris@ethereum.org> | 2018-10-04 20:55:02 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-10-12 21:15:01 +0800 |
commit | 6daeb39ecc7ffd0e834e63f6495442c4211c5c1c (patch) | |
tree | 670349dc15db2f9be5210f4ad2c99a386c079168 /solc | |
parent | 5f5dc8956d39ab19c5408aa4c39a3cd10d3a2dec (diff) | |
download | dexon-solidity-6daeb39ecc7ffd0e834e63f6495442c4211c5c1c.tar.gz dexon-solidity-6daeb39ecc7ffd0e834e63f6495442c4211c5c1c.tar.zst dexon-solidity-6daeb39ecc7ffd0e834e63f6495442c4211c5c1c.zip |
Use hash for library placeholders.
Diffstat (limited to 'solc')
-rw-r--r-- | solc/CommandLineInterface.cpp | 38 | ||||
-rw-r--r-- | solc/CommandLineInterface.h | 4 |
2 files changed, 36 insertions, 6 deletions
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 8fd0d6ef..7ab76c12 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -226,21 +226,21 @@ void CommandLineInterface::handleBinary(string const& _contract) if (m_args.count(g_argBinary)) { if (m_args.count(g_argOutputDir)) - createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin", m_compiler->object(_contract).toHex()); + createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin", objectWithLinkRefsHex(m_compiler->object(_contract))); else { cout << "Binary: " << endl; - cout << m_compiler->object(_contract).toHex() << endl; + cout << objectWithLinkRefsHex(m_compiler->object(_contract)) << endl; } } if (m_args.count(g_argBinaryRuntime)) { if (m_args.count(g_argOutputDir)) - createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin-runtime", m_compiler->runtimeObject(_contract).toHex()); + createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin-runtime", objectWithLinkRefsHex(m_compiler->runtimeObject(_contract))); else { cout << "Binary of the runtime part: " << endl; - cout << m_compiler->runtimeObject(_contract).toHex() << endl; + cout << objectWithLinkRefsHex(m_compiler->runtimeObject(_contract)) << endl; } } } @@ -1056,8 +1056,12 @@ bool CommandLineInterface::link() { 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. + // This leaves 36 characters for the library identifier. The identifier used to + // be just the cropped or '_'-padded library name, but this changed to + // the cropped hex representation of the hash of the library name. + // We support both ways of linking here. + librariesReplacements["__" + eth::LinkerObject::libraryPlaceholder(name) + "__"] = library.second; + string replacement = "__"; for (size_t i = 0; i < placeholderSize - 4; ++i) replacement.push_back(i < name.size() ? name[i] : '_'); @@ -1087,6 +1091,11 @@ bool CommandLineInterface::link() cerr << "Reference \"" << name << "\" in file \"" << src.first << "\" still unresolved." << endl; it += placeholderSize; } + // Remove hints for resolved libraries. + for (auto const& library: m_libraries) + boost::algorithm::erase_all(src.second, "\n" + libraryPlaceholderHint(library.first)); + while (!src.second.empty() && *prev(src.second.end()) == '\n') + src.second.resize(src.second.size() - 1); } return true; } @@ -1100,6 +1109,23 @@ void CommandLineInterface::writeLinkedFiles() writeFile(src.first, src.second); } +string CommandLineInterface::libraryPlaceholderHint(string const& _libraryName) +{ + return "// " + eth::LinkerObject::libraryPlaceholder(_libraryName) + " -> " + _libraryName; +} + +string CommandLineInterface::objectWithLinkRefsHex(eth::LinkerObject const& _obj) +{ + string out = _obj.toHex(); + if (!_obj.linkReferences.empty()) + { + out += "\n"; + for (auto const& linkRef: _obj.linkReferences) + out += "\n" + libraryPlaceholderHint(linkRef.second); + } + return out; +} + bool CommandLineInterface::assemble( AssemblyStack::Language _language, AssemblyStack::Machine _targetMachine diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index 010dce34..aa49383a 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -54,6 +54,10 @@ public: private: bool link(); void writeLinkedFiles(); + /// @returns the ``// <identifier> -> name`` hint for library placeholders. + static std::string libraryPlaceholderHint(std::string const& _libraryName); + /// @returns the full object with library placeholder hints in hex. + static std::string objectWithLinkRefsHex(eth::LinkerObject const& _obj); bool assemble(AssemblyStack::Language _language, AssemblyStack::Machine _targetMachine); |