Code in .subsection 0 should be prior to .subsection 1
Georg-Johann Lay
avr@gjlay.de
Mon Nov 24 11:26:43 GMT 2025
Am 24.11.25 um 11:11 schrieb Jan Beulich:
> On 24.11.2025 11:02, Georg-Johann Lay via Binutils wrote:
>> So I have problems grasping why code in .subsection 1
>> is located PRIOR to code in .subsection 0:
>>
>> ;; init.S
>> .section .init2,"ax",@progbits
>> .subsection 0
>> .type __init_sp,@function
>> .global __init_sp
>> __init_sp:
>> ldi r22, 0
>>
>> ;; main.S
>> .section .init2,"ax",@progbits
>> .subsection 1
>> ldi r22, 1
>> .global __init_sp
>
> Sub-sections are an assembler-internal thing, i.e. that information is lost
> by the time the object file is built. Once again you could observe this
> yourself when looking at the dump of the generate objects, where you will
> see no trace of sub-sections.
>
> Jan
Ok, thank you for the explanation.
Though that's not at all clear from the documentation.
Johann
>> So the expected disassembly is
>>
>> ldi r22, 0 ; .subsection 0
>> ldi r22, 1 ; .subsection 1
>>
>> But when I run
>>
>> avr-ld --version | head -1
>> avr-as main.S -o main.o
>>
>> avr-as init.S -o init.o
>> avr-ar cru libinit.a init.o
>> avr-ranlib libinit.a
>>
>> avr-ld main.o -o main.elf -L. -linit
>> avr-objdump -d main.elf
>>
>> The output is:
>>
>> GNU ld (GNU Binutils) 2.45.50.20250718
>>
>> main.elf: file format elf32-avr
>>
>>
>> Disassembly of section .text:
>>
>> 00000000 <__ctors_end>:
>> 0: 61 e0 ldi r22, 0x01 ; 1
>>
>> 00000002 <__init_sp>:
>> 2: 60 e0 ldi r22, 0x00 ; 0
>>
>> The .init2 section is part of text and mentioned in the
>> default ld script:
>>
>> .text :
>> {
>> ....
>> *(.init2) /* Clear __zero_reg__, set up stack pointer. */
>> KEEP (*(.init2))
>> ....
>> } > text
>>
>> What am I doing / understanding wrong?
>> Is this a bug?
>>
>> Johann
More information about the Binutils
mailing list