Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between .section .text and .text with gas

As far as I can tell with objdump, with gas using

.section .text

and

.text

are equivalent. Is this true?

From gas manual .section name:

Use the .section directive to assemble the following code into a section named name.

From gas manual .text subsection:

Tells as to assemble the following statements onto the end of the text subsection numbered subsection, which is an absolute expression. If subsection is omitted, subsection number zero is used.

My question also applies to .data.

like image 832
qwr Avatar asked Oct 18 '25 11:10

qwr


1 Answers

I think there is a small difference.

.section lets the programmer specify any section name and thus, as stated in the documentation, is not supported for the a.out format (while it is for COFF and ELF).

This directive is only supported for targets that actually support arbitrarily named sections; on a.out targets, for example, it is not accepted, even with a standard a.out section name.

.text on the contrary always designates the code section regardless of its actual name in the output format.

Considering that a.out was used before ELF was added back in the '96, I won't consider compatibility with such an old format an issue.

.text and .data save a few keystrokes but for consistency it's perfectly fine to always use .section.

like image 124
Margaret Bloom Avatar answered Oct 22 '25 07:10

Margaret Bloom