Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6365433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:17:30+00:00 2026-05-25T00:17:30+00:00

I need some advice on forwarding arguments to a callee (in the LLVM-IR). Suppose

  • 0

I need some advice on “forwarding” arguments to a callee (in the LLVM-IR).

Suppose I have a function F that is called at the beginning of all other functions in the module. From F I need to access (read) the arguments passed to its immediate caller.

Right now to do this I box all arguments in the caller inside a struct and pass a i8* pointer to the struct to F, alongside an identifier telling which caller F is being called from. F has then a giant switch that branches to the appropriate unboxing code. This must be done because the functions in the module have differing signatures (differing argument/return value count and types; even differing calling conventions), but it is obviously suboptimal (both from a performance and code size point-of-view) because I need to allocate the struct on the stack, copy the arguments inside of it, passing an additional pointer to F and then performing the unboxing.

I was wondering if there’s a better way to do this, i.e. a way to access from a function the stack frame of its immediate caller (knowing, thanks to the identifier, which caller the function was called from) or, more in general, arbitrary values defined in its immediate caller. Any suggestions?

note: the whole point of what I’m working on is having a single function F that does all this; splitting/inlining/specializing/templating F is not an option.


to clarify, suppose we have the following functions FuncA and FuncB (note: what follows is just pseudo-C-code, always remember we are talking about LLVM-IR!)

Type1 FuncA(Type2 ArgA1) {
  F();
  // ...
}

Type3 FuncB(Type4 ArgB1, Type5 ArgB2, Type6 ArgB3) {
  F();
  // ...
}

what I need is an efficient way for the function F to do the following:

void F() {
  switch (caller) {
    case FuncA:
      // do something with ArgA1
      break;
    case FuncB:
      // do something with ArgB1, ArgB2, ArgB3
      break;
  }
}

as I explained in the first part, right now my F looks like this:

struct Args_FuncA { Type2 ArgA1 };
struct Args_FuncB { Type4 ArgB1, Type5 ArgB2, Type6 ArgB3 };

void F(int callerID, void *args) {
  switch (callerID) {
    case ID_FuncA:
      Args_FuncA *ArgsFuncA = (Args_FuncA*)args;
      Type2 ArgA1 = ArgsFuncA->ArgA1;
      // do something with ArgA1
      break;
    case ID_FuncB:
      Args_FuncB *ArgsFuncB = (Args_FuncB*)args;
      Type4 ArgB1 = ArgsFuncB->ArgB1;
      Type5 ArgB2 = ArgsFuncB->ArgB2;
      Type6 ArgB3 = ArgsFuncB->ArgB3;
      // do something with ArgB1, ArgB2, ArgB3
      break;
  }
}

and the two functions become:

Type1 FuncA(Type2 ArgA1) {
  Args_FuncA args = { ArgA1 };
  F(ID_FuncA, (void*)&args);
  // ...
}

Type3 FuncB(Type4 ArgB1, Type5 ArgB2, Type6 ArgB3) {
  Args_FuncB args = { ArgB1, ArgB2, ArgB3 };
  F(ID_FuncB, (void*)&args);
  // ...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:17:31+00:00Added an answer on May 25, 2026 at 12:17 am

    IMHO you’ve done it right. While there are solutions in machinecode assembly, I am afraid there might be no solution in LLVM assembly, as it’s “higher level”. If you’d like to run a function on the beginning of some functions have you thought about checking

    • debugger sources (like gdb)
    • Binary Instrumentation with Valgrind

    I know it’s not direct answer, but I hope it might be helpful in some way ;).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some advice with the Java Print API. I have a program that
I need some advice. I’m building an app that has a sequence of 4
I need some advice of how to setup my tables I currently have a
I need some advice for a design which I have to implement in application.
I need some advice in the following matter: I have a QT project, which
I need some advice here, I hope somebody can help me. I have the
I need some advice. I have a web page and want to extend it's
I need some advice, I have a simple html input type text field: <p><input
I need some advice here. I need to make a webservice, that can make
Need some advice, I'm after a decent process/task manager for Ubuntu. Basically I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.