2016-11-15 3 views
-1

En fait, j'écris un chargeur d'objets partagés, qui se charge avec les objets partagés créés par gcc (ELF) sur un contrôleur cortex-m4. Le chargement, la résolution de dépendance et le déplacement etc. fonctionnent bien. Mais l'objet partagé a des symboles étranges dans la section .dynsym que je ne sais pas comment gérer.Objet partagé sur les symboles étranges Cortex-M4 dans la section dynsym

readelf --dyn-sym libfoo.so

Num: Wert Size Typ  Bind Vis  Ndx Name                              
0: 00000000  0 NOTYPE LOCAL DEFAULT UND                                
1: 000005c8  0 SECTION LOCAL DEFAULT 8                                
2: 00000874  0 SECTION LOCAL DEFAULT 16                                
3: 00000000  0 NOTYPE GLOBAL DEFAULT UND printf                              
4: 0000082d 32 FUNC GLOBAL DEFAULT 12 foo3                              
5: 0000087c  0 NOTYPE GLOBAL DEFAULT 18 __bss_start__                            
6: 00000000  0 NOTYPE GLOBAL DEFAULT UND __libc_init_array                           
7: 00000728  0 NOTYPE GLOBAL DEFAULT 12 _mainCRTStartup                            
8: 000005c8  0 FUNC GLOBAL DEFAULT 8 _init                              
9: 00000000  0 NOTYPE GLOBAL DEFAULT UND __libc_fini_array                           
10: 00000000  0 NOTYPE WEAK DEFAULT UND __deregister_frame_info                          
11: 00000000  0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable                         
12: 00000898  0 NOTYPE GLOBAL DEFAULT 18 __bss_end__                             
13: 00000728  0 NOTYPE GLOBAL DEFAULT 12 _start                              
14: 00000000  0 NOTYPE WEAK DEFAULT UND software_init_hook                           
15: 00000000  0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab                         
16: 00000000  0 NOTYPE GLOBAL DEFAULT UND memset                              
17: 00000000  0 NOTYPE GLOBAL DEFAULT UND main                              
18: 00000000  0 NOTYPE WEAK DEFAULT UND hardware_init_hook                           
19: 000005e0  0 FUNC GLOBAL DEFAULT 9 _fini                              
20: 00000000  0 NOTYPE GLOBAL DEFAULT UND atexit                              
21: 00000000  0 NOTYPE WEAK DEFAULT UND __stack                              
22: 00000000  0 NOTYPE GLOBAL DEFAULT UND exit                              
23: 00000000  0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses                           
24: 00000000  0 NOTYPE WEAK DEFAULT UND __register_frame_info 

Pourquoi l'objet partagé besoin d'une référence à une fonction principale et la fonction __libc_init_array? En particulier le symbole de __libc_init_array n'a aucun sens pour moi ... Cette fonction normalise les __preinit_array, _init et __init_array, mais ce travail devrait être fait par mon loader et non par l'objet lui-même, ou je me trompe?

Y a-t-il une documentation étape par étape pour initialiser un objet partagé chargé avec toutes ses dépendances?

C'est la façon, comment je construire mon objet commun:

gcc -std=gnu99 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -ffunction-sections -fdata-sections -mfloat-abi=soft -mcpu=cortex-m4 -mthumb -mlong-calls -Os -g -c -fPIC -o foo.o foo.c 

gcc -shared -fPIC -Wl,-soname,libfoo.so -T./shared.ld -o libfoo.so foo.o 

Il y a une autre question: Sans l'option -mlong-appels, mon gcc génère opcode non valide dans la section .plt .. ce que je fais mal?

EDIT: Mon foo.c est verry simple:

#include <stdio.h> 
#include <string.h> 

void foo3 (void) 
{ 
    printf("Hello from shared-object"); 
} 

Ceci est mon shared.ld:

OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") 

OUTPUT_ARCH(arm) 

SECTIONS 
{ 
    .interp   : { *(.interp) } 
    .note.ABI-tag : { *(.note.ABI-tag) } 

    .gnu.version : { *(.gnu.version) } 
    .gnu.version_d : { *(.gnu.version_d) } 
    .gnu.version_r : { *(.gnu.version_r) } 

    .dynamic  : { *(.dynamic) } 

    .hash   : { *(.hash) } 
    .dynsym   : { *(.dynsym) } 
    .dynstr   : { *(.dynstr) } 

    .rel.dyn  : { *(.rel.dyn) } 
    .rela.dyn  : { *(.rela.dyn) } 
    .rel.plt  : { *(.rel.plt) } 
    .rela.plt  : { *(.rela.plt) } 

    .plt   : { *(.plt) } 
    .got   : { *(.got.plt) *(.got) } 

    .init ALIGN(32/8) : 
    { 
     KEEP (*(.init)) 
    } 

    .fini ALIGN(32/8) : 
    { 
     KEEP (*(.fini)) 
    } 

    .preinit_array ALIGN(32/8) : 
    { 
     PROVIDE(__preinit_array_start = .); 
     KEEP (*(.preinit_array)) 
     PROVIDE(__preinit_array_end = .); 
    } 

    .init_array ALIGN(32/8) : 
    { 
     PROVIDE(__init_array_start = .); 
     KEEP (*(.init_array*)) 
     PROVIDE(__init_array_end = .); 
    } 

    .fini_array ALIGN(32/8) : 
    { 
     PROVIDE(__fini_array_start = .); 
     KEEP (*(.fini_array*)) 
     PROVIDE(__fini_array_end = .); 
    } 

    .text ALIGN(32/8) : 
    { 
     *(.text .text.*) 
    } 

    .rodata ALIGN(32/8) : 
    { 
     *(.rodata .rodata.*) 
    } 

    .data ALIGN(32/8) : 
    { 
     *(.data .data.*) 
    } 

    .bss ALIGN(32/8) : 
    { 
     PROVIDE(__bss_start__ = .); 

     *(.bss .bss.*) 
     *(COMMON) 

     PROVIDE(__bss_end__ = .); 
    } 
} 

AVIS: La référence à printf est réglé à la printf de mon programme principal à linktime - juste pour testingpurpose.

merci pour votre aide :-)

+0

Il serait utile si vous fournissiez également du code (tronqué) pour foo.c et shared.ld. – yugr

+0

"Sans l'option -mlong-calls, mon gcc génère un opcode invalide dans la section .plt ... ce que je fais de mal?" - Si cela se reproduit sur des binutils récents, vous devriez [déposer un bug] (https://sourceware.org/bugzilla/). – yugr

+0

Je me demande si votre chaîne d'outils est capable de construire des bibliothèques partagées. Pourriez-vous vérifier les suggestions dans http://stackoverflow.com/questions/18586291/could-not-build-shared-library-using-toolchain-arm-uclinuxeabi? – yugr

Répondre

0

J'ai résolu le premier problème! -nostartfiles était mon ami :-)

gcc -std=gnu99 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -ffunction-sections -fdata-sections -mfloat-abi=soft -mcpu=cortex-m4 -mthumb -mlong-calls -Os -g -c -fPIC -o foo.o foo.c 

gcc -shared -fPIC -nostartfiles -mfloat-abi=soft -mcpu=cortex-m4 -mthumb -Wl,-soname,libfoo.so -T./shared.ld -o libfoo.so foo.o 

sans l'ensemble des trucs crtxxx la bibliothèque est maintenant propre! Le problème avec l'opcode invalide existe toujours, mais j'utilise gcc dans la version 4.7.4, donc ce "bug" peut être corrigé aujourd'hui.