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

Support disabling rewriting for specific function pointer types #417

Open
randomPoison opened this issue Oct 3, 2024 · 2 comments
Open
Assignees

Comments

@randomPoison
Copy link
Contributor

For some function pointers in a library, we don't want those to be rewritten because we know the function pointers are entirely internal to the compartment. We can use IA2_IGNORE in all of the places where function addresses are taken, but the fn ptr type will still get rewritten, resulting in compiler errors. We need a general mechanism for marking function pointer types that shouldn't be rewritten at all. IA2_BEGIN_NO_WRAP seems like the right mechanism for this, but currently it only applies to direct function calls, and can't be used in the way we want.

@kkysen kkysen self-assigned this Oct 4, 2024
@kkysen
Copy link
Contributor

kkysen commented Oct 4, 2024

From what I can tell, I don't think we need to change the apply_to = hasType(functionType) in IA2_BEGIN_NO_WRAP. With this

https://godbolt.org/z/3qsfqYEdG

typedef void(*a_fn)(int);

IA2_BEGIN_NO_WRAP

typedef void(*b_fn)(int, int);

struct DSP1 {
    a_fn a;
    b_fn b;
};

IA2_END_NO_WRAP

struct DSP2 {
    a_fn a;
    b_fn b;
};

b_fn, DSP1::a, DSP2::b all get AnnotateAttrs with ia2_skip_wrap.

So what we need to do is the rest of what @ayrtonm outlined:

  1. add an ignore_type to SourceRewriter.cpp analogous to the existing ignore_function
  2. call this ignore_type somewhere in the run method in the FnPtrTypes class

@ayrtonm ayrtonm self-assigned this Oct 7, 2024
@ayrtonm
Copy link
Contributor

ayrtonm commented Oct 7, 2024

To summarize discussions on slack:

using the being_no_wrap macro is gonna be more complicated here. Basically changing FnPtrTypes::run will keep the those types as fn ptrs (instead of structs) in the sources output by the rewriter, but in the input sources they'll still be seen as fn ptrs so the other libtooling passes (i.e. FnPtrExpr::run, FnPtrCall::run, etc.) may still find matches for things with those types. I think most of the other passes will need changes but it may be tricky for some of them because I don't think you can put attributes on expressions in C.

I'll handle this since it's not as simple as I anticipated and we'd really like to avoid the hacky workarounds that @kkysen needed for this.

@kkysen kkysen removed their assignment Oct 7, 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

3 participants