Strange "Undefined reference" name mangling ? HELP!!

DOS specific questions.
Cpcdos
Posts: 192
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Strange "Undefined reference" name mangling ? HELP!!

Postby Cpcdos » Jul 24, 2016 10:52

Hi,

This question is for is for experts

I'll explain my 5 procedures, and after my question.

1) With my friend, we have coded an PE loader in C++ with GPP, and we can use this with FreeBasic for dos this work! :)
And we want to execute simple Win32 console application, so I've used HX-Extender library by Japthet for complet all win32 missing functions.
So we use Japthet DPMILD32, (HX-Extender) library. Source : https://sourceforge.net/projects/hx-dos/files/

2) I've extracted the .LIB file content for getting lot of .OBJ files. So with this .OBJ files, I've include in a new archive library .A
And i've include this .A library file in my C++/FreeBasic program compilation.Bla bla bla bla..... Brief, So it's always good!

3) When I want to use a Win32 function (EnterCriticalSection function) natively on my C++ code for test, and compile this, I've this :
Image

4) So, in my C++ code I tested to declare :

Code: Select all

void WINAPI  EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection);

Same problem

Code: Select all

extern void WINAPI  EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection);

Same problem also...

5) When I read the symbol on my "MemoryModule.OBJ", with CFF Explorer software :

I've my Win32 function that I want use here, so OK!
Image

But my (i think) my declaration symbol generated is not the same...
Image

My question:
How to resolve this problem for have exactly "EnterCriticalSection" and NOT "__Z20EnterCriticalSectionP21_RTL_CRITICAL_SECTION" ?? This caused by the C++ name mangling ?

ps: "MemoryModule.OBJ" is compiled with GPP/DJGPP

Regards
Sébastien FAVIER
Last edited by Cpcdos on Jul 24, 2016 11:37, edited 1 time in total.
Cpcdos
Posts: 192
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: Strange "Undefined reference" name mangling ? HELP!!

Postby Cpcdos » Jul 24, 2016 11:31

Base problem was resolved with

Code: Select all

extern "C" { }
or

Code: Select all

nm.exe -C MemoryModule.OBJ

I've always the same problem, "undefined reference"...

SO, I've another question :
For my "EnterCriticalSection" function, I've found that in HX-Exterder library by Japthet, the name is "_EnterCriticalSection@4" in library... WHY ??

@4 for 4 bytes ? integer argument ? .. but how to declare/use this ? :o

Regards
Sébastien FAVIER

Excuse me for my bad english level
dkl
Site Admin
Posts: 3166
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Strange "Undefined reference" name mangling ? HELP!!

Postby dkl » Jul 24, 2016 12:36

The _ underscore prefix is common for symbols on Windows. I think it's used to avoid name/keyword conflicts in Intel assembly syntax (e.g. eax register vs. eax() function).

The @N suffix is the sum of parameter sizes, and it's added automatically by the compiler for stdcall functions, see for example __stdcall on MSDN (name decoration). Encoding the parameter size adds some safety when linking, because it prevents linking foo() (_foo@0) against foo(byval as ulong) (_foo@4). With cdecl the linker can't detect the problem because both are named _foo. The @N helps, but it's not as good as full C++ name mangling which encodes exact parameter types.
Cpcdos
Posts: 192
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: Strange "Undefined reference" name mangling ? HELP!!

Postby Cpcdos » Aug 04, 2016 18:07

Thank you for your help, this no work correctly.. so we have found an alternative with "overrides" in c++

Thank you guy :)

Return to “DOS”

Who is online

Users browsing this forum: No registered users and 1 guest