Hi all:

I have been noticing that a function that is not used by any module in
program gets linked anyway, occupying some precious amount of memory.

Suppose that you were sharing a common module but you only needed some
functions of it. Is there a way to avoid linking all the unused
functions?

I am also posting the output of msp430-objdump with an example of the
situation:


tst_unreachable_code.elf:     file format elf32-msp430

Disassembly of section .text:

00003100 <__init_stack>:
    3100:       31 40 00 31     mov     #12544, r1      ;#0x3100

00003104 <__low_level_init>:
    3104:       b2 40 80 5a     mov     #23168, &0x0120 ;#0x5a80
    3108:       20 01 

0000310a <__do_clear_bss>:
    310a:       3f 40 00 00     mov     #0,     r15     ;#0x0000
    310e:       0f 93           cmp     #0,     r15     ;r3 As==00
    3110:       04 24           jz      $+10            ;abs 0x311a
    3112:       1f 83           dec     r15             ;
    3114:       cf 43 00 11     mov.b   #0,     4352(r15);r3 As==00
    3118:       fc 23           jnz     $-6             ;abs 0x3112

0000311a <__do_copy_data>:
    311a:       3f 40 00 00     mov     #0,     r15     ;#0x0000
    311e:       0f 93           cmp     #0,     r15     ;r3 As==00
    3120:       05 24           jz      $+12            ;abs 0x312c
    3122:       2f 83           decd    r15             ;
    3124:       9f 4f 4c 31     mov     12620(r15),4352(r15);
    3128:       00 11 
    312a:       fb 23           jnz     $-8             ;abs 0x3122

0000312c <__jump_to_main>:
    312c:       30 40 3a 31     br      #0x313a         ;

00003130 <__ctors_end>:
    3130:       80 00           .word   0x0080; ????
    3132:       4a 31           jn      $+662           ;abs 0x33c8

#include <io.h>

00003134 <foo>:
void foo(void)
{
/* A function not used by anybody in program but,
 * however, is linked anyway, wasting ROM space.
 */
    P1OUT ^= 0x02;          /* Toggle P1.1 */
    3134:       e2 e3 21 00     xor.b   #2,     &0x0021 ;r3 As==10
}
    3138:       30 41           ret                     

0000313a <main>:
int main (void)
{
    313a:       31 40 00 31     mov     #12544, r1      ;#0x3100
    WDTCTL=WDTPW+WDTHOLD;   /* Stop watchdog */
    313e:       b2 40 80 5a     mov     #23168, &0x0120 ;#0x5a80
    3142:       20 01 
    
    while(1)
    {
        P1OUT ^= 0x01;      /* Toggle P1.0 */
    3144:       d2 e3 21 00     xor.b   #1,     &0x0021 ;r3 As==01
    3148:       fd 3f           jmp     $-4             ;abs 0x3144

0000314a <_unexpected_>:
    }
}// end main
    314a:       00 13           reti                    
Disassembly of section .vectors:

0000ffc0 <InterruptVectors>:
    ffc0:       30 31           jn      $+610           ;abs 0x222
    ffc2:       30 31           jn      $+610           ;abs 0x224
    ffc4:       30 31           jn      $+610           ;abs 0x226
    ffc6:       30 31           jn      $+610           ;abs 0x228
    ffc8:       30 31           jn      $+610           ;abs 0x22a
    ffca:       30 31           jn      $+610           ;abs 0x22c
    ffcc:       30 31           jn      $+610           ;abs 0x22e
    ffce:       30 31           jn      $+610           ;abs 0x230
    ffd0:       30 31           jn      $+610           ;abs 0x232
    ffd2:       30 31           jn      $+610           ;abs 0x234
    ffd4:       30 31           jn      $+610           ;abs 0x236
    ffd6:       30 31           jn      $+610           ;abs 0x238
    ffd8:       30 31           jn      $+610           ;abs 0x23a
    ffda:       30 31           jn      $+610           ;abs 0x23c
    ffdc:       30 31           jn      $+610           ;abs 0x23e
    ffde:       30 31           jn      $+610           ;abs 0x240
    ffe0:       30 31           interrupt service routine at 0x3130
    ffe2:       30 31           interrupt service routine at 0x3130
    ffe4:       30 31           interrupt service routine at 0x3130
    ffe6:       30 31           interrupt service routine at 0x3130
    ffe8:       30 31           interrupt service routine at 0x3130
    ffea:       30 31           interrupt service routine at 0x3130
    ffec:       30 31           interrupt service routine at 0x3130
    ffee:       30 31           interrupt service routine at 0x3130
    fff0:       30 31           interrupt service routine at 0x3130
    fff2:       30 31           interrupt service routine at 0x3130
    fff4:       30 31           interrupt service routine at 0x3130
    fff6:       30 31           interrupt service routine at 0x3130
    fff8:       30 31           interrupt service routine at 0x3130
    fffa:       30 31           interrupt service routine at 0x3130
    fffc:       30 31           interrupt service routine at 0x3130
    fffe:       00 31           interrupt service routine at 0x3100

Thank you very much for your attention.

Alex

Reply via email to