Dear All,

Consider the following code:

---------------------------------------------

struct S1
{
    char a, b, c;
};

typedef void (*foo_t)(void *arg);

struct S2
{
    __xdata void *p;
    foo_t f1, f2, f3;
};

void foo1 (void *arg) {arg;}
void foo2 (void *arg) {arg;}
void foo3 (void *arg) {arg;}

void execute (__code struct S2 *s)
{
    s->f1 (s->p);
    s->f2 (s->p);
    s->f3 (s->p);
}

void main (void)
{
    static __xdata struct S1 s1;

    static __code struct S2 s2 =
    {
        &s1,
        foo1,
        foo2,
        foo3
    };

    execute (&s2);
}

---------------------------------------------

It is compiled with sdcc --model-large --stack-auto --std-c99 options.
However it give the following link error:

?ASlink-Warning-Undefined Global '_s1' referenced by module 'main'

I went into the assmebly code and found the error.

;------------------------------------------------------------
;Allocation info for local variables in function 'main'
;------------------------------------------------------------
;s1                        Allocated with name '_main_s1_1_1'
;------------------------------------------------------------
;       main.c:25: void main (void)
;       -----------------------------------------
;        function main
;       -----------------------------------------
_main:
;       main.c:37: s1.a = 1;
        mov     dptr,#_main_s1_1_1
        mov     a,#0x01
        movx    @dptr,a
;       main.c:38: execute (&s2);
        mov     dptr,#_main_s2_1_1
        ljmp    _execute
        .area CSEG    (CODE)
        .area CONST   (CODE)
_main_s2_1_1:
        .byte _s1,(_s1 >> 8)                   ; should be
_main_s1_1_1 instead of s1
        .byte _foo1,(_foo1 >> 8)
        .byte _foo2,(_foo2 >> 8)
        .byte _foo3,(_foo3 >> 8)
        .area XINIT   (CODE)
        .area CABS    (ABS,CODE)

Hope I am correct.
Krish

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to