3

I was looking into a C++ program compiled for aarch64 with ida pro 6.9 and came across something really weird:

somescope::SomeClass<false>::some_name<somescope::SomeClass<false>::other_name(uint,uint,uint)::{lambda(void *,bool)#2}>::SOMETHING

I'm really confused by this notation... Specifically:

  1. What does {lambda(void *,bool)#2} mean? Is it an indicator for lambda expression? Also, what is #2?

  2. Is other_name(uint,uint,uint) somewhat a scope? What could other_name possibly be if this is the case?

I'm fairly new to reverse engineering and I've tried to google this for like an hour... Please hint me if you've got clue.

Thanks in advance!

3

About your first question: what does ...lambda... mean: Yes, obviously, it refers to a lambda function.

The second part of your first question: What is #2: Some experimentation with lambda's shows that this is like a sequence number of lambda's within a function. Note that gcc and clang have different ways of encoding this. gcc uses the lambda()#2 notation, while clang uses something like $_1.

Your second question: what is other_name: I think that would be the function where the lambda is defined.

And some_name being the function which is passed the lambda as a template parameter.

The lambda's themselves are passed as a struct containing either copies of values or pointers, or from a c++ point of view: references, to the closure defined by the lambda.


Experimenting with how your compiler treats lambda's is quite easy. Write some test code:

#include <stdio.h>

template<typename FN>
int test(FN f)
{
    return f();
}

int main(int, char**)
{
    int a, b;
    auto f1 = [](int a, int b) { return a+b; };
    int c = test([&a, b, &f1]() { return f1(a,b); });
    auto f2 = [](int a, int b) { return a-b; };
    int d = test([&a, b, &f2]() { return f2(a,b); });

    printf("c=%d, d=%d\n", c, d);
    return 0;
}

Then compile with least optimization, and debug symbols:

g++ -O0 -g yourfile.cpp

And view the resulting binary in ida.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.