Merge pull request #7775 from ethereum/linkreferences

Clarify some notes in LinkerObject and assert that linkReferences are always correct
This commit is contained in:
chriseth 2019-11-25 16:24:53 +01:00 committed by GitHub
commit c4622774bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -519,8 +519,11 @@ map<u256, u256> Assembly::optimiseInternal(
LinkerObject const& Assembly::assemble() const
{
// Return the already assembled object, if present.
if (!m_assembledObject.bytecode.empty())
return m_assembledObject;
// Otherwise ensure the object is actually clear.
assertThrow(m_assembledObject.linkReferences.empty(), AssemblyException, "Unexpected link references.");
size_t subTagSize = 1;
for (auto const& sub: m_subs)

View File

@ -35,7 +35,9 @@ namespace eth
*/
struct LinkerObject
{
/// The bytecode.
bytes bytecode;
/// Map from offsets in bytecode to library identifiers. The addresses starting at those offsets
/// need to be replaced by the actual addresses by the linker.
std::map<size_t, std::string> linkReferences;
@ -47,7 +49,7 @@ struct LinkerObject
void link(std::map<std::string, h160> const& _libraryAddresses);
/// @returns a hex representation of the bytecode of the given object, replacing unlinked
/// addresses by placeholders.
/// addresses by placeholders. This output is lowercase.
std::string toHex() const;
/// @returns a 36 character string that is used as a placeholder for the library