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


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: Add a weak definition of mep_di to MeP's libgloss


Hi,

this is the second recent post which makes questionable use of "weak",
at least to my mind.

Traditional Unix static linkers link the object and library (archive)
files listed in the command line strictly from left to right.  GNU ld
follows this tradition.  On encountering an archive, the members of the
archive are scanned, again from left to right, and all members that
resolve a symbol are extracted and included in the link output.
Extracting members of the archive might create new unresolved symbols.
The process of scanning the archive is repeated until no new members can
be extracted.  However, once processed, this archive is not revisited,
even if later object files have unresolved symbols that could be
resolved by this library (unless the library is mentioned a second time
on the command line, to the right of these later object files).

As an aside, these semantics of processing of archive members from left
to right is not modified by the existence of the archive's symbol table.
This is why GNU ar still has the "b" (before), "a" (after), "i"
(insert), and "m" (move) keys.  The symbol table is merely an
optimization.

If you wish to override the definition of a symbol, add an object
(possibly in an archive, if you are sure that an unresolved reference to
this symbol exists before the library is processed) defining that symbol
before the library containing the overridden definition.

Object files are included in a link integrally (with the exception of
segment garbage collection, which requires extra effort from both the
implementer of the module and from the invoker of the linker).  That is,
either all of the definitions are included or none of them are.  Thus,
adding weak definitions to existing members (object files) will bloat
the linker's output (perhaps only slightly, as in the case below) when
that member is extracted for other reasons.  

The correct solution is to add a separate archive member for each
"fall-back" definition.  These definitions do not profit from having the
"weak" attribute.

Regards,

Konrad Schwarz


> -----Original Message-----
> From: newlib-owner@sourceware.org 
> [mailto:newlib-owner@sourceware.org] On Behalf Of Nick Clifton
> Sent: Wednesday, February 04, 2009 09:00
> To: dj@redhat.com
> Cc: newlib@sourceware.org
> Subject: RFA: Add a weak definition of mep_di to MeP's libgloss
> 
> Hi DJ,
> 
>   Whilst trying to compile some of the gcc testsuite for the MeP
>   target I ran into a problem with libgloss.  Specifically the
>   _handler_RESET function in libgloss/mep/h_reset.c references a
>   function called "mep_di" which does not seem to be defined
>   anywhere.  My guess was that this is a board specific function to
>   disable interrupts, but since I was only using the simulator I was
>   not really concerned with interrupt handling.
> 
>   So I created the patch below to add a weak, empty definition of the
>   mep_di function.  With this patch applied I was able to compile and
>   link the gcc testsuite testcases.
> 
>   What do you think.  Is the patch suitable for application to the
>   libgloss sources or should there be some other way of providing the
>   mep_di function ?
> 
> Cheers
>   Nick
> 
> libgloss/ChangeLog
> 2009-02-04  Nick Clifton  <nickc@redhat.com>
> 
> 	* mep/h_reset.c: Add a weak definition of mep_di.
> 
> Index: libgloss/mep/h_reset.c
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mep/h_reset.c,v
> retrieving revision 1.1
> diff -c -3 -p -r1.1 h_reset.c
> *** libgloss/mep/h_reset.c	8 Feb 2007 21:22:05 -0000	1.1
> --- libgloss/mep/h_reset.c	4 Feb 2009 07:58:53 -0000
> ***************
> *** 13,18 ****
> --- 13,22 ----
>    * the express permission of Red Hat, Inc.
>    */
>   
> + #pragma weak mep_di
> + void mep_di (void) __attribute__((section(".hwinit")));
> + void mep_di (void) { }
> +   
>   #pragma weak _handler_RESET
>   
>   void _handler_RESET(void) __attribute__((section(".hwinit")));
> 


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