Add:
- RV64C instructions sets.
- corresponding unittests.
- c.break code for lldb and lldb-server
Fix:
- wrong decoding of imm in DecodeSType
Differential D136362
[LLDB][RISCV] Add RV64C instruction support for EmulateInstructionRISCV Emmmer on Oct 20 2022, 8:25 AM. Authored by
Details Add:
Fix:
Diff Detail Event TimelineComment Actions Cool to see the lowering in action. A few comments but (arch details aside) this is looking good.
Comment Actions Oh and is this a specific named subset of RVC? Would be good to be specific in the commit title if there is a name for this set you are adding.
Comment Actions You could add static asserts with https://en.cppreference.com/w/cpp/types/is_trivial if you wanted to enforce the POD-ness of the instructions. Up to you though. I don't see a need for complex fields and it would probably fail quite fast over a few test runs in any case. This LGTM with the one comment ammended.
Comment Actions After commit 05ae747a5353811f93f5814f24d2335e6229d78a ("[LLDB][RISCV] Add RV64C instruction support for EmulateInstructionRISCV"), [1/3] Building CXX object tools/lldb/unittests/Instruction/CMakeFiles/EmulatorTests.dir/RISCV/TestRISCVEmulator.cpp.o FAILED: tools/lldb/unittests/Instruction/CMakeFiles/EmulatorTests.dir/RISCV/TestRISCVEmulator.cpp.o /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/loongson/llvm-project/llvm/build/tools/lldb/unittests/Instruction -I/home/loongson/llvm-project/lldb/unittests/Instruction -I/home/loongson/llvm-project/lldb/include -I/home/loongson/llvm-project/llvm/build/tools/lldb/include -I/home/loongson/llvm-project/llvm/build/include -I/home/loongson/llvm-project/llvm/include -I/home/loongson/llvm-project/llvm/../clang/include -I/home/loongson/llvm-project/llvm/build/tools/lldb/../clang/include -I/home/loongson/llvm-project/lldb/source -I/home/loongson/llvm-project/lldb/unittests -I/home/loongson/llvm-project/llvm/utils/unittest/googletest/include -I/home/loongson/llvm-project/llvm/utils/unittest/googlemock/include -isystem /usr/include/libxml2 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-stringop-truncation -O3 -DNDEBUG -include /home/loongson/llvm-project/lldb/unittests/gtest_common.h -Wno-variadic-macros -fno-exceptions -fno-rtti -Wno-suggest-override -std=c++17 -MD -MT tools/lldb/unittests/Instruction/CMakeFiles/EmulatorTests.dir/RISCV/TestRISCVEmulator.cpp.o -MF tools/lldb/unittests/Instruction/CMakeFiles/EmulatorTests.dir/RISCV/TestRISCVEmulator.cpp.o.d -o tools/lldb/unittests/Instruction/CMakeFiles/EmulatorTests.dir/RISCV/TestRISCVEmulator.cpp.o -c /home/loongson/llvm-project/lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp c++: fatal error: Killed signal terminated program cc1plus compilation terminated. ninja: build stopped: subcommand failed. After revert the changes in lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp, build successful. Comment Actions I failed to repro this error. :(
With such a vague error message it is hard to find the problematic part and it does not look like a code problem. Would you mind checking your build configuration and trying ninja check-lldb -j1 for detailed information? Comment Actions dmesg shows that the compiler is getting killed by the OOM-killer due to using too many resources. Comment Actions Can you give us:
Could be tripping over a bug in g++. If that version is >= the minimum llvm requires we should look for a workaround. One thing you could try is removing parts of TestRISCVEmulator.cpp and seeing what breaks the build. Though this is best done by @Emmmer, if it can be reproduced elsewhere. Comment Actions git clone https://github.com/llvm/llvm-project.git mkdir -p llvm-project/llvm/build cd llvm-project/llvm/build cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="BPF" \ -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="LoongArch" \ -DLLVM_ENABLE_PROJECTS="clang;lldb" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_BUILD_RUNTIME=OFF ninja ninja check-lldb -j1
gcc (GCC) 13.0.0 20220919
clfs loongarch
LoongArch
clang version 14.0.6
This is introduced in the following commit: $ git log -p lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp commit 05ae747a5353811f93f5814f24d2335e6229d78a Author: Emmmer <yjhdandan@163.com> Date: Thu Oct 20 23:05:37 2022 +0800 [LLDB][RISCV] Add RV64C instruction support for EmulateInstructionRISCV c++ OOM is related with this vector, if it is empty, building is OK, if it has one element at least, build failed. std::vector<TestDecode> tests = { }; @SixWeining can also reproduce it on his local machine. Comment Actions I suspect the cause is that g++ tries to instantiate these generic lambdas inside std::visit, which consumes N^2 the size memory (or whatever is related?) when there's nested-std::visit bool compareInst(const RISCVInst &lhs, const RISCVInst &rhs) { if (lhs.index() != rhs.index()) return false; return std::visit( [&](auto &&L) { return std::visit( [&](auto &&R) { return std::memcmp(&L, &R, sizeof(L)) == 0; }, rhs); }, lhs); } we can try to change this code to : bool compareInst(const RISCVInst &L, const RISCVInst &R) { return std::visit( [](auto &&lhs, auto &&rhs) { return std::is_same_v<decltype(lhs), decltype(rhs)> && memcmp(&lhs, &rhs, sizeof(lhs)) == 0; }, L, R); } But I’m unsure if it will work. Comment Actions I can reproduce this issue on x86_64 used with the latest gcc. (1) Install Fedora36 $ uname -a (2) Install some packages $ gcc --version (3) Build llvm git clone https://github.com/llvm/llvm-project.git mkdir -p llvm-project/llvm/build cd llvm-project/llvm/build cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="X86" \ -DLLVM_ENABLE_PROJECTS="clang;lldb" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_BUILD_RUNTIME=OFF ninja ninja check-lldb This is OK used with gcc/c++ 12. (4) Update gcc to the latest version $ gcc --version (5) Do the above (3) again used with gcc/c++ 13 git clone https://github.com/llvm/llvm-project.git mkdir -p llvm-project/llvm/build cd llvm-project/llvm/build cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="X86" \ -DLLVM_ENABLE_PROJECTS="clang;lldb" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_BUILD_RUNTIME=OFF \ -DCMAKE_C_COMPILER="/usr/local/gcc/bin/gcc" \ -DCMAKE_CXX_COMPILER="/usr/local/gcc/bin/c++" ninja ninja check-lldb We can see that "ninja check-lldb" failed due to OOM Comment Actions Then I guess it is a gcc-specific bug and you could try to report this to their developers.
We can try arc patch --diff 137041 before cmake and see if it failed. Let's move to D137041 |
No bit 0 because you'll never be branching to an odd address, correct?