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

[1.0.3] fix building with LLVM 7, 8, and 9 #903

Merged
merged 1 commit into from
Oct 8, 2024
Merged

Conversation

spoonincode
Copy link
Member

Spring claims that it builds with LLVM versions 7 through 11. Code says it,

spring/CMakeLists.txt

Lines 68 to 70 in 1606ade

if(LLVM_VERSION_MAJOR VERSION_LESS 7 OR LLVM_VERSION_MAJOR VERSION_GREATER_EQUAL 12)
message(FATAL_ERROR "Spring requires an LLVM version 7 through 11")
endif()

README says it,
- LLVM 7 - 11 - for Linux only

Unfortunately building with versions 7-9 was broken in leap 5.0. This change restores building with LLVM 7 through 11 by using an older interface that's common across all supported LLVM versions.

An example exhaustive workflow run with all versions 7-11 enabled:
https://github.com/AntelopeIO/spring/actions/runs/11223407160
(this is off a demonstration only branch that cherry-picks the workflow back to 1.0, as otherwise it only exists on main. plus also then adding #902 on top)

#else
using de_offset_t = uint64_t;
#endif
llvm::DataExtractor ds(llvm::StringRef(reinterpret_cast<const char*>(stacksizes.data()), stacksizes.size()), true, 8);
Copy link
Member Author

Choose a reason for hiding this comment

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

okay okay, I know this looks all sorts of ick, but take a look at,
https://github.com/llvm/llvm-project/blob/release/11.x/llvm/include/llvm/Support/DataExtractor.h#L85
The ctor that takes an ArrayRef does the exact same cast + StringRef as I'm doing here. So this is not really even a change for existing working versions.

de_offset_t offset = 0;

while(ds.isValidOffsetForAddress(offset)) {
ds.getAddress(&offset);
Copy link
Member Author

Choose a reason for hiding this comment

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

isValidOffsetForAddress() guarantees there is enough space in the buffer for getAddress() to succeed.

ds.getAddress(&offset);
const de_offset_t offset_before_read = offset;
const uint64_t stack_size = ds.getULEB128(&offset);
WAVM_ASSERT_THROW(offset_before_read != offset);
Copy link
Member Author

Choose a reason for hiding this comment

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

This older interface of getULEB128() documents that if it fails to read the variable sized int, offset is not incremented. The Cursor/Error interface is a lot better, but our use case here is simple enough this still seems clear enough.

using de_offset_t = uint32_t;
#else
using de_offset_t = uint64_t;
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see any sort of exposed typedef/using to make this cleaner.

@spoonincode spoonincode merged commit bc2bee9 into release/1.0 Oct 8, 2024
36 checks passed
@spoonincode spoonincode deleted the fix-llvm789 branch October 8, 2024 00:30
@ericpassmore
Copy link
Contributor

Note:start
category: System Stability
component: Internal
summary: Fix building with LLVM 7, 8, and 9.
Note:end

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.

4 participants