Link binaries produced in assembly mode

This commit is contained in:
Kamil Śliwak 2020-11-05 14:40:51 +01:00
parent 6ef1e4cfd4
commit df8e182b46
11 changed files with 53 additions and 5 deletions

View File

@ -8,6 +8,7 @@ Compiler Features:
* SMTChecker: Support ``selector`` for expressions with value known at compile-time.
* Command Line Interface: New option ``--model-checker-timeout`` sets a timeout in milliseconds for each individual query performed by the SMTChecker.
* Standard JSON: New option ``modelCheckerSettings.timeout`` sets a timeout in milliseconds for each individual query performed by the SMTChecker.
* Assembler: Perform linking in assembly mode when library addresses are provided.
Bugfixes:

View File

@ -1180,8 +1180,6 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
return formatFatalError("JSONError", "Yul mode does not support smtlib2responses.");
if (!_inputsAndSettings.remappings.empty())
return formatFatalError("JSONError", "Field \"settings.remappings\" cannot be used for Yul.");
if (!_inputsAndSettings.libraries.empty())
return formatFatalError("JSONError", "Field \"settings.libraries\" cannot be used for Yul.");
if (_inputsAndSettings.revertStrings != RevertStrings::Default)
return formatFatalError("JSONError", "Field \"settings.debug.revertStrings\" cannot be used for Yul.");
@ -1234,6 +1232,11 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
MachineAssemblyObject runtimeObject;
tie(object, runtimeObject) = stack.assembleAndGuessRuntime();
if (object.bytecode)
object.bytecode->link(_inputsAndSettings.libraries);
if (runtimeObject.bytecode)
runtimeObject.bytecode->link(_inputsAndSettings.libraries);
for (string const& objectKind: vector<string>{"bytecode", "deployedBytecode"})
if (isArtifactRequested(
_inputsAndSettings.outputSelection,

View File

@ -1895,6 +1895,7 @@ bool CommandLineInterface::assemble(
try
{
object = stack.assemble(_targetMachine);
object.bytecode->link(m_libraries);
}
catch (Exception const& _exception)
{

View File

@ -1 +1 @@
{"errors":[{"component":"general","formattedMessage":"Field \"settings.libraries\" cannot be used for Yul.","message":"Field \"settings.libraries\" cannot be used for Yul.","severity":"error","type":"JSONError"}]}
{"contracts":{"A":{"a":{"evm":{"bytecode":{"generatedSources":[],"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"}}}}},"errors":[{"component":"general","formattedMessage":"Yul is still experimental. Please use the output with care.","message":"Yul is still experimental. Please use the output with care.","severity":"warning","type":"Warning"}]}

View File

@ -0,0 +1,20 @@
{
"language": "Yul",
"sources": {
"A": {
"content": "object \"a\" { code { let addr := linkersymbol(\"contract/test\\\".sol:L\") } }"
}
},
"settings": {
"libraries": {
"contract/test\".sol": {
"L": "0x1234567890123456789012345678901234567890"
}
},
"outputSelection": {
"*": {
"*": ["evm.bytecode.object", "evm.bytecode.linkReferences"]
}
}
}
}

View File

@ -0,0 +1 @@
{"contracts":{"A":{"a":{"evm":{"bytecode":{"generatedSources":[],"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"}}}}},"errors":[{"component":"general","formattedMessage":"Yul is still experimental. Please use the output with care.","message":"Yul is still experimental. Please use the output with care.","severity":"warning","type":"Warning"}]}

View File

@ -0,0 +1,20 @@
{
"language": "Yul",
"sources": {
"A": {
"content": "object \"a\" { code { let addr1 := linkersymbol(\"contract/test.sol:L1\") let addr2 := linkersymbol(\"contract/test.sol:L2\") } }"
}
},
"settings": {
"libraries": {
"contract/test.sol": {
"L1": "0x1234567890123456789012345678901234567890"
}
},
"outputSelection": {
"*": {
"*": ["evm.bytecode.object", "evm.bytecode.linkReferences"]
}
}
}
}

View File

@ -0,0 +1 @@
{"contracts":{"A":{"a":{"evm":{"bytecode":{"generatedSources":[],"linkReferences":{"contract/test.sol":{"L2":[{"length":20,"start":22}]}},"object":"<BYTECODE REMOVED>__$fb58009a6b1ecea3b9d99bedd645df4ec3$__<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"}}}}},"errors":[{"component":"general","formattedMessage":"Yul is still experimental. Please use the output with care.","message":"Yul is still experimental. Please use the output with care.","severity":"warning","type":"Warning"}]}

View File

@ -10,7 +10,7 @@ object "a" {
Binary representation:
73__$f919ba91ac99f96129544b80b9516b27a8$__50
73123456789012345678901234567890123456789050
Text representation:
linkerSymbol("f919ba91ac99f96129544b80b9516b27a80e376b9dc693819d0b18b7e0395612")

View File

@ -11,7 +11,7 @@ object "a" {
Binary representation:
<BYTECODE REMOVED>__$05b0326038374a21e0895480a58bda0768$__<BYTECODE REMOVED>__$fb58009a6b1ecea3b9d99bedd645df4ec3$__5050
73123456789012345678901234567890123456789073__$fb58009a6b1ecea3b9d99bedd645df4ec3$__5050
Text representation:
linkerSymbol("05b0326038374a21e0895480a58bda0768cdcc04c8d18f154362d1ca5223d245")

View File

@ -97,6 +97,7 @@ bytes SolidityExecutionFramework::multiSourceCompileContract(
{
asmStack.optimize();
obj = std::move(*asmStack.assemble(yul::AssemblyStack::Machine::EVM).bytecode);
obj.link(_libraryAddresses);
break;
}
catch (...)