Zig Version
0.14.0-dev.2989+bf6ee7cb3
Steps to Reproduce and Observed Behavior
Build an STM32 binary in Debug mode (for the STM32F3DISCOVERY board in this case), with 0.14.0-dev.2989+bf6ee7cb3 results in something that is way too big to flash (128 MB), apparently because of .ARM.extab.t[...] section being placed in RAM instead of in flash.
Reproduction scenario: With https://github.com/marnix/microzig/tree/zig-issue-22603-0.14.0-dev.2851%2Bb074fb7dd (and Zig 0.14.0-dev.2989+bf6ee7cb3), in examples/stmicro/stm32, run zig build and inspect the resulting zig-out/firmware/stm32f3discovery.elf file.
The readelf -S output is shown below, and after that the generated and used linker.ld file, which has the memory layout of the specific MCU that I compile for and use.
The resulting binary therefore covers 0x0800_0000...0x1000_06cf (slightly over 128 MB), with zeroes in the range 0x0800_4bb8...0x1000_069f (first RAM is at 0x1000_000...0x1000_1fff), which goes beyond the flash range of 0x0800_0000...0x0803_ffff.)
So the issue seems to be that the ARM.extab sections (which seem contain exception tables, each is 12 bytes large) are put in RAM instead of in flash. But these sections are not even mentioned in linker.ld...
My question: What could be causing this?
Note that this only happens in Debug mode: with ReleaseSafe and ReleaseFast there are fewer sections, but they are all put in the flash region; and with ReleaseSmall these sections completely disappear; so in all those cases the resulting binary can be flashed.
For completeness, this is for -ODebug -target thumb-freestanding-eabihf -mcpu cortex_m4+vfp4d16sp.
readelf -S output:
There are 24 section headers, starting at offset 0xe6380:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 08000000 010000 00441e 00 AX 0 0 4
[ 2] .ARM.exidx ARM_EXIDX 08004420 014420 0000f8 00 AL 1 0 4
[ 3] .data PROGBITS 10000000 020000 0006a0 00 AMS 0 0 8
[ 4] .ARM.extab.t[...] PROGBITS 100006a0 0206a0 00000c 00 A 0 0 4
[ 5] .ARM.extab.t[...] PROGBITS 100006ac 0206ac 00000c 00 A 0 0 4
[ 6] .ARM.extab.t[...] PROGBITS 100006b8 0206b8 00000c 00 A 0 0 4
[ 7] .ARM.extab.t[...] PROGBITS 100006c4 0206c4 00000c 00 A 0 0 4
[ 8] .bss NOBITS 100006d0 0206d0 000000 00 WA 0 0 1
[ 9] .flash_end PROGBITS 08004bb8 0206d0 000000 00 WA 0 0 1
[10] .debug_loc PROGBITS 00000000 0206d0 05c5af 00 0 0 1
[11] .debug_abbrev PROGBITS 00000000 07cc7f 0006ad 00 0 0 1
[12] .debug_info PROGBITS 00000000 07d32c 02a3c6 00 0 0 1
[13] .debug_ranges PROGBITS 00000000 0a76f2 00b420 00 0 0 1
[14] .debug_str PROGBITS 00000000 0b2b12 00c532 01 MS 0 0 1
[15] .debug_pubnames PROGBITS 00000000 0bf044 0038bb 00 0 0 1
[16] .debug_pubtypes PROGBITS 00000000 0c28ff 001c0e 00 0 0 1
[17] .ARM.attributes ARM_ATTRIBUTES 00000000 0c450d 000045 00 0 0 1
[18] .debug_frame PROGBITS 00000000 0c4554 003ddc 00 0 0 4
[19] .debug_line PROGBITS 00000000 0c8330 01b1bb 00 0 0 1
[20] .comment PROGBITS 00000000 0e34eb 000067 01 MS 0 0 1
[21] .symtab SYMTAB 00000000 0e3554 001580 10 23 329 4
[22] .shstrtab STRTAB 00000000 0e4ad4 000175 00 0 0 1
[23] .strtab STRTAB 00000000 0e4c49 001736 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
D (mbind), y (purecode), p (processor specific)
linker.ld:
/*
* This file was auto-generated by microzig
*
* Target CPU: cortex_m4
* Target Chip: STM32F303VC
*/
ENTRY(microzig_main);
MEMORY
{
flash0 (rx!w) : ORIGIN = 0x08000000, LENGTH = 0x00040000
ram0 (rw!x) : ORIGIN = 0x10000000, LENGTH = 0x00002000
ram1 (rw!x) : ORIGIN = 0x20000000, LENGTH = 0x0000A000
}
SECTIONS
{
.text :
{
KEEP(*(microzig_flash_start))
*(.text*)
} > flash0
.ARM.exidx : {
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} >flash0
.data :
{
microzig_data_start = .;
*(.sdata*)
*(.data*)
*(.rodata*)
microzig_data_end = .;
} > ram0 AT> flash0
.bss (NOLOAD) :
{
microzig_bss_start = .;
*(.bss*)
*(.sbss*)
microzig_bss_end = .;
} > ram0
.flash_end :
{
microzig_flash_end = .;
} > flash0
microzig_data_load_start = LOADADDR(.data);
}
Expected Behavior
With Zig 0.13.0, no .ARM.extab.t[...] section is ever created.
Reproduction scenario: Do the same thing with https://github.com/marnix/microzig/tree/zig-issue-22603-0.13.0, with Zig 0.13.0, and compare the readelf -S output.
(That code is identical to the code above, minus changes to match Zig 0.13.0, most of which are in marnix/microzig@cebfb1b.)
Zig Version
0.14.0-dev.2989+bf6ee7cb3
Steps to Reproduce and Observed Behavior
Build an STM32 binary in Debug mode (for the STM32F3DISCOVERY board in this case), with 0.14.0-dev.2989+bf6ee7cb3 results in something that is way too big to flash (128 MB), apparently because of
.ARM.extab.t[...]section being placed in RAM instead of in flash.Reproduction scenario: With https://github.com/marnix/microzig/tree/zig-issue-22603-0.14.0-dev.2851%2Bb074fb7dd (and Zig 0.14.0-dev.2989+bf6ee7cb3), in examples/stmicro/stm32, run
zig buildand inspect the resulting zig-out/firmware/stm32f3discovery.elf file.The
readelf -Soutput is shown below, and after that the generated and usedlinker.ldfile, which has the memory layout of the specific MCU that I compile for and use.The resulting binary therefore covers 0x0800_0000...0x1000_06cf (slightly over 128 MB), with zeroes in the range 0x0800_4bb8...0x1000_069f (first RAM is at 0x1000_000...0x1000_1fff), which goes beyond the flash range of 0x0800_0000...0x0803_ffff.)
So the issue seems to be that the ARM.extab sections (which seem contain exception tables, each is 12 bytes large) are put in RAM instead of in flash. But these sections are not even mentioned in linker.ld...
My question: What could be causing this?
Note that this only happens in Debug mode: with ReleaseSafe and ReleaseFast there are fewer sections, but they are all put in the flash region; and with ReleaseSmall these sections completely disappear; so in all those cases the resulting binary can be flashed.
For completeness, this is for
-ODebug -target thumb-freestanding-eabihf -mcpu cortex_m4+vfp4d16sp.readelf -Soutput:linker.ld:
Expected Behavior
With Zig 0.13.0, no
.ARM.extab.t[...]section is ever created.Reproduction scenario: Do the same thing with https://github.com/marnix/microzig/tree/zig-issue-22603-0.13.0, with Zig 0.13.0, and compare the
readelf -Soutput.(That code is identical to the code above, minus changes to match Zig 0.13.0, most of which are in marnix/microzig@cebfb1b.)