Bug 10865 - The entry point is mainCRTStartup
Summary: The entry point is mainCRTStartup
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.19
: P2 minor
Target Milestone: ---
Assignee: unassigned
URL: https://sourceware.org/binutils/docs/...
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-29 12:43 UTC by Christopher Yeleighton
Modified: 2022-07-28 08:25 UTC (History)
3 users (show)

See Also:
Host: mingw32
Target: mingw32
Build: mingw32
Last reconfirmed:


Attachments
Amend linker documentation (422 bytes, patch)
2009-11-10 15:58 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Yeleighton 2009-10-29 12:43:54 UTC
The documentation of ld [1] says that the default ENTRY point is start.  This 
is not universally true; the default ENTRY point in MinGW is mainCRTStartup.

Steps to reproduce:

gcc -nostartfiles the following source code without crt2.o:

#include <stdio.h>
#include <stdlib.h>
int begin() { puts ("begin"); return 0; }
int start() { puts ("start"); return 0; }
int mainCRTStartup() { puts ("CRT"); return 0; }

The program prints "CRT", not "start".

In order to solve the problem, modify the documentation to say that the 
initial symbol is implementation-dependent.

[1] <URL:http://sourceware.org/binutils/docs/ld/Entry-Point.html#Entry-Point>
Comment 1 Nick Clifton 2009-11-10 15:58:37 UTC
Created attachment 4379 [details]
Amend linker documentation
Comment 2 Nick Clifton 2009-11-10 16:00:08 UTC
Hi Christopher,

The uploaded patch changes the documentation to read:

   There are several ways to set the entry point.  The linker will 
   set the entry point by trying each of the following methods in 
   order, and stopping when one of them succeeds:

   * the `-e' ENTRY command-line option;

   * the `ENTRY(SYMBOL)' command in a linker script;

   * the value of a target specific symbol, if it is defined;  For many
     targets this is `start', but PE and BeOS based systems for example
     check a list of possible entry symbols, matching the first one
     found.

   * the address of the first byte of the `.text' section, if present;

   * The address `0'.

Does this seem OK to you ?

Cheers
  Nick
Comment 3 Christopher Yeleighton 2009-11-10 16:14:36 UTC
Subject: RE:  The entry point is mainCRTStartup

That patch is right, thanks, except that that PE is rather surprising
because is not used as a target symbol within gcc docs.  I cannot tell about
BeOS because I never got in touch with one.  I am going to report a bug
against MinGW as soon as the ld documentation is fixed to specify the
startup symbols supported.  That information should probably go to the
platform-specific section of ld also, except that I hope it is subject to
change because the implementation should be augmented to support
wide-character applications properly (or at least as properly as MSVCRT
allows, which means UTF-16LE and BMP only).
Cheers,
Chris

-----Original Message-----
From: nickc at redhat dot com [mailto:sourceware-bugzilla@sourceware.org] 
Sent: Tuesday, November 10, 2009 5:00 PM
To: giecrilj@stegny.2a.pl
Subject: [Bug ld/10865] The entry point is mainCRTStartup


------- Additional Comments From nickc at redhat dot com  2009-11-10 16:00
-------
Hi Christopher,

The uploaded patch changes the documentation to read:

   There are several ways to set the entry point.  The linker will 
   set the entry point by trying each of the following methods in 
   order, and stopping when one of them succeeds:

   * the `-e' ENTRY command-line option;

   * the `ENTRY(SYMBOL)' command in a linker script;

   * the value of a target specific symbol, if it is defined;  For many
     targets this is `start', but PE and BeOS based systems for example
     check a list of possible entry symbols, matching the first one
     found.

   * the address of the first byte of the `.text' section, if present;

   * The address `0'.

Does this seem OK to you ?

Cheers
  Nick

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING


http://sourceware.org/bugzilla/show_bug.cgi?id=10865

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.

Comment 4 Kai Tietz 2012-02-10 17:55:25 UTC
Nick,

Your last patch looks reasonable. As user seems not to reply, I would vote for go for it.

Thanks,
Kai
Comment 5 Nick Clifton 2012-02-11 18:43:30 UTC
Hi Kai,

  Actually I have already checked that patch in.  Back in 2009....

  I did not follow up on Christopher's suggestion that their ought to be a PE specific section in the linker documentation enumerating the start symbols that are tried however.  Nor did I look at adding wide character support for start symbol names.  Perhaps you would care to look at these issues ?

Cheers
  Nick
Comment 6 Christopher Yeleighton 2018-11-12 13:33:03 UTC
It seems it should say "PE- and BeOS-based systems" though.
Comment 7 Sourceware Commits 2018-11-12 15:13:30 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8a758655b3ee39bed245a6ba2fc9f81f77813443

commit 8a758655b3ee39bed245a6ba2fc9f81f77813443
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Nov 12 15:12:15 2018 +0000

    Update documentation describing how the linker chooses a start address.
    
    	PR 10865
    	* ld.texi (Entry Point): Make it clear that the text refers to
    	PE-based systems rather than just a PE system.
Comment 8 Alan Modra 2022-07-28 08:25:09 UTC
.