Hello, I write some simple program with option "ignore standart places " (no crt).
In Linker section I add entry_point as ep. In code I write
int ep(void)
but this fails. Also fails , if write in linker section _ep, _ep@4 and other.
But if I write in code
int ep()
it works , but I have warnings "old style"
Hi bitcoin,
The entry point should be ep as you mentioned.
Attached is a quick example for you.
Thank you Vortex, your sample works good..save it as template )
In Pelle's C help is a topic Program startup: the true story
linker knows these:
mainCRTStartup
wmainCRTStartup
WinMainCRTStartup
wWinMainCRTStartup
DllMainCRTStartup
Hi bitcoin,
You are welcome. Here is how to build the project with a batch file.
After running \PellesC\Bin\povars32.bat :
pocc.exe /Ze /Zx -Tx86-coff CustEntryPoint.c
pocc.exe /Ze /Zx -Tx86-coff StdOut.c
pocc.exe /Ze /Zx -Tx86-coff StrLen.c
polink /SUBSYSTEM:CONSOLE /ENTRY:ep /LIBPATH:\Pellesc\Lib\Win CustEntryPoint.obj StdOut.obj StrLen.obj kernel32.lib user32.lib
For lazy programmer, to sourcecode:
#pragma comment(linker, "/SUBSYSTEM:CONSOLE /ENTRY:ep")
Quote from: bitcoin on September 02, 2021, 08:45:03 PM
Hello, I write some simple program with option "ignore standart places " (no crt).
In Linker section I add entry_point as ep. In code I write
int ep(void)
but this fails. Also fails , if write in linker section _ep, _ep@4 and other.
But if I write in code
int ep()
it works , but I have warnings "old style"
Probably you compiled your code with MS extensions on and __stdcall as default.
The entry point name can be the base name or the underscore decorated if compiling as __cdecl your function, that automatically happen when you declare it as 'int ep()'.
So you have 2 options declare your function as:
int __cdecl ep(void)
and the entry point as 'ep' or '_ep', or if you compile the function as __stdcall use the entry point '_ep@0' with full decorations.
Yes, if change to _cdecl, all works also.
Thanks all for the answers!
A NoCrt library is also usually needed, as compiler needs support library, like SEH in x86 mode.
#include <excpt.h>
void __stdcall ExitProcess(int);
int __cdecl main(void);
void __cdecl mainCRTStartup(void) { ExitProcess(main()); }
int __cdecl main(void)
{
__try
{
char *p = 0;
*p = 0; /* force a null-pointer exception */
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
//printf("An exception occurred - the code is %x\n", exception_code());
}
return 0;
}
map-file 0001:00000078 __except_handler3 00401078 f crt:seh2.obj
0001:00000150 __seh_longjmp_unwind@4 00401150 f crt:seh2.obj
0001:00000170 __global_unwind2 00401170 f crt:seh1.obj
0001:00000190 __unwind_handler 00401190 f crt:seh1.obj
0001:000001c0 __local_unwind2 004011c0 f crt:seh1.obj
0001:0000021f __NLG_Return2 0040121f crt:seh1.obj
0001:00000230 __abnormal_termination 00401230 f crt:seh1.obj
0001:00000260 __NLG_Notify1 00401260 crt:seh1.obj
0001:00000269 __NLG_Notify 00401269 crt:seh1.obj
0001:0000027d __NLG_Dispatch 0040127d crt:seh1.obj
0002:00000010 __load_config_used 00402010 crt:_loadcfg.obj
0003:00000068 __NLG_Destination 00403068 crt:seh1.obj
https://forum.pellesc.de/index.php?topic=7264.msg27613#msg27613