This is the mail archive of the crossgcc@sourceware.org mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Undetected duplicate symbols


On Tue, 7 Feb 2006, Khem Raj wrote:

Do you have your own linker script file ? or do you use default one. I think you need to have your own for the system
either way you can remove the symbol for linker script and see if that works. Would be nice if you could make a short example to exhibit the problem.

Sure, see below.


Writing this example I found the issue not only happens with my MIPS
toolchain, but also with my host gcc. Most convincing is the disassembly; it
clearly shows that the _start which I defined as entry point is has been
lost. Maybe it's a "feature" that linker script variables override
application variables, but don't think I like this feature then...

  sh# gcc -c -o duplicate.o duplicate.c
  sh# ld -o duplicate -T duplicate-ld duplicate.o
  sh# nm duplicate
  00000000 T dummy
  00000000 T _start
  mag@mag:~/work> nm duplicate.o
  00000000 T dummy
  00000025 T _start
  mag@mag:~/work> objdump -d duplicate

duplicate: file format elf32-i386

Disassembly of section .text:

  00000000 <_start>:
     0:   55                      push   %ebp
     1:   89 e5                   mov    %esp,%ebp
     3:   83 ec 04                sub    $0x4,%esp
     6:   c7 45 fc 00 00 00 00    movl   $0x0,0xfffffffc(%ebp)
     d:   8b 45 fc                mov    0xfffffffc(%ebp),%eax
    10:   83 f8 63                cmp    $0x63,%eax
    13:   7e 02                   jle    17 <_start+0x17>
    15:   eb 09                   jmp    20 <_start+0x20>
    17:   8b 45 fc                mov    0xfffffffc(%ebp),%eax
    1a:   40                      inc    %eax
    1b:   89 45 fc                mov    %eax,0xfffffffc(%ebp)
    1e:   eb ed                   jmp    d <_start+0xd>
    20:   8b 45 fc                mov    0xfffffffc(%ebp),%eax
    23:   c9                      leave
    24:   c3                      ret
    25:   55                      push   %ebp
    26:   89 e5                   mov    %esp,%ebp
    28:   83 ec 08                sub    $0x8,%esp
    2b:   c7 45 fc 00 00 0c bf    movl   $0xbf0c0000,0xfffffffc(%ebp)
    32:   e8 c9 ff ff ff          call   0 <_start>
    37:   89 c2                   mov    %eax,%edx
    39:   8b 45 fc                mov    0xfffffffc(%ebp),%eax
    3c:   89 10                   mov    %edx,(%eax)
    3e:   c9                      leave
    3f:   c3                      ret



Sampel application "duplicate.c":
  extern int dummy(void)
  {
      volatile int i;

/* create some .text data to move _start away from the beginning */

      for(i = 0; i < 100; i++)
          ;

      return i;
  }

  extern void _start(void)
  {
      volatile int *p = (volatile int*)0xbf0c0000;

      *p = dummy();
  }

Linker script "duplicate-ld":
  SECTIONS
  {
      .text 0x00000000:
      {
          _start = . ;
          *(.text)
      }
  }

Marius

--
Marius Groeger <mgroeger@sysgo.com>
SYSGO AG                      Embedded and Real-Time Software
Voice: +49 6136 9948 0                  FAX: +49 6136 9948 10
www.sysgo.com | www.elinos.com | www.osek.de | www.pikeos.com


------ Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/ Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]