Note that there are some explanatory texts on larger screens.

plurals
  1. POunderstanding shared libraries using gcc
    primarykey
    data
    text
    <p>I am trying to understand the following behavior of shared libraries in C</p> <blockquote> <p>Machine One</p> </blockquote> <pre><code>$ cat one.c #include&lt;stdio.h&gt; int main() { printf ("%d", 45); } $ gcc one.c -o one -O3 $ ldd one linux-gate.so.1 =&gt; (0x00331000) libc.so.6 =&gt; /lib/tls/i686/cmov/libc.so.6 (0x00bc2000) /lib/ld-linux.so.2 (0x006dc000) $ cat two.c int main() { int i = 0; } $ gcc two.c -o two -O3 $ ldd two linux-gate.so.1 =&gt; (0x006f7000) libc.so.6 =&gt; /lib/tls/i686/cmov/libc.so.6 (0x00110000) /lib/ld-linux.so.2 (0x00eb0000) $ </code></pre> <blockquote> <p>Machine Two</p> </blockquote> <pre><code>$ cat three.c #include&lt;stdio.h&gt; int main() { printf ("%d", 45); } $ gcc three.c -o three -O3 $ ldd three /usr/lib/libcwait.so (0xb7ffd000) libc.so.6 =&gt; /lib/tls/i686/nosegneg/libc.so.6 (0x002de000) /lib/ld-linux.so.2 (0x002bf000) $ </code></pre> <p>A few things I don't fully understand at present:</p> <ul> <li><p>What does the address given in brackets (for example, <code>(0x002de000)</code>) mean?</p> <p>These addresses are different even for the same library on the same machine, which suggests these are addresses of the locations in memory where these libraries are loaded. But, if that is true, why are these libraries loaded in memory at all (I did not execute the programs yet, shouldn't they be loaded only at runtime?).</p></li> <li><p>Why does <code>two</code> need any libraries at all? I have used <code>-O3</code>, and the assembler output is</p> <pre><code>$ gcc two.c -S -O3 $ cat two.s .file "two.c" .text .p2align 4,,15 .globl main .type main, @function main: pushl %ebp movl %esp, %ebp popl %ebp ret .size main, .-main .ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3" .section .note.GNU-stack,"",@progbits $ </code></pre> <p>What is the need of any libraries at all?</p></li> <li><p>On Machine Two, why is <code>/usr/lib/libcwait.so</code> being used instead of <code>linux-gate.so.1</code>? </p> <p>I think this is because the kernel on Machine Two is very old (2.6.9) and the library <code>linux-gate.so.1</code> is not available. Is that the reason?</p></li> </ul>
    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.
 

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