From ae428dc2a03733d51332b1c785f8e9a1e14f4829 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 20 Nov 2019 21:34:39 +0000 Subject: [PATCH] Clarify some notes in LinkerObject and assert that linkReferences are always correct --- libevmasm/Assembly.cpp | 3 +++ libevmasm/LinkerObject.h | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index ae8d001d7..88bddd7f7 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -519,8 +519,11 @@ map 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) diff --git a/libevmasm/LinkerObject.h b/libevmasm/LinkerObject.h index 928908032..3630365e0 100644 --- a/libevmasm/LinkerObject.h +++ b/libevmasm/LinkerObject.h @@ -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 linkReferences; @@ -47,7 +49,7 @@ struct LinkerObject void link(std::map 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