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

Assertion NewParamInfo.size() == getNumParams() && "Parameter count mismatch!" failed. #333

Closed
aytey opened this issue Mar 28, 2024 · 3 comments
Assignees

Comments

@aytey
Copy link

aytey commented Mar 28, 2024

I am using rellic at commit: 86280f6

The system I'm running this on is:

uname -a
Linux ubnt2204 5.15.0-101-generic #111-Ubuntu SMP Tue Mar 5 20:16:58 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy

Here's my example:

void a(void *b) { __asm__(""); }

Which I compile and try to decompile as follows:

${HOME}/lifting-bits-downloads/vcpkg_ubuntu-22.04_llvm-16_amd64/installed/x64-linux-rel/bin/clang -emit-llvm -c input.c -o input.bc -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter

${HOME}/rellic/rellic-build/install/usr/local/bin/rellic-decomp --input input.bc --output output.c

Note: I'm using the clang that gets pulled down by vcpkg when building rellic from source (so hopefully everything is compatible).

When I run this, I get the following error:

rellic-decomp: /__w/cxx-common/cxx-common/vcpkg/buildtrees/llvm-16/src/org-16.0.5-90a3d25b70.clean/clang/lib/AST/Decl.cpp:3489: void clang::FunctionDecl::setParams(clang::ASTContext&, llvm::ArrayRef<clang::ParmVarDecl*>): Assertion `NewParamInfo.size() == getNumParams() && "Parameter count mismatch!"' failed.

Here is how the backtrace looks in gdb:

#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140737348173440) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=140737348173440) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140737348173440, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff7a96476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff7a7c7f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007ffff7a7c71b in __assert_fail_base (fmt=0x7ffff7c31130 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
    assertion=0x55555b8c1378 "NewParamInfo.size() == getNumParams() && \"Parameter count mismatch!\"",
    file=0x55555b8be838 "/__w/cxx-common/cxx-common/vcpkg/buildtrees/llvm-16/src/org-16.0.5-90a3d25b70.clean/clang/lib/AST/Decl.cpp", line=3489, function=<optimized out>)
    at ./assert/assert.c:92
#6  0x00007ffff7a8de96 in __GI___assert_fail (assertion=0x55555b8c1378 "NewParamInfo.size() == getNumParams() && \"Parameter count mismatch!\"",
    file=0x55555b8be838 "/__w/cxx-common/cxx-common/vcpkg/buildtrees/llvm-16/src/org-16.0.5-90a3d25b70.clean/clang/lib/AST/Decl.cpp", line=3489,
    function=0x55555b8c1318 "void clang::FunctionDecl::setParams(clang::ASTContext&, llvm::ArrayRef<clang::ParmVarDecl*>)") at ./assert/assert.c:101
#7  0x000055555833398f in clang::FunctionDecl::setParams(clang::ASTContext&, llvm::ArrayRef<clang::ParmVarDecl*>) ()
#8  0x000055555622fe16 in clang::FunctionDecl::setParams (this=0x55555d0e9a28, NewParamInfo=...)
    at /home/avj/lifting-bits-downloads/vcpkg_ubuntu-22.04_llvm-16_amd64/installed/x64-linux-rel/include/clang/AST/Decl.h:2616
#9  0x000055555625a690 in rellic::IRToASTVisitor::VisitFunctionDecl (this=0x55555d00fe68, func=...) at /home/avj/rellic/lib/AST/IRToASTVisitor.cpp:1247
#10 0x000055555622ceaa in rellic::GenerateAST::run (this=0x55555d00fe68, module=..., MAM=...) at /home/avj/rellic/lib/AST/GenerateAST.cpp:545
#11 0x000055555624f415 in llvm::detail::PassModel<llvm::Module, rellic::GenerateAST, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (this=0x55555d00fe60, IR=..., AM=...) at /home/avj/lifting-bits-downloads/vcpkg_ubuntu-22.04_llvm-16_amd64/installed/x64-linux-rel/include/llvm/IR/PassManagerInternal.h:89
#12 0x00005555599d26fe in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) ()
#13 0x000055555622d874 in rellic::GenerateAST::run (module=..., dec_ctx=...) at /home/avj/rellic/lib/AST/GenerateAST.cpp:653
#14 0x0000555555fe5002 in rellic::Decompile (module=std::unique_ptr<llvm::Module> = {...}, options=...) at /home/avj/rellic/lib/Decompiler.cpp:97
#15 0x0000555555fb5f91 in main (argc=1, argv=0x7fffffffe418) at /home/avj/rellic/tools/decomp/Decomp.cpp:125
@aytey aytey changed the title Assertion NewParamInfo.size() == getNumParams() && "Parameter count mismatch!"'` Assertion NewParamInfo.size() == getNumParams() && "Parameter count mismatch!" Mar 28, 2024
@aytey aytey changed the title Assertion NewParamInfo.size() == getNumParams() && "Parameter count mismatch!" Assertion NewParamInfo.size() == getNumParams() && "Parameter count mismatch!" failed. Mar 28, 2024
@aytey aytey changed the title Assertion NewParamInfo.size() == getNumParams() && "Parameter count mismatch!" failed. Assertion NewParamInfo.size() == getNumParams() && "Parameter count mismatch!" failed. Mar 28, 2024
@pgoodman
Copy link
Collaborator

It's possible that rellic doesn't properly understand inline assembly. Those are implemented via function calls in clang.

@aytey
Copy link
Author

aytey commented Mar 28, 2024

So the line where code hits the assertion is in the process of trying to handle the asm block, but it just falls over:

if (auto iasm = llvm::dyn_cast<llvm::InlineAsm>(&opnd)) {
// TODO(frabert): We still need to find a way to embed the inline asm
// into the function
auto &decl{dec_ctx.value_decls[iasm]};
if (decl) {
return;
}
auto tudecl{dec_ctx.ast_ctx.getTranslationUnitDecl()};
auto name{"asm_" +
std::to_string(GetNumDecls<clang::FunctionDecl>(tudecl))};
auto ftype{iasm->getFunctionType()};
auto type{dec_ctx.GetQualType(ftype)};
decl = ast.CreateFunctionDecl(tudecl, type, name);
std::vector<clang::ParmVarDecl *> iasm_params;
for (auto arg : ftype->params()) {
auto arg_type{dec_ctx.GetQualType(arg)};
auto name{"arg_" + std::to_string(iasm_params.size())};
iasm_params.push_back(
ast.CreateParamDecl(decl->getDeclContext(), arg_type, name));
}
auto fdecl{decl->getAsFunction()};
fdecl->setParams(params);

@pgoodman
Copy link
Collaborator

Inline asm is tricky because Clang does some kind of translation of it into an internal LLVM-specific assembly dialect.

frabert added a commit that referenced this issue Apr 29, 2024
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

No branches or pull requests

4 participants