This is sources Bugzilla
Bugzilla Version 2.17.5
Bugzilla Bug 1038
  resolution of weak symbol not left for the linker if value is already known Last modified: 2009-10-14 11:48:01
     Query page      Enter new bug
Bug#: 1038   Hardware:   Reporter: Joerg Wunsch <j@uriah.heep.sax.de>
Host: Target: Build:
Product:     Add CC:
Component:   Version:   CC:
Remove selected CCs
Status: NEW   Priority:  
Resolution:   Severity:  
Assigned To: unassigned@sources.redhat.com   Target Milestone:  
Summary:
Keywords:

Attachment Description Type Created Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 1038 depends on: Show dependency tree
Show dependency graph
Bug 1038 blocks:

Additional Comments:


Leave as NEW 
Mark bug as waiting for feedback
Mark bug as suspended
Accept bug (change status to ASSIGNED)
Resolve bug, changing resolution to
Resolve bug, mark it as duplicate of bug #
Reassign bug to
Reassign bug to owner of selected component

View Bug Activity   |   Format For Printing


Description:   Last confirmed: 0000-00-00 00:00 Opened: 2005-06-28 22:02
avr-libc's C run-time startup code uses something like the following to
initialize the stack:

        .weak   __stack
        .set    __stack, RAMEND
...
        ldi     r28,lo8(__stack)
#ifdef SPH
        ldi     r29,hi8(__stack)
        out     _SFR_IO_ADDR(SPH), r29
#endif
        out     _SFR_IO_ADDR(SPL), r28

Here, RAMEND as a C preprocessor macro that depends on the actual processor
type this code is being compiled for, and which evaluates to a 16-bit
number by the time this code is being assembled.

The idea behind that is that while the stack initially starts at top of
RAM (growing downwards), the user can tune the actual stack location at
link time by supplying a different value for the weak symbol __stack.

However, as the value of __stack is already known to the assembler at
that point, the assembler actually inserts the fixed value RAMEND instead
of a reference to the weak symbol __stack, thereby entirely defeating the
idea behind marking __stack as `weak' in the first place.

By reordering the code, and placing the definition of __stack behind its
use in the assembly code, the problem can be worked around, but I believe
the assembler must not resolve symbols marked as `weak' in the first place
but always leave that to the linker.

------- Additional Comment #1 From Bjoern Haase 2006-04-22 07:29 -------
The method to resolve the issue would probably be to disallow gas to do any 
fixup work on weak lables. 
Probably one could use the TC_VALIDATE_FIX hook in order to realize this. E.g. 
by adapting an expression like 
 
#define TC_VALIDATE_FIX(FIXP,SEG,SKIP)                      \ 
if (FIXP->fx_r_type == BFD_RELOC_AVR_7_PCREL                \ 
    || FIXP->fx_r_type == BFD_RELOC_AVR_13_PCREL            \ 
    || FIXP->fx_r_type == BFD_RELOC_AVR_LO8_LDI_PM          \ 
    || FIXP->fx_r_type == BFD_RELOC_AVR_HI8_LDI_PM          \ 
    || FIXP->fx_r_type == BFD_RELOC_AVR_HH8_LDI_PM          \ 
    || FIXP->fx_r_type == BFD_RELOC_AVR_16_PM)              \     
  {                                                         \ 
     goto SKIP;                                             \ 
  } 
 
to handle the case that FIXP refers to weak lables. The only question would be, 
how to find out whether or not FIXP refers to a weak label.?  
 
This probably would solve the issue for the avr target. I think, however, that 
the issue should be addressed for all of the targets since I believe it to be 
present also elsewhere. 
 
 

     Query page      Enter new bug
Actions: New | Query | bug # | Reports | Requests   New Account | Log In