2012-10-02 27 views
11

मैं साथ जीसीसी hello.c -ओ इस कोड संकलन कर रहा हूँ हैलो -O3__gmon_start__ प्रतीक क्या है?

#include <stdio.h> 

int main(void) { 
    printf("Hello world\n"); 
    return 0; 
} 

जब मैं relocations सूची मैं:

[email protected]$ readelf -r hello | grep gmon 
080495a4 00000106 R_386_GLOB_DAT 00000000 __gmon_start__ 
080495b4 00000107 R_386_JUMP_SLOT 00000000 __gmon_start__ 

जब मैं इस फाइल मैं में प्रतीकों की सूची :

[email protected]$ readelf -s hello | grep gmon 
    1: 00000000  0 NOTYPE WEAK DEFAULT UND __gmon_start__ 
    48: 00000000  0 NOTYPE WEAK DEFAULT UND __gmon_start__ 

क्या gmon_start में gprof के साथ कुछ भी है? उस प्रतीक के लिए स्थानांतरण क्यों है, यहां तक ​​कि मैंने -pg या -g के साथ संकलन/लिंक नहीं किया है? कौन सा पुस्तकालय इस प्रतीक को हल करेगा?

उत्तर

10

एक छोटे से Googling किया और here से मिला:

समारोह call_gmon_start gmon रूपरेखा प्रणाली initializes। जब बाइनरी -pg झंडा, साथ संकलित और gprof साथ प्रयोग के लिए उत्पादन बनाता रहे इस प्रणाली सक्षम किया गया है (1)। परिदृश्य द्विआधारी call_gmon_start के मामले में सीधे कि आगे बढ़ने से स्थित है समारोह _start। call_gmon_start समारोह वैश्विक ऑफसेट तालिका में अंतिम प्रविष्टि (भी __gmon_start__ रूप में जाना जाता है) और, अगर शून्य नहीं, निर्दिष्ट पते पर नियंत्रण पारित करेंगे पाता है। __gmon_start__ तत्व gmon आरंभीकरण समारोह है, जो जानकारी की रूपरेखा की रिकॉर्डिंग शुरू होता है और() atexit के साथ एक सफाई समारोह पंजीकृत करता है करने के लिए अंक। हमारे मामले में हालांकि gmon उपयोग में नहीं है, और इस तरह __gmon_start__ के रूप में शून्य है।

तो ...

  1. हाँ, यह gprof
  2. मुझे यकीन है कि क्यों प्रतीक वहाँ में छोड़ दिया जा रहा है नहीं कर रहा हूँ के साथ कुछ है। शायद यह एक जगह धारक के लिए जब यह gprof के लिए संकलित किया गया है?

अद्यतन:

ठीक है, तो मैं के साथ और -pg के बिना अपने कोड संकलित। ऐसा लगता है कि __gmon_start__ संकलित प्रोग्राम के भीतर किसी पते पर मैप किया गया है। तो ऐसा कहा जा रहा है कि, मुझे नहीं लगता कि एक पुस्तकालय है जो उस प्रतीक को हल करता है, लेकिन प्रोग्राम स्वयं ही।

-pg साथ :

[email protected]:~$ readelf -r hello 

Relocation section '.rel.dyn' at offset 0x32c contains 1 entries: 
Offset  Info Type   Sym.Value Sym. Name 
08049fec 00000806 R_386_GLOB_DAT 08048460 __gmon_start__ 

Relocation section '.rel.plt' at offset 0x334 contains 6 entries: 
Offset  Info Type   Sym.Value Sym. Name 
0804a000 00000607 R_386_JUMP_SLOT 080483b0 _mcleanup 
0804a004 00000107 R_386_JUMP_SLOT 00000000 __monstartup 
0804a008 00000207 R_386_JUMP_SLOT 00000000 mcount 
0804a00c 00000307 R_386_JUMP_SLOT 00000000 __cxa_atexit 
0804a010 00000407 R_386_JUMP_SLOT 00000000 puts 
0804a014 00000507 R_386_JUMP_SLOT 00000000 __libc_start_main 

__gmon_start__ कोड की objdump:

[email protected]:~$ objdump -S hello | grep "460 <__gmon_start__>:" -A 20 

08048460 <__gmon_start__>: 
8048460:  83 ec 1c    sub $0x1c,%esp 
8048463:  a1 20 a0 04 08   mov 0x804a020,%eax 
8048468:  85 c0     test %eax,%eax 
804846a:  75 2a     jne 8048496 <__gmon_start__+0x36> 
804846c:  c7 05 20 a0 04 08 01 movl $0x1,0x804a020 
8048473:  00 00 00 
8048476:  c7 44 24 04 36 86 04 movl $0x8048636,0x4(%esp) 
804847d:  08 
804847e:  c7 04 24 30 84 04 08 movl $0x8048430,(%esp) 
8048485:  e8 36 ff ff ff   call 80483c0 <[email protected]> 
804848a:  c7 04 24 b0 83 04 08 movl $0x80483b0,(%esp) 
8048491:  e8 1a 01 00 00   call 80485b0 <atexit> 
8048496:  83 c4 1c    add $0x1c,%esp 
8048499:  c3      ret  
804849a:  90      nop 
804849b:  90      nop 
804849c:  90      nop 
804849d:  90      nop 

संकलित hello कार्यक्रम में __gmon_start__ वर्तमान के साथ, आप देख सकते हैं कि कि __monstartup में कहा जाता है।(monstartup man page)

-pg बिना:

[email protected]:~$ readelf -r hello 

Relocation section '.rel.dyn' at offset 0x290 contains 1 entries: 
Offset  Info Type   Sym.Value Sym. Name 
08049ff0 00000206 R_386_GLOB_DAT 00000000 __gmon_start__ 

Relocation section '.rel.plt' at offset 0x298 contains 3 entries: 
Offset  Info Type   Sym.Value Sym. Name 
0804a000 00000107 R_386_JUMP_SLOT 00000000 puts 
0804a004 00000207 R_386_JUMP_SLOT 00000000 __gmon_start__ 
0804a008 00000307 R_386_JUMP_SLOT 00000000 __libc_start_main 

आप यहाँ देख सकते हैं, कि __gmon_start__ का प्रतीक मूल्य 00000000 को तैयार है।

+0

तीसरे प्रश्न के बारे में? क्या मुझे GOT में अंतिम प्रविष्टि को __gmon_start__ के पते के रूप में माना जाना चाहिए? इसके अलावा, "हैलो" की बाइनरी का निरीक्षण करते हुए यह पता चला है कि एक प्रविष्टि है: __gmon_start __ @ plt और दूसरा (पीएलटी प्रविष्टि) __gmon_start __ @ plt-0x10> – JohnTortugo

+0

तो 'gmon_start' के ऑफसेट को भौतिक पते पर कैसे मैप किया जाता है ? – RouteMapper

संबंधित मुद्दे