1

Is there any difference between the following two section definitions?

.section .text

And:

.text
.section    .text.startup,"ax",@progbits

I've come across the second in some gcc compiler output, but it seems like just doing .section .text or .text initializes the .text section just the same:

$ readelf file2 -S -W

[Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al

# using .text
[ 1] .text             PROGBITS        00000000004000b0 0000b0 000016 00  AX  0   0  1

# using .section .text
[ 1] .text             PROGBITS        00000000004000b0 0000b0 000016 00  AX  0   0  1

# using .text; .text.startup,"ax",@progbits
[ 1] .text             PROGBITS        00000000004000b0 0000b0 000016 00  AX  0   0  1

Is the compiler output just a more verbose way of saying .text ? As another example, would the .rodata and .data section be 'verbosely written' as:

.section .rodata,"a",@progbits
.string "Not-writable"

.section .data,"wa",@progbits
.string "Writable"

Also seems to be related to: X86 assembly: What is the difference between .text.startup section and .text section.

David542
  • 104,438
  • 178
  • 489
  • 842
  • You missed the obvious difference for some reason. One is named `.text`, the other is named `.text.startup`. – Ross Ridge Sep 21 '20 at 23:14
  • @RossRidge right, but it doesn't show a new section (or maybe I don't know how to find it) for the `.text.startup` section). – David542 Sep 21 '20 at 23:17
  • Did you define anything in it? Also are you looking at the assembler output or the linker output? – Ross Ridge Sep 21 '20 at 23:18
  • @RossRidge could you please clarify what you mean? The `.text.startup` is from a compiler output, but yes there's a small `_start` function/label in there. – David542 Sep 21 '20 at 23:20
  • 1
    An empty section may not be output. If you're not looking at the assembler output, an unlinked relocatable object file, then you're not looking in the right place. Sections in linked executables or shared libraries are just debugging information and don't actually need to be present. It's only sections in relocatable object files that serve a purpose. – Ross Ridge Sep 21 '20 at 23:24
  • 1
    Also the default linker script likely merges all `foo.bar` sections into `foo`. – Jester Sep 21 '20 at 23:32
  • @Jester oh I see. That's probably why it's just showing up as one section. – David542 Sep 21 '20 at 23:35

0 Answers0