Bug 5533 - ld -e (--entry) is too quiet on bad symbol names
Summary: ld -e (--entry) is too quiet on bad symbol names
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-02 15:43 UTC by Daniel Jacobowitz
Modified: 2008-01-10 14:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2008-01-09 12:59:06


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Jacobowitz 2008-01-02 15:43:00 UTC
-e entry
       --entry=entry
           Use entry as the explicit symbol for beginning execution of your
program, rather than  the
           default  entry  point.   If  there  is no symbol named entry, the
linker will try to parse
           entry as a number, and use that as the entry address (the number will
 be  interpreted  in
           base 10; you may use a leading 0x for base 16, or a leading 0 for
base 8).

If the option is specified, and there is no symbol with the given name, and it
is not a hex value, ld should issue an error.  Instead it defaults to the first
instruction without any message.  If you forget ".globl" on _start, for
instance, the program will start somewhere unexpected.
Comment 1 Nick Clifton 2008-01-09 10:24:35 UTC
Hi Daniel,

  Do you have a test case that reproduces this problem ?

  I tried the following:

  % cat fred.s
    .global foo
    .global bar
  foo:
    nop
  bar:
    nop

  % as fred.s -o fred.o
  % ld -e does-not-exist fred.o
  ld: warning: cannot find entry symbol does-not-exist; defaulting to
0000000000008000

ie a warning message *was* produced.

This was with an arm-eabi toolchain built from today's sources on a 64-bit host,
so maybe one of these factors is connected with the generation of the warning
message.

Cheers
  Nick
Comment 2 Daniel Jacobowitz 2008-01-09 12:59:06 UTC
Oops, the message is only suppressed for -shared.  I was building an executable
shared library.

Does entry_symbol.name get set from both the default linker script and the
command line?  Not warning with -shared and ENTRY is probably appropriate, since
all the existing -shared linker scripts have an ENTRY and most shared libraries
are executable.
Comment 3 Nick Clifton 2008-01-09 15:03:44 UTC
Hi Daniel,

> Does entry_symbol.name get set from both the default linker script and the
> command line?

Yes.  See ld/ldlang.c:lang_add_entry().  It has a parameter which tells it
whether the symbol is being set from a linker script (default or otherwise) or
from the command line.  The command line takes precedence.

> Not warning with -shared and ENTRY is probably appropriate, since
> all the existing -shared linker scripts have an ENTRY and most shared 
> libraries are executable.

Agreed.

Cheers
  Nick
Comment 4 Daniel Jacobowitz 2008-01-09 16:25:29 UTC
Sorry, that's not what I meant.  -shared, ENTRY, and not found is valid not to
warn.  -shared, -e, and not found is different.

What do you think of this?

   if (link_info.relocatable || link_info.shared)
-    warn = FALSE;
+    warn = entry_from_cmdline;
   else
Comment 5 Nick Clifton 2008-01-10 14:29:39 UTC
Hi Daniel,

  Sorry for being so dense!  Yes your patch will work and I have checked it in
along with this ChangeLog entry.  OK to close this PR now ? :-)

Cheers
  Nick

ld/ChangeLog
2008-01-10  Daniel Jacobowitz  <drow@sources.redhat.com>

	PR ld/5533
	* ldlang.c (lang_end): Issue a warning for a missing start symbol
	of a shared library if the symbol was specified on the command
	line.
Comment 6 Daniel Jacobowitz 2008-01-10 14:40:55 UTC
Thanks!