Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that on most <code>UNIX</code> platforms (unlike on <code>Win32</code> and <code>AIX</code>) all symbol references by default bind to the <em>first</em> definition of the symbol visible to the runtime loader.</p> <p>If you define <code>'operator new'</code> in the main <code>a.out</code>, everything will bind to that definition (as Neil Butterworth's example shows), because <code>a.out</code> is the very first image runtime loader searches.</p> <p>If you define it in a library which is loaded after <code>libC.so</code> (or <code>libstdc++.so</code> in case you are using <code>GCC</code>), then your definition will never be used. Since you are <code>dlopen()</code>ing your library after the program has started, <code>libC</code> is already loaded by that point, and your library is the very last one the runtime loader will search; so you lose. </p> <p>On <code>ELF</code> platforms, you may be able to change the default behavior by using <code>-Bsymbolic</code>. From <code>man ld</code> on Linux:</p> <pre><code> -Bsymbolic When creating a shared library, bind references to global symbols to the definition within the shared library, if any. Normally, it is possible for a program linked against a shared library to override the definition within the shared library. This option is only meaningful on ELF platforms which support shared libraries. </code></pre> <p>Note that <code>-Bsymbolic</code> is a linker flag, not a compiler flag. If using <code>g++</code>, you must pass the flag to the linker like this:</p> <pre><code> g++ -fPIC -shared library.cpp -o library.so -Wl,-Bsymbolic </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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