public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] __CTORS__
@ 2000-12-07  2:38 Rafael Rodríguez Velilla
  2000-12-07  4:12 ` Jesper Skov
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael Rodríguez Velilla @ 2000-12-07  2:38 UTC (permalink / raw)
  To: ecos

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]

  I'm analyzing the ARM PID initialization of eCos and I have seen that
the routine that calls the constructors (cyg_invoke_constructors) is the
following:

typedef void (*pfunc) (void)
extern pfunc __CTOR_LIST__[];
extern pfunc __CTOR_END__[];

void cyg_invoque_constructors(void)
{
   pfunc *p;
  for (p=&__CTOR_END__[-1];p >= __CTOR_LIST__;p--)
       (*p) ();
}

  I have search what these extern symbols are (__CTOR_LIST__  and
__CTOR_END__). I found it at the linker script arm.ld.
  Can anybody explain me which constructors are referenced at
__CTOR__LIST__ and what does it means when you reference it with
brackets? The symbol at arm.ld is just __CTOR_END__, but at this routine
is called with __CTOR_END__[-1].

   Is there any place where I can read about where gcc and g++ places
each part of the code (with an explanation about every section of the
linker script)?

--
Rafael Rodríguez Velilla        rrv@tid.es
Telefónica I+D          http://www.tid.es
Telf: 34 - 1 - 91 337 4270



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ECOS] __CTORS__
  2000-12-07  2:38 [ECOS] __CTORS__ Rafael Rodríguez Velilla
@ 2000-12-07  4:12 ` Jesper Skov
  2000-12-07  4:16   ` [ECOS] sa1100 brutus gdb stub Jun Wu
  2000-12-07  4:59   ` [ECOS] __CTORS__ Rafael Rodríguez Velilla
  0 siblings, 2 replies; 7+ messages in thread
From: Jesper Skov @ 2000-12-07  4:12 UTC (permalink / raw)
  To: Rafael Rodríguez Velilla; +Cc: ecos

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]

>>>>> "Rafael" == Rafael Rodríguez Velilla <rrv@tid.es> writes:

Rafael> void cyg_invoque_constructors(void) { pfunc *p; for
Rafael> (p=&__CTOR_END__[-1];p >= __CTOR_LIST__;p--) (*p) (); }

Rafael>   I have search what these extern symbols are (__CTOR_LIST__
Rafael> and __CTOR_END__). I found it at the linker script arm.ld.
Rafael> Can anybody explain me which constructors are referenced at
Rafael> __CTOR__LIST__ and what does it means when you reference it
Rafael> with brackets? The symbol at arm.ld is just __CTOR_END__, but
Rafael> at this routine is called with __CTOR_END__[-1].

The two symbols are the limits of an array of pointers to
constructors. The pointers in this array get sorted (see linker
script) according to their priority. We add the brackets in the C code
to make the compiler treat the symbols as array references -- type
information only exists in the compiler; in the linker a symbols is
just named entity associated with an address.

The code above iterates through the array from the top to the bottom
(end-1 to start), calling each constructor in turn.

Hope that helps.

Jesper

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ECOS] sa1100 brutus gdb stub
  2000-12-07  4:12 ` Jesper Skov
@ 2000-12-07  4:16   ` Jun Wu
  2000-12-07 11:27     ` Jonathan Larmour
  2000-12-07  4:59   ` [ECOS] __CTORS__ Rafael Rodríguez Velilla
  1 sibling, 1 reply; 7+ messages in thread
From: Jun Wu @ 2000-12-07  4:16 UTC (permalink / raw)
  To: ecos-discuss

Hi all,
I'm new to eCos.
I build strongARM SA1100 brutus board gdb stubs, and two files,
gdb_module.bin and gdb_module.img, are generated.
Anybody tell me the relationship between them? and the format of the two
files(offset of program entry in the file)?

Best Regards

Jun






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ECOS] __CTORS__
  2000-12-07  4:12 ` Jesper Skov
  2000-12-07  4:16   ` [ECOS] sa1100 brutus gdb stub Jun Wu
@ 2000-12-07  4:59   ` Rafael Rodríguez Velilla
  2000-12-07  5:09     ` Gary Thomas
  2000-12-07  5:42     ` Jesper Skov
  1 sibling, 2 replies; 7+ messages in thread
From: Rafael Rodríguez Velilla @ 2000-12-07  4:59 UTC (permalink / raw)
  To: ecos

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1730 bytes --]

  I can see it brighter now. I have also found the documentation that
talks about __CTOR_LIST__ at the documentation of the GNUPro Utilities.
now I see that only the global constructors are referenced here. (The
documentation differs a litte from what arm.ld does, it ommits the first
word with the number of entries and the last "0")

  Why do you say that they are sorted according to their priority?
  I have read that you can configure with CDL the priority that
determines when the different actions are taken. How do I tell gcc which
constructor is more prioritary?

  Thank you for your explanation, I'm not used to merging c, c++ and
assembler and the explanation of how the symbols are managed was what I
was lacking.

> The two symbols are the limits of an array of pointers to
> constructors. The pointers in this array get sorted (see linker
> script) according to their priority. We add the brackets in the C code
> to make the compiler treat the symbols as array references -- type
> information only exists in the compiler; in the linker a symbols is
> just named entity associated with an address.
>
> The code above iterates through the array from the top to the bottom
> (end-1 to start), calling each constructor in turn.
>
> Hope that helps.
>
> Jesper

  Of course it helps.


  Let me ask another question...
  While I was looking for where in hell was defined __CTOR_LIST__ I have
searched through lots of source files almost manually (grep __CTOR_LIST__
*). I'm sure that there's a simpler way to find where a symbol comes
from, Can anyone of you tell me if there's such a utility?

--
Rafael Rodríguez Velilla        rrv@tid.es
Telefónica I+D          http://www.tid.es
Telf: 34 - 1 - 91 337 4270



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ECOS] __CTORS__
  2000-12-07  4:59   ` [ECOS] __CTORS__ Rafael Rodríguez Velilla
@ 2000-12-07  5:09     ` Gary Thomas
  2000-12-07  5:42     ` Jesper Skov
  1 sibling, 0 replies; 7+ messages in thread
From: Gary Thomas @ 2000-12-07  5:09 UTC (permalink / raw)
  To: Rafael Rodríguez Velilla; +Cc: ecos

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 675 bytes --]

On 07-Dec-2000 Rafael Rodríguez Velilla wrote:
>   Let me ask another question...
>   While I was looking for where in hell was defined __CTOR_LIST__ I have
> searched through lots of source files almost manually (grep __CTOR_LIST__
> *). I'm sure that there's a simpler way to find where a symbol comes
> from, Can anyone of you tell me if there's such a utility?
> 

Here are some:
  Source Navigator - http://sources.redhat.com/sourcenav/
  Cscope - http://cscope.sourceforge.net/

Note that neither of these would probably help much with this particular
symbol since it's being defined in the linker script.  Both of these 
programs work primarily from C/C++ sources.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ECOS] __CTORS__
  2000-12-07  4:59   ` [ECOS] __CTORS__ Rafael Rodríguez Velilla
  2000-12-07  5:09     ` Gary Thomas
@ 2000-12-07  5:42     ` Jesper Skov
  1 sibling, 0 replies; 7+ messages in thread
From: Jesper Skov @ 2000-12-07  5:42 UTC (permalink / raw)
  To: Rafael Rodríguez Velilla; +Cc: ecos

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1588 bytes --]

>>>>> "Rafael" == Rafael Rodríguez Velilla <rrv@tid.es> writes:

Rafael>   Why do you say that they are sorted according to their
Rafael> priority?  I have read that you can configure with CDL the
Rafael> priority that determines when the different actions are
Rafael> taken. How do I tell gcc which constructor is more prioritary?

There's a compiler attribute for that:

#if defined(__cplusplus) && defined(__GNUC__)
# define CYGBLD_ATTRIB_INIT_PRI( _pri_ ) __attribute__((init_priority(_pri_)))
#else
// FIXME: should maybe just bomb out if this is attempted anywhere else?
// Not sure
# define CYGBLD_ATTRIB_INIT_PRI( _pri_ )
#endif

This is used a few places in the eCos code to control in which order
various constructors get run. Grep for CYGBLD_ATTRIB_INIT_PRI in the
sources.

Rafael>   Let me ask another question...  While I was looking for
Rafael> where in hell was defined __CTOR_LIST__ I have searched
Rafael> through lots of source files almost manually (grep
Rafael> __CTOR_LIST__ *). I'm sure that there's a simpler way to find
Rafael> where a symbol comes from, Can anyone of you tell me if
Rafael> there's such a utility?

Are you kidding? Grep is the best thing since sliced bread! :)

This is what I use (it's in a file called grepf):

find . -name "*.[chSs]" -or -name "*.cxx" -or -name "*.java" \
     -or -name "*.cpp" -or -name "*.ht" -or -name "*.hxx" \
     -or -name "*.in[cl]" -or -name "*.ld" -or -name "*.cdl" \
     -or -name "*.ect" -or -name "*.db" | sed 's/.*SCCS.*//;' |\
     xargs grep -n "$@"


It's not pretty, but it works very well.

Jesper



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ECOS] sa1100 brutus gdb stub
  2000-12-07  4:16   ` [ECOS] sa1100 brutus gdb stub Jun Wu
@ 2000-12-07 11:27     ` Jonathan Larmour
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Larmour @ 2000-12-07 11:27 UTC (permalink / raw)
  To: Jun Wu; +Cc: ecos-discuss

Jun Wu wrote:
> 
> Hi all,
> I'm new to eCos.
> I build strongARM SA1100 brutus board gdb stubs, and two files,
> gdb_module.bin and gdb_module.img, are generated.
> Anybody tell me the relationship between them? and the format of the two
> files(offset of program entry in the file)?

The first is a binary format file suitable for programming into a ROM or
FLASH. The latter is an ELF format file which is what was produced by the
compiler, and may be used to convert into other formats (including binary,
but also srec etc.) as required.

Jifl
-- 
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS  Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow."  ||  These opinions are all my own fault

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2000-12-07 11:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-07  2:38 [ECOS] __CTORS__ Rafael Rodríguez Velilla
2000-12-07  4:12 ` Jesper Skov
2000-12-07  4:16   ` [ECOS] sa1100 brutus gdb stub Jun Wu
2000-12-07 11:27     ` Jonathan Larmour
2000-12-07  4:59   ` [ECOS] __CTORS__ Rafael Rodríguez Velilla
2000-12-07  5:09     ` Gary Thomas
2000-12-07  5:42     ` Jesper Skov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).