Recent

Author Topic: .section .text  (Read 600 times)

Key-Real

  • Sr. Member
  • ****
  • Posts: 282
.section .text
« on: April 26, 2024, 01:41:45 pm »
finally I got fpc to compile me an assembly output.


Code: Pascal  [Select][+][-]
  1. .section .text.n_main,"ax"
  2.  
  3. .globl  main
  4. .type   main,@function
  5. main:
  6.  
  7.  .globl PASCALMAIN
  8.  .type  PASCALMAIN,@function
  9.  
  10. PASCALMAIN:
  11. .ent main
  12.  
  13.    ... code ...
  14.  
  15. .end main
  16. .size   main, . - main
  17.  

so question
1) what is    .n_main,"ax"   ?
and
2) as i understand we start at main, so we have .ent and .end and .size debugger directives
    I thought fpc starts at PASCALMAIN? how to understand this?

Kays

  • Hero Member
  • *****
  • Posts: 586
  • Whasup!?
    • KaiBurghardt.de
Re: .section .text
« Reply #1 on: April 26, 2024, 02:01:01 pm »
First of all, assembly highlighting is possible [code=asm][/code]. Secondly, the GNU Assembler has a manual explaining everything. To summarize: Normally, everything belonging to one section is gathered in textual order. The subsection extension allows mixing various texts, thus
Code: ASM  [Select][+][-]
  1. .section .text.foo
  2. ABC
  3. .section .text.bar
  4. CDE
  5. .section .text.foo
  6. FGH
becomes
Code: ASM  [Select][+][-]
  1. .section .text
  2. ; now all `foo` texts
  3. ABC
  4. FGH
  5. ; now all `bar` texts
  6. CDE
even though ABC/FGH was “interrupted” by CDE. This allows more readable source code. The string "ax" merely indicates the custom section is allocated and executable. I’m not sure about your other question, so I’ll leave it for someone else to answer.
« Last Edit: April 26, 2024, 02:03:41 pm by Kays »
Yours Sincerely
Kai Burghardt

Key-Real

  • Sr. Member
  • ****
  • Posts: 282
Re: .section .text
« Reply #2 on: April 26, 2024, 02:05:45 pm »
ah, ok,
my question was wrong formulated.

I need to knew why this section is called n_main?
Is it a requerment for something?

Kays

  • Hero Member
  • *****
  • Posts: 586
  • Whasup!?
    • KaiBurghardt.de
Re: .section .text
« Reply #3 on: April 26, 2024, 02:28:14 pm »
[…] I need to knew why this section is called n_main? […]
Because m_main was already taken. :D It’s really just a name and using a pattern – something, underscore, something – ensures there are no unwanted collisions. Based on
Code: Bash  [Select][+][-]
  1. strings ./myExecutableProgram | grep n_main
the subsection name does not end up in the final executable.
Yours Sincerely
Kai Burghardt

nickysn

  • New Member
  • *
  • Posts: 18
Re: .section .text
« Reply #4 on: April 28, 2024, 10:08:35 pm »
On targets that support section based smartlinking (marked by the 'tf_smartlink_sections' flag in compiler/systems/i_*.pas), FPC puts each function in a separate section, i.e. something like that: '.text.n_NAMEOFFUNCTION'.

When linking the '--gc-sections' option is used, which causes the linker to remove ("garbage collect") unused sections and thus produce a smaller executable.

If the whole unit or program's code was put in a single section, called '.text', then unused functions won't be removed by the linker.

 

TinyPortal © 2005-2018