Reputation: 10974
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
.
Upvotes: 3
Views: 2394
Reputation: 44126
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
.
Upvotes: 6