Where is the "main" function?

Where is the function ' main ' located?

 int main() { const char *str = "hello world"; printf("%s\n", str); } 

I know about these places:

  • .text
  • .data
  • .bss
  • stack
  • heap

I think the answer is .bss because I know that the " main " function is not in others (but I could be wrong).

+5
source share
1 answer

This is obviously outside the scope of the C-standard, because there are no "sections" in it.

Using ELF as an example, usually all the code will be in the text segment (also known as the code segment) and main will be in the text segment. You can see where the characters are using the readelf or objdump commands. For example, if you check the output of objdump -S a.out , you can see the assembly and various sections.

You can read http://wiki.osdev.org/ELF and http://www.cs.cmu.edu/afs/cs/academic/class/15213-f00/docs/elf.pdf for more information.

+8
source

Source: https://habr.com/ru/post/1274070/


All Articles