Re: Non-relocatable DLLs and GCC -shared

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Danny,

Thanks for your answer.

 > gcc -mdll -ofoo.dll --Wl,-out-implib,libfoo.a foo.def foo.c

It seems to me that the DLL built this way are somehow relocatable. What I
have done is to build 2 DLLs. Both are using the same ImageBase and yet a
program using both can be started. The program should not be able to start
and reports and error as the second DLL should fails to load properly.

Am I missing something ?

Here is what I have tried:

file: main.c
<<
#include <stdio.h>

extern void fct1 (void);
extern void fct2 (void);

int
main (void)
{
  printf ("main\n");
  fct1();
  fct2();
}
>>

file: code1.c
<<
#include <stdio.h>

void
fct1 (void)
{
  printf ("fct1\n");
}
>>

file: code2.c
<<
#include <stdio.h>

void
fct2 (void)
{
  printf ("fct2\n");
}
>>

file: code1.def
<<
EXPORTS
	fct1
>>

file: code2.def
<<
EXPORTS
	fct2
>>

$ gcc -mdll -o dll1-nr.dll -Wl,--out-implib,libdll1.a code1.def code1.c
$ gcc -mdll -o dll2-nr.dll -Wl,--out-implib,libdll2.a code2.def code2.c
$ gcc -o main-nr main.c libdll1.a libdll2.a
$ ./main-nr

To build a non-relocatable DLL, the procedure was to build an .exp file,
doing this will build a non-relocatable DLL:

$ dlltool --def code1.def --dllname dll1-nr.dll --output-lib libdll1.a --output-exp dll1.exp
$ dlltool --def code2.def --dllname dll2-nr.dll --output-lib libdll2.a --output-exp dll2.exp
$ gcc -mdll -o dll1-nr.dll dll1.exp code1.c
$ gcc -mdll -o dll2-nr.dll dll2.exp code2.c
$ gcc -o main-nr main.c libdll1.a libdll2.a
$ ./main-nr

But since dlltool is called "obsolete", what should be used instead ?

Thanks,
Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux