1

Suppose that this C program is running on a SPARC structure. I think that normal function's name is allocated in .text, but static one is allocated in BSS? Is that correct? For example, this is a C static function

static void fubar( int b )
{
    static int c = 7;
    void (*d) (int) = fubar;
}

Where is this fubar stored?

Jester
  • 56,577
  • 4
  • 81
  • 125
Patroclus
  • 1,163
  • 13
  • 31
  • BSS is all zeroes. You don't store functions there. Zero-initialized static variables may go there though. – Jester Mar 02 '17 at 01:13
  • 3
    There is no requirement that the name be stored at all. If it's stripped of debugging symbols, there is no need for storing the name. Function names only matter at compile time, for exported functions, and debugging purposes (and the name isn't strictly necessary for debugging; a debugger with source access could look it up in the source file); a static function's name is meaningless programmatically the moment it finishes compilation. – ShadowRanger Mar 02 '17 at 01:13
  • Please put the question in the question, not just the title. The question shouldn't start with "and". – Barmar Mar 02 '17 at 01:15
  • "name is stored in .text". No it's not. There are no function names in the text section - static or otherwise. – kaylum Mar 02 '17 at 01:16
  • The code for `fubar` goes into `.text`. The name `fubar` is not stored anywhere (see comments above). The variable `d` is local on the stack (unless optimized to a register, or elided completely). – Jester Mar 02 '17 at 01:17
  • @Jester But is there any memory is allocated for the function name? If so, where? – Patroclus Mar 02 '17 at 01:19
  • No, there isn't. See ShadowRanger's comment, above. This applies to non-static functions just the same. – Jester Mar 02 '17 at 01:19
  • If you don't strip the binary, the names may be stored in debug info, but that's probably not even loaded by OS when executing the binary, it's just in the executable file. There's no need to have the function name anywhere in the machine code, it needs only memory address of it. – Ped7g Mar 02 '17 at 03:35

0 Answers0