Ticket #3042 (closed bug: worksforme)

Opened 4 years ago

Last modified 4 years ago

rts defines "real_main" which can clash with user C code

Reported by: duncan Owned by:
Priority: normal Milestone:
Component: Runtime System Version: 6.10.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I was just about to file a bug about ghc -no-hs-main not working but it turns out it is just because I had a real_main C function in my .c file. This ends up clashing with the C function of the same name from the rts package. This means that when linking we pull in the wrong one and the rts one needs __stginit_ZCMain and ZCMain_main_closure which is what the linker error message reports (which is rather confusing).

Suggestion: rename the rts real_main to something less likely to clash with user code.

Change History

Changed 4 years ago by simonmar

  • difficulty set to Unknown

real_main is declared to be static - I don't understand how it could clash?

Changed 4 years ago by simonmar

  • status changed from new to closed
  • resolution set to worksforme

Indeed I tried a little example, and didn't see any problems:

#include <stdlib.h>
#include <stdio.h>

void real_main(void)
{
    exit(42);
}

void main(int argc, char *argv[])
{
    printf("main\n");
    real_main();
}
> ./a.out
main
[3]    25611 exit 42    ./a.out
Note: See TracTickets for help on using tickets.