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>
Created attachment 4379 [details] Amend linker documentation
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
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.
Nick, Your last patch looks reasonable. As user seems not to reply, I would vote for go for it. Thanks, Kai
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
It seems it should say "PE- and BeOS-based systems" though.
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.
.