This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


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

Re: Dlls @n symbols


> > The goal for me is:
> > 1. NOT having mangled names in the exports table
> > 2. having an import library which lets ld lookup mangled names
> > 3. having finally an application that imports UNmangled names
> >
> > I succeeded only with step 1.
>
>I don't understand (2) and (3). Could you please elaborate, with examples,
>and then we can discuss if they're feasible or not. If these steps are
>not possible with MSVC or Borland, chances are it won't be easily doable
>or practical in GNU tools either.

Here is a full not working example. Perhaps I use dlltool the wrong way. (2) 
is: test.a seems not having symbols for Foo@0 and Bar@24. If I uncomment 
mangled names in the DEF file, they get defined, but appear also in the 
DLL's exports table. (3) is: if I define the mangled names in the DEF, then 
ld creates the application, but its imports table contains mangled names, 
not clean names, so having a clean exports table in the DLL is useless!

--- calltest.c ---
#include <windows.h>
#include <stdio.h>

VOID
STDCALL
Foo(VOID);

LONG
STDCALL
Bar( int arg0, int arg1, int arg2, int arg3, int arg4, int arg5 );

main()
{
	Foo();
	printf("Bar = %d\n",Bar(1,2,3,4,5,6));
	return 0;
}
/* EOF */
--- dllmain.c ---
#include <windows.h>
INT
__stdcall
DllMain(
	PVOID	hinstDll,
	ULONG	dwReason,
	PVOID	reserved
	)
{
	switch (dwReason)
	{
		case DLL_PROCESS_ATTACH:
			break;
		case DLL_THREAD_ATTACH:
			break;
		case DLL_THREAD_DETACH:
			break;
		case DLL_PROCESS_DETACH:
			break;
	}
	return(1);
}
/* EOF */
--- dlltest.c ---
#include <windows.h>
#include <stdio.h>

VOID
STDCALL
Foo(VOID)
{
	printf("Hi, I am Foo()!\n");
}

LONG
STDCALL
Bar( int arg0, int arg1, int arg2, int arg3, int arg4, int arg5 )
{
	return
		(LONG) arg0
		+ (LONG) arg1
		+ (LONG) arg2
		+ (LONG) arg3
		+ (LONG) arg4
		+ (LONG) arg5;
}

/* EOF */
--- makefile ---
# mingw32
CC=gcc.exe -Wall -Wstrict-prototypes -O2
LD=ld.exe
NM=nm.exe
RM=erase
DLLTOOL=dlltool.exe
TARGET=test
DLLTARGET=$(TARGET).dll
DLLMAIN=dllmain.o
DLL_OBJECTS= $(DDLMAIN) dll$(TARGET).o

all: $(DLLTARGET) call$(TARGET).exe

clean:
	$(RM) *.o *.a *.sym *.tmp *.dll *.exe

$(TARGET).a: $(DLL_OBJECTS)
	$(AR) csr $(TARGET).a $(DLL_OBJECTS)

$(TARGET).dll: $(DLLMAIN) $(DLL_OBJECTS) $(TARGET).def
	$(LD) -r $(DLL_OBJECTS) -o $(TARGET).o
	$(DLLTOOL) \
		--dllname $(TARGET).dll \
		--def $(TARGET).def \
		--output-lib $(TARGET).a \
		--add-stdcall-alias \
		--kill-at
	$(CC) \
		-specs=$(TARGET)_specs \
		-mdll \
		-o junk.tmp \
		-Wl,--base-file,base.tmp \
		$(TARGET).o \
		-Wl,-lcrtdll
	- $(RM) junk.tmp
	$(DLLTOOL) \
		--dllname $(TARGET).dll \
		--base-file base.tmp \
		--output-exp temp.exp \
		--def $(TARGET).def \
		--add-stdcall-alias \
		--kill-at
	- $(RM) base.tmp
	$(CC) \
		-specs=$(TARGET)_specs \
		-mdll \
		-o $(TARGET).dll \
		$(TARGET).o \
		-Wl,--image-base,0x70000000 \
		-Wl,--file-alignment,0x1000 \
		-Wl,--section-alignment,0x1000 \
		-Wl,temp.exp \
		-Wl,-lcrtdll
	- $(RM) temp.exp
	$(NM) --numeric-sort $(TARGET).dll > $(TARGET).sym

call$(TARGET).exe: call$(TARGET).o dllmain.o
	$(CC) call$(TARGET).o dllmain.o \
		-o call$(TARGET).exe \
		-Wl,$(TARGET).a \
		-Wl,-lcrtdll
	$(NM) --numeric-sort call$(TARGET).exe > call$(TARGET).sym

# EOF
--- test.def ---
LIBRARY test
EXPORTS
;	Bar@24
	Bar			= Bar@24
;	Foo@0
	Foo			= Foo@0
;EOF
--- test_specs ---
*asm:


*asm_final:


*cpp:
-remap %(cpp_cpu) %{posix:-D_POSIX_SOURCE}

*cc1:
%(cc1_spec)

*cc1plus:


*endfile:


*link:
%{mwindows:--subsystem windows} %{mdll:--dll -e _DllMainCRTStartup@12}

*lib:


*libgcc:
-lgcc

*startfile:


*switches_need_spaces:


*signed_char:
%{funsigned-char:-D__CHAR_UNSIGNED__}

*predefines:
-Di386 -D_WIN32 -DWIN32 -D__WIN32__   -D__MINGW32__ -DWINNT  -D_X86_=1 
-D__STDC__=1  -D__stdcall=__attribute__((__stdcall__))   
_D_stdcall=__attribute__((__stdcall__))   
-D__cdecl=__attribute__((__cdecl__))   -D__declspec(x)=__attribute__((x))   
-Asystem(winnt) -Acpu(i386) -Amachine(i386)

*cross_compile:
1

*version:
egcs-2.91.57

*multilib:
. ;

*multilib_defaults:


*multilib_extra:


*multilib_matches:


*linker:
collect2

*cpp_486:
%{!ansi:-Di486} -D__i486 -D__i486__

*cpp_586:
%{!ansi:-Di586 -Dpentium} 	-D__i586 -D__i586__ -D__pentium -D__pentium__

*cpp_686:
%{!ansi:-Di686 -Dpentiumpro} 	-D__i686 -D__i686__ -D__pentiumpro 
-D__pentiumpro__

*cpp_cpu_default:
%(cpp_586)

*cpp_cpu:
-Acpu(i386) -Amachine(i386) %{!ansi:-Di386} -D__i386 -D__i386__ 
%{mcpu=i486:%(cpp_486)} %{m486:%(cpp_486)} %{mpentium:%(cpp_586)} 
%{mcpu=pentium:%(cpp_586)} %{mpentiumpro:%(cpp_686)} 
%{mcpu=pentiumpro:%(cpp_686)} 
%{!mcpu*:%{!m486:%{!mpentium*:%(cpp_cpu_default)}}}

*cc1_cpu:
%{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{mno-486:-mcpu=i386 -march=i386} 
%{m486:-mcpu=i486 -march=i486} %{mno-386:-mcpu=i486 -march=i486} 
%{mno-pentium:-mcpu=i486 -march=i486} %{mpentium:-mcpu=pentium} 
%{mno-pentiumpro:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}
--- EOF ---


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


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