Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EraVM] Adding support of library linkage #682

Merged
merged 2 commits into from
Sep 23, 2024
Merged

Conversation

PavelKopyl
Copy link
Contributor

Code Review Checklist

Purpose

Ticket Number

Requirements

  • Have the requirements been met?
  • Have stakeholder(s) approved the change?

Implementation

  • Does this code change accomplish what it is supposed to do?
  • Can this solution be simplified?
  • Does this change add unwanted compile-time or run-time dependencies?
  • Could an additional framework, API, library, or service improve the solution?
  • Could we reuse part of LLVM instead of implementing the patch or a part of it?
  • Is the code at the right abstraction level?
  • Is the code modular enough?
  • Can a better solution be found in terms of maintainability, readability, performance, or security?
  • Does similar functionality already exist in the codebase? If yes, why isn’t it reused?
  • Are there any best practices, design patterns or language-specific patterns that could substantially improve this code?

Logic Errors and Bugs

  • Can you think of any use case in which the
    code does not behave as intended?
  • Can you think of any inputs or external events
    that could break the code?

Error Handling and Logging

  • Is error handling done the correct way?
  • Should any logging or debugging information
    be added or removed?
  • Are error messages user-friendly?
  • Are there enough log events and are they
    written in a way that allows for easy
    debugging?

Maintainability

  • Is the code easy to read?
  • Is the code not repeated (DRY Principle)?
  • Is the code method/class not too long?

Dependencies

  • Were updates to documentation, configuration, or readme files made as required by this change?
  • Are there any potential impacts on other parts of the system or backward compatibility?

Security

  • Does the code introduce any security vulnerabilities?

Performance

  • Do you think this code change decreases
    system performance?
  • Do you see any potential to improve the
    performance of the code significantly?

Testing and Testability

  • Is the code testable?
  • Have automated tests been added, or have related ones been updated to cover the change?
    • For changes to mutable state
  • Do tests reasonably cover the code change (unit/integration/system tests)?
    • Line Coverage
    • Region Coverage
    • Branch Coverage
  • Are there some test cases, input or edge cases
    that should be tested in addition?

Readability

  • Is the code easy to understand?
  • Which parts were confusing to you and why?
  • Can the readability of the code be improved by
    smaller methods?
  • Can the readability of the code be improved by
    different function, method or variable names?
  • Is the code located in the right
    file/folder/package?
  • Do you think certain methods should be
    restructured to have a more intuitive control
    flow?
  • Is the data flow understandable?
  • Are there redundant or outdated comments?
  • Could some comments convey the message
    better?
  • Would more comments make the code more
    understandable?
  • Could some comments be removed by making the code itself more readable?
  • Is there any commented-out code?
  • Have you run a spelling and grammar checker?

Documentation

  • Is there sufficient documentation?
  • Is the ReadMe.md file up to date?

Best Practices

  • Follow Single Responsibility principle?
  • Are different errors handled correctly?
  • Are errors and warnings logged?
  • Magic values avoided?
  • No unnecessary comments?
  • Minimal nesting used?

Experts' Opinion

  • Do you think a specific expert, like a security
    expert or a usability expert, should look over
    the code before it can be accepted?
  • Will this code change impact different teams, and should they review the change as well?

@PavelKopyl PavelKopyl force-pushed the kpv-eravm-library-support branch 3 times, most recently from d5104c6 to e702b66 Compare August 31, 2024 11:08
lld/include/lld-c/LLDAsLibraryC.h Outdated Show resolved Hide resolved
lld/include/lld-c/LLDAsLibraryC.h Outdated Show resolved Hide resolved
lld/include/lld-c/LLDAsLibraryC.h Outdated Show resolved Hide resolved
@PavelKopyl PavelKopyl force-pushed the kpv-eravm-library-support branch 9 times, most recently from 6fadd01 to e209205 Compare September 11, 2024 08:34
Copy link
Collaborator

@akiramenai akiramenai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we put some effort into improving readability/maintainability?

lld/ELF/Arch/EraVM.cpp Outdated Show resolved Hide resolved
lld/include/lld-c/LLDAsLibraryC.h Show resolved Hide resolved
lld/include/lld-c/LLDAsLibraryC.h Outdated Show resolved Hide resolved
lld/include/lld-c/LLDAsLibraryC.h Outdated Show resolved Hide resolved
lld/lld-c/LLDAsLibraryC.cpp Outdated Show resolved Hide resolved
lld/lld-c/LLDAsLibraryC.cpp Show resolved Hide resolved
lld/lld-c/LLDAsLibraryC.cpp Outdated Show resolved Hide resolved
lld/lld-c/LLDAsLibraryC.cpp Show resolved Hide resolved
@PavelKopyl
Copy link
Contributor Author

PavelKopyl commented Sep 12, 2024

Could we put some effort into improving readability/maintainability?

Thank you very much for your comments! Sure, I'll address them. But I'd start with renaming "linker symbol" -> "library symbol" everywhere, but the intrinsic name. @hedgar2017, @akiramenai, are you OK with this? Original terminology "linker symbol" came from Solidity docs, but it is meaningless in LLVM-based tool chain. Essentially, these are usual symbols (in terminology of ELF format) that are resolved to the library addresses at a linking time. The only difference from the default workflow is that on MC level each library symbol is split into 5 sub-symbols because a library address is a 20-byte relocatable value, but our ELF format is ELF-32 one.

@PavelKopyl PavelKopyl force-pushed the kpv-eravm-library-support branch 3 times, most recently from 4cf8ae3 to 9511326 Compare September 17, 2024 12:22
Copy link
Collaborator

@akiramenai akiramenai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation and code improvements look great, thank you.
I agree that library symbols make more sense in terms of terminology. @hedgar2017 is it ok to rename?
Except for that and remained triple pointer, LGTM.

@hedgar2017
Copy link
Collaborator

hedgar2017 commented Sep 17, 2024

Documentation and code improvements look great, thank you.

I agree that library symbols make more sense in terms of terminology. @hedgar2017 is it ok to rename?

Except for that and remained triple pointer, LGTM.

I don't think it makes sense to make linker know about Solidity libraries.

Even Yul is agnostic of libraries and only features linkersymbol with an address. In handwritten Yul it is possible to link any address, not just a library.

@PavelKopyl
Copy link
Contributor Author

PavelKopyl commented Sep 17, 2024

Documentation and code improvements look great, thank you. I agree that library symbols make more sense in terms of terminology. @hedgar2017 is it ok to rename? Except for that and remained triple pointer, LGTM.

Thank you for the review!
As for the usage of "library symbol" terminology, after discussing this with @hedgar2017 we decided to keep the "linker symbol".
This seems reasonable because this patch, in fact, implements a generalization of relocatable symbol. In the ELF format the max width of a symbol value is 64 bits. Here we extended it to 160 bits. Yes, currently the only application of this feature is the libraries support, but in future we can employ this for other things.

Copy link
Collaborator

@akiramenai akiramenai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash

@hedgar2017 hedgar2017 changed the title [DO NOT MERGE][EraVM] Adding support of library linkage. [EraVM] Adding support of library linkage Sep 18, 2024
@hedgar2017
Copy link
Collaborator

You may just remove the lock, as it is not complete and FE is not going to be multi-threaded here anymore.

@PavelKopyl
Copy link
Contributor Author

You may just remove the lock, as it is not complete and FE is not going to be multi-threaded here anymore.

Yep, will remove it.

Copy link

github-actions bot commented Sep 20, 2024

╔═╡ Size (-%) ╞════════════════╡ All M3B3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════════════╡ All M3B3 ╞═╣
║ Best                               11.285 ║
║ Worst                              -2.196 ║
║ Total                              -0.003 ║
╠═╡ Ergs (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Best                                2.858 ║
║ Worst                              -0.941 ║
║ Total                              -0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════════════╡ All MzB3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════════════╡ All MzB3 ╞═╣
║ Best                               11.285 ║
║ Worst                              -2.196 ║
║ Total                              -0.003 ║
╠═╡ Ergs (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Best                                2.858 ║
║ Worst                              -0.941 ║
║ Total                              -0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter M3B3 ╞═╣
║ Best                               11.285 ║
║ Worst                              -2.196 ║
║ Total                              -0.438 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╣
║ Best                                2.858 ║
║ Worst                              -0.941 ║
║ Total                              -0.291 ║
╠═╡ Ergs/gas ╞══════╡ EVMInterpreter M3B3 ╞═╣
║ ADD                                44.750 ║
║ MUL                                26.850 ║
║ SUB                                44.750 ║
║ DIV                                29.250 ║
║ SDIV                               44.850 ║
║ MOD                                29.250 ║
║ SMOD                               42.450 ║
║ ADDMOD                             23.656 ║
║ MULMOD                             25.906 ║
║ EXP                                 7.338 ║
║ SIGNEXTEND                         26.850 ║
║ LT                                 48.750 ║
║ GT                                 48.750 ║
║ SLT                                72.750 ║
║ SGT                                70.750 ║
║ EQ                                 48.750 ║
║ ISZERO                             40.417 ║
║ AND                                44.750 ║
║ OR                                 44.750 ║
║ XOR                                44.750 ║
║ NOT                                36.417 ║
║ BYTE                               52.750 ║
║ SHL                                50.750 ║
║ SHR                                52.750 ║
║ SAR                                66.750 ║
║ SGT                                70.750 ║
║ SHA3                               27.121 ║
║ ADDRESS                            53.812 ║
║ BALANCE                            40.261 ║
║ ORIGIN                           1363.750 ║
║ CALLER                             53.812 ║
║ CALLVALUE                          53.812 ║
║ CALLDATALOAD                       38.750 ║
║ CALLDATASIZE                       54.125 ║
║ CALLDATACOPY                       52.446 ║
║ CODESIZE                           54.625 ║
║ CODECOPY                           64.426 ║
║ GASPRICE                         1357.562 ║
║ EXTCODESIZE                         3.767 ║
║ EXTCODECOPY                         3.832 ║
║ RETURNDATASIZE                     52.500 ║
║ RETURNDATACOPY                     45.222 ║
║ EXTCODEHASH                         4.996 ║
║ BLOCKHASH                         241.619 ║
║ COINBASE                         1360.750 ║
║ TIMESTAMP                        1354.750 ║
║ NUMBER                           1354.750 ║
║ PREVRANDAO                       1354.750 ║
║ GASLIMIT                         1360.750 ║
║ CHAINID                          1348.750 ║
║ SELFBALANCE                       644.100 ║
║ BASEFEE                          1354.750 ║
║ POP                                44.625 ║
║ MLOAD                              55.248 ║
║ MSTORE                             60.733 ║
║ MSTORE8                            68.480 ║
║ SLOAD                              20.976 ║
║ SSTORE                              4.744 ║
║ JUMP                               17.667 ║
║ JUMPI                              17.273 ║
║ PC                                 54.312 ║
║ MSIZE                              60.812 ║
║ GAS                                51.312 ║
║ JUMPDEST                           77.625 ║
║ PUSH0                              51.312 ║
║ PUSH1                              45.958 ║
║ PUSH2                              49.375 ║
║ PUSH4                              52.208 ║
║ PUSH5                              53.625 ║
║ PUSH6                              55.042 ║
║ PUSH7                              56.458 ║
║ PUSH8                              57.875 ║
║ PUSH9                              59.292 ║
║ PUSH10                             60.708 ║
║ PUSH11                             62.125 ║
║ PUSH12                             63.542 ║
║ PUSH13                             64.958 ║
║ PUSH14                             66.375 ║
║ PUSH15                             67.792 ║
║ PUSH16                             69.208 ║
║ PUSH17                             70.625 ║
║ PUSH18                             72.042 ║
║ PUSH19                             73.458 ║
║ PUSH20                             74.875 ║
║ PUSH21                             76.292 ║
║ PUSH22                             77.708 ║
║ PUSH23                             79.125 ║
║ PUSH24                             80.542 ║
║ PUSH25                             81.958 ║
║ PUSH26                             83.375 ║
║ PUSH27                             84.792 ║
║ PUSH28                             86.208 ║
║ PUSH29                             87.625 ║
║ PUSH30                             89.042 ║
║ PUSH31                             90.458 ║
║ PUSH32                             89.875 ║
║ DUP1                               36.417 ║
║ DUP2                               44.417 ║
║ DUP3                               44.417 ║
║ DUP4                               44.417 ║
║ DUP5                               44.417 ║
║ DUP6                               44.417 ║
║ DUP7                               44.417 ║
║ DUP8                               44.417 ║
║ DUP9                               44.417 ║
║ DUP10                              44.417 ║
║ DUP11                              44.417 ║
║ DUP12                              44.417 ║
║ DUP13                              44.417 ║
║ DUP14                              44.417 ║
║ DUP15                              44.417 ║
║ DUP16                              44.417 ║
║ SWAP1                              43.083 ║
║ SWAP2                              45.083 ║
║ SWAP3                              45.083 ║
║ SWAP4                              45.083 ║
║ SWAP5                              45.083 ║
║ SWAP6                              45.083 ║
║ SWAP7                              45.083 ║
║ SWAP8                              45.083 ║
║ SWAP9                              45.083 ║
║ SWAP10                             45.083 ║
║ SWAP11                             45.083 ║
║ SWAP12                             45.083 ║
║ SWAP13                             45.083 ║
║ SWAP14                             45.083 ║
║ SWAP15                             45.083 ║
║ SWAP16                             45.083 ║
║ CALL                               36.590 ║
║ STATICCALL                         35.620 ║
║ DELEGATECALL                       34.643 ║
║ CREATE                              4.095 ║
║ CREATE2                             5.574 ║
║ RETURN                              1.000 ║
║ REVERT                              1.000 ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
║ CALLDATACOPY                       24.194 ║
║ CODECOPY                           -3.153 ║
║ CALL                               -0.077 ║
║ STATICCALL                         -0.079 ║
║ DELEGATECALL                       -0.093 ║
║ CREATE                             -1.044 ║
║ CREATE2                            -1.158 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter MzB3 ╞═╣
║ Best                               11.285 ║
║ Worst                              -2.196 ║
║ Total                              -0.438 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╣
║ Best                                2.858 ║
║ Worst                              -0.941 ║
║ Total                              -0.291 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles M3B3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles MzB3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life M3B3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞════════╡ Real life M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life MzB3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞════════╡ Real life MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

@PavelKopyl PavelKopyl force-pushed the kpv-eravm-library-support branch 3 times, most recently from 2eb8037 to 864213b Compare September 23, 2024 15:09
This also includes the C-API for requiting the following info:
- If the given memory buffer contains an ELF file
- List of undefined linker symbols of the given ELF file
@akiramenai akiramenai merged commit a40666b into main Sep 23, 2024
11 of 13 checks passed
@akiramenai akiramenai deleted the kpv-eravm-library-support branch September 23, 2024 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants