简体   繁体   English

llvm可以发出跳转到函数内给定地址的代码吗?

[英]Can llvm emit code that jumps to a given address within a function?

Following up on this question, is it possible for llvm to generate code that may jump to an arbitrary address within a function in the same address space? 关注这个问题,llvm是否有可能生成可能跳转到同一地址空间中函数内任意地址的代码? ie

      void func1() {
       ...
       <code that jumps to addr2>
       ...
       }

       void func2() {
       ...
addr2:
       <some code in func2()>
       ...
       }

Yes,No,Yes,No,(yes) - It depends on the level you look at and what you mean with possible : 是的,不,是,否,(是) -这取决于你看水平,你的意思,与possible

  • Yes, as the llvm backend will produce target specific assembler instructions and those assembler instructions allow to set the program counter to an abitrary value. 是的,因为llvm后端将生成目标特定的汇编程序指令,并且那些汇编程序指令允许将程序计数器设置为abitrary值。
  • No, because - as far as I know - the llvm ir (the intermediate representation into which a frontend like clang compiles your c code) hasn't any instructions that would allow abitrary jumps between (llvm-ir) functions. 不,因为 - 据我所知 - llvm ir(像clang这样的前端编译你的c代码的中间表示)没有任何允许(llvm-ir)函数之间的abitrary跳转的指令。
  • Yes, because the frontend COULD certainly produce code, that simulates that behaviour (breaking up func2 into multiple separate functions). 是的,因为前端COULD肯定会生成代码,模拟该行为(将func2分解为多个单独的函数)。
  • No, because C and C++ don't allow such jumps to ARBITRARY positions and so clang will not compile any program that tries to do that (eg via goto ) 不,因为C和C ++不允许这样的跳转到ARBITRARY位置,所以clang不会编译任何尝试这样做的程序(例如通过goto
  • (yes) the c longjmp macro jumps back to a place in the control flow that you have already visited (where you called setjmp ) but also restores (most) of the system state. (是)c longjmp宏跳回到您已访问过的控制流中的某个位置(您调用setjmp ),但也恢复(大部分)系统状态。 EDIT: However, this is UB if func2 isn't somewhere up in the current callstack from where you jump. 编辑:但是,如果func2不在你跳转的当前callstack的某个地方,这就是UB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM