Hi, Now that binutils 2.26 supports symbols for memory region lengths, I thought it would be nice to have avr-libc's crt file export those symbols from the gcrt1.S, so that overflows can be detected at link time.
This is how the standard linker script memory map looks now, with the default values for the *_LENGTH__ symbols being the previous constant values. <snip> MEMORY { text (rx) : ORIGIN = 0, LENGTH = __TEXT_REGION_LENGTH__ data (rw!x) : ORIGIN = $DATA_ORIGIN, LENGTH = __DATA_REGION_LENGTH__ eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = __EEPROM_REGION_LENGTH__ fuse (rw!x) : ORIGIN = 0x820000, LENGTH = __FUSE_REGION_LENGTH__ lock (rw!x) : ORIGIN = 0x830000, LENGTH = __LOCK_REGION_LENGTH__ signature (rw!x) : ORIGIN = 0x840000, LENGTH = __SIGNATURE_REGION_LENGTH__ user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = __USER_SIGNATURE_REGION_LENGTH__ } </snip> Previously, only constant literals were allowed for the LENGTH parameter, so the lengths were set to match the device with the biggest size for each architecture, IIRC. Only if user code managed to overflow one of those would the linker complain. Now that symbols work, it is possible to set region lengths accurately on a per device basis and have the linker error out if any of them overflow. Someone needs to define them though, and I thought avr-libc's crt file, being compiled for each device, might be a good candidate. For starters, the below patch defines __FUSE_REGION_LENGTH__ as a weak symbol. diff --git avr-libc/crt1/gcrt1.S avr-libc/crt1/gcrt1.S index 561d4f8..b2f482b 100644 --- avr-libc/crt1/gcrt1.S +++ avr-libc/crt1/gcrt1.S @@ -390,3 +390,8 @@ __do_copy_data: .L__desc_end: .balign 4 + /* Set length symbol values - this linker script + and the linker use these to detect size overflows. + */ + .weak __FUSE_REGION_LENGTH__ + .set __FUSE_REGION_LENGTH__, FUSE_MEMORY_SIZE Is this ok? Regards Senthil _______________________________________________ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-libc-dev