This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: ld-auto-import documentation update


> > I've tried the testcase with  gcc version 2.95.3-5 (cygwin special).
> >
> > Any idead where we should document this feature ? In the cygwin do
> or in the ld
> > or ??? At least this is an gcc feature.
>
> Well, probably in gcc.  But, the ld documentation could be changed also:
>
Yes you're right. The gcc docu contains this already, so a note in ld should
make sense.

> 2. Sometimes, it is useful to rename exports.  For instance, the cygwin
> kernel does this regularly: a symbol @samp{_foo} will be exported as
> @samp{_foo}, but also as @samp{foo} by using special directives in the
> DEF file when creating the import library.  This ability is not
> present without import libs.
>
> Remove the last sentence, and continue:
>
> ----
> It is possible to mimic this behavior by using the following recipe: in
> your source code,
>
> void thefunction () { /* do something */; }
> void aliasforfunction () __attribute__ ((weak, alias ("thefunction")));
> ----
>
but in the case if this is a real replacement (can anyone else verify this), the
full topic isn't longer a reason for using importing import libs and should be
placed in a separate topic in the win 32 specific node. Any comments ?

> Now, last question: can you REALLY do this alias:
>
> foo -> _foo
>
> e.g. no underscore and with underscore, as in libcygwin.a:
>
> 00000000 I __imp___sqrt
> 00000000 T __sqrt
> 00000000 I __imp__sqrt
> 00000000 T _sqrt
>

yes with the costs of two exports in the dll. See the example. Try to compile
this

dll.c
--------------------------------------------------------------------
#include <stdio.h>

int foo = 1;

void _print_foo () __attribute__ ((weak, alias ("print_foo")));

void print_foo()
{
  printf("Dll sees foo=%d\n",foo);
}
--------------------------------------------------------------------
dll.c
--------------------------------------------------------------------
#include <stdio.h>

extern void print_foo();
extern void _print_foo();

main()
{
  print_foo();

  _print_foo();
	}
--------------------------------------------------------------------
gcc    -c -o dll.o dll.c
gcc --shared  dll.o -o dll.dll
gcc    -c -o client.o client.c
gcc -g -o client client.o  -L. -ldll


$ nm dll.o
00000000 b .bss
00000000 d .data
00000000 ? .stab
00000000 ? .stabstr
00000000 t .text
00000000 t ___gnu_compiled_c
00000014 T __print_foo
00000014 T _print_foo
00000000 D _foo
         U _printf
00000000 t gcc2_compiled.

$ nm client.o
00000000 b .bss
00000000 d .data
00000000 ? .stab
00000000 ? .stabstr
00000000 t .text
00000000 t ___gnu_compiled_c
         U ___main
         U __print_foo
         U _print_foo
00000000 T _main
00000000 t gcc2_compiled.

$objdump -x dll.dll
<snip>
Export Address Table -- Ordinal Base 1
        [   0] +base[   1] 1014 Export RVA
        [   1] +base[   2] 2000 Export RVA
        [   2] +base[   3] 1014 Export RVA
        [   3] +base[   4] 1034 Export RVA

[Ordinal/Name Pointer] Table
        [   0] _print_foo
        [   1] foo
        [   2] print_foo
        [   3] x
<snip>


Ralf


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]