NO

Author Topic: gcc directive section .drectve  (Read 4323 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
gcc directive section .drectve
« on: December 07, 2016, 12:19:01 PM »
Finally gcc works with polink v.8 ;)
Code: [Select]
#ifdef __GNUC__
// IMAGE_SCN_LNK_INFO | IMAGE_SCN_LNK_REMOVE
void comment_linker(void) {
__asm__(".section .drectve, \"ney\"\n"
"\t.string \"-defaultlib:msvcrt.lib -subsystem:console\"\n"
"\t.section .text");
}
void __main(void) {}
#else
#pragma comment(lib, "msvcrt.lib")
#pragma comment(linker,"/subsystem:console")
#endif
void __cdecl mainCRTStartup(void)
{
int __cdecl main(int argc, char **argv);
int __cdecl __getmainargs(int*, char***, char***, int, void*);
void __cdecl exit(int status);

int    argc;
char** argv;
char** env;
int    sinfo = 0;

__getmainargs(&argc,&argv,&env,0,&sinfo);
exit(main(argc,argv));
}
fake ld.exe using polink.exe
Code: [Select]
#ifdef __GNUC__
// IMAGE_SCN_LNK_INFO | IMAGE_SCN_LNK_REMOVE
void comment_linker(void) {
__asm__(".section .drectve, \"ney\"\n"
"\t.string \"-defaultlib:msvcrt.lib -subsystem:console\"\n"
"\t.section .text");
}
void __main(void) {}
#else
#pragma comment(lib, "msvcrt.lib")
#pragma comment(linker,"/subsystem:console")
#endif

//void __main(void) {}
void __cdecl mainCRTStartup(void)
{
int __cdecl main(int argc, char **argv);
int __cdecl __getmainargs(int*, char***, char***, int, void*);
void __cdecl exit(int status);

int    argc;
char** argv;
char** env;
int    sinfo = 0;

__getmainargs(&argc,&argv,&env,0,&sinfo);
main(argc,argv);
exit(0);
}

int printf(const char * format, ...);
int strlen(const char *string);
char * strcpy(char * restrict dst, const char * restrict src);
char * strcat(char * restrict dst, const char * restrict src);
int strcmp(const char *string1, const char *string2);
int system(const char *string);

int __cdecl main(int argc, char **argv)
{
char scmd[1024]; // commandline
int ipar = 0; // parameter status
int i;

strcpy(scmd, argv[0]);
i = strlen(scmd) - 1;
while (scmd[i] && scmd[i] != '/' && scmd[i] != '\\')
scmd[i--] = 0;
strcat(scmd, "polink.exe ");
/* for (int i=0; i<argc; i++) {
printf("%s\n", argv[i]);
}
printf("\n");*/
for (int i=0; i<argc; i++) {
if (!ipar && !strcmp(argv[i], "crtbegin.o")) {
ipar = 1;
i++;
}
if (!strcmp(argv[i], "crtend.o")) {
//ipar = 3;
break;
}
if (!ipar && argv[i][0] == '-') { // parameters that are interest
if (argv[i][1] == 'o') {
strcat(scmd, " -out:");
if (scmd, argv[i][2])
strcat(scmd, &argv[i][2]);
else {
i++;
strcat(scmd, argv[i]);
}
strcat(scmd, " ");
}
}
if (ipar == 1 && argv[i][0] != '-') { // parameters that are interest
while (argv[i][0] != '-') {
//printf("%s\n", argv[i]);
strcat(scmd, argv[i]);
strcat(scmd, " ");
if (i<argc) i++;
else break;
}
}

if (ipar == 1 && argv[i][0] == '-') { // parameters that are interest
if (argv[i][1] == 'l') {
if (!strcmp(argv[i], "-lmingw32")) break;
strcat(scmd, " ");
strcat(scmd, &argv[i][2]);
strcat(scmd, ".lib");
}
if (argv[i][1] == 'L') {
strcat(scmd, " -libpath:");
strcat(scmd, &argv[i][2]);
strcat(scmd, " ");
}
}
//printf("%s\n", argv[i]);
}
//printf("\n%s\n", scmd);
system(scmd);
return 0;
}
put ld.exe and polink.exe to folder libexec\gcc
« Last Edit: December 08, 2016, 11:58:06 PM by TimoVJL »
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: directive section .drectve
« Reply #1 on: December 07, 2016, 07:23:32 PM »
Hi TimoVJL,

Nice work. Here is a GAS ( GNU assembler ) example linked with Polink.
Code it... That's all...