Note that there are some explanatory texts on larger screens.

plurals
  1. POpreventing "ld -wrap " circular references
    primarykey
    data
    text
    <p>I am using GNU ld's "-wrap" option to intercept calls in applications, but have ran into a scenario where the code implementing the wrapper indirectly calls the wrapped function, creating a circular reference.</p> <h2>Example</h2> <p>The goal is to wrap read calls that occur in Program Foo. This code can be recompiled/relinked, but not modified.</p> <h3>Program Foo</h3> <pre><code>main() { ... read(fd, buf, size); ... } </code></pre> <p>The wrapper here will intercept calls to libc's read in Program Foo when using "-wrap read".</p> <h3>Wrapper</h3> <pre><code>extern int __real_read(...); int __wrap_read(...) { bar(); __real_read(...); } </code></pre> <p>However, Library Bar, called from the wrapper needs to use libc's read() function without going through the wrapper (thus causing the circular dependency).</p> <h3>Library Bar</h3> <pre><code>void bar(void) { read(fd, buf, size) } </code></pre> <p>Changing all wrapped routines in Library Bar to use __real_read() is not an option because the level of indirections that exist inside additional calls to external libraries in Library Bar are arbitrary.</p> <h2>Avoiding Flags</h2> <p>One way to solve this is to use per-thread flags to prevent wrapped reads originating from Library Bar reentering the library. Although I would prefer to not use this solution, I'm also open to suggestions on how to implement this with minimal code change in the wrapper and bar libraries.</p> <h2>Ideal Solution</h2> <p>??? That is why I'm asking the question :)</p> <p>Thanks... -n</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload