From a330401769a7e4bf6f950ae610776aa2cc0c9914 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 25 May 2021 16:47:13 +0200 Subject: [PATCH] change strategy for refs to linker symbols to get compatible again with old GCC (6.3), tested on GCC 11 too --- armsrc/BigBuf.c | 2 +- armsrc/appmain.c | 26 ++++++++++++++------------ armsrc/fpgaloader.c | 6 +++--- armsrc/start.c | 14 +++++++------- bootrom/bootrom.c | 8 ++++---- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index 31ecb4329..bf5d961ea 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -14,7 +14,7 @@ #include "dbprint.h" #include "pm3_cmd.h" -extern char _stack_start[], __bss_end__[]; +extern uint32_t _stack_start[], __bss_end__[]; // BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces. // Also used to hold various smaller buffers and the Mifare Emulator Memory. diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 36b7b1768..a419617d1 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -70,7 +70,7 @@ int DBGLEVEL = DBG_ERROR; uint8_t g_trigger = 0; bool g_hf_field_active = false; -extern char _stack_start[], _stack_end[]; +extern uint32_t _stack_start[], _stack_end[]; struct common_area common_area __attribute__((section(".commonarea"))); static int button_status = BUTTON_NO_CLICK; static bool allow_send_wtx = false; @@ -240,9 +240,9 @@ static uint32_t MeasureAntennaTuningLfData(void) { } void print_stack_usage(void) { - for (uint32_t *p = (uint32_t *)_stack_start; ; ++p) { + for (uint32_t *p = _stack_start; ; ++p) { if (*p != 0xdeadbeef) { - Dbprintf(" Max stack usage......... %d / %d bytes", _stack_end - (char *)p, _stack_end - _stack_start); + Dbprintf(" Max stack usage......... %d / %d bytes", (uint32_t)_stack_end - (uint32_t)p, (uint32_t)_stack_end - (uint32_t)_stack_start); break; } } @@ -256,9 +256,9 @@ void ReadMem(int addr) { /* osimage version information is linked in, cf commonutil.h */ /* bootrom version information is pointed to from _bootphase1_version_pointer */ -extern char _bootphase1_version_pointer[], _flash_start[], _flash_end[], __data_src_start__[]; +extern uint32_t _bootphase1_version_pointer[], _flash_start[], _flash_end[], __data_src_start__[]; #ifdef WITH_NO_COMPRESSION -extern char _bootrom_end[], _bootrom_start[], __os_size__[]; +extern uint32_t _bootrom_end[], _bootrom_start[], __os_size__[]; #endif static void SendVersion(void) { char temp[PM3_CMD_DATA_SIZE - 12]; /* Limited data payload in USB packets */ @@ -268,11 +268,13 @@ static void SendVersion(void) { * symbol _bootphase1_version_pointer, perform slight sanity checks on the * pointer, then use it. */ - char *bootrom_version = *(char **)_bootphase1_version_pointer; + // dummy casting to avoid "dereferencing type-punned pointer breaking strict-aliasing rules" errors + uint32_t bootrom_version_ptr = (uint32_t)_bootphase1_version_pointer; + char *bootrom_version = *(char **)(bootrom_version_ptr); strncat(VersionString, " [ "_YELLOW_("ARM")" ]\n", sizeof(VersionString) - strlen(VersionString) - 1); - if (bootrom_version < _flash_start || bootrom_version >= _flash_end) { + if ((uint32_t)bootrom_version < (uint32_t)_flash_start || (uint32_t)bootrom_version >= (uint32_t)_flash_end) { strcat(VersionString, "bootrom version information appears invalid\n"); } else { FormatVersionInformation(temp, sizeof(temp), " bootrom: ", bootrom_version); @@ -300,7 +302,7 @@ static void SendVersion(void) { } #ifndef WITH_NO_COMPRESSION // Send Chip ID and used flash memory - uint32_t text_and_rodata_section_size = __data_src_start__ - _flash_start; + uint32_t text_and_rodata_section_size = (uint32_t)__data_src_start__ - (uint32_t)_flash_start; uint32_t compressed_data_section_size = common_area.arg1; #endif @@ -314,7 +316,7 @@ static void SendVersion(void) { struct p payload; payload.id = *(AT91C_DBGU_CIDR); #ifdef WITH_NO_COMPRESSION - payload.section_size = _bootrom_end - _bootrom_start + (uint32_t)__os_size__; + payload.section_size = (uint32_t)_bootrom_end - (uint32_t)_bootrom_start + (uint32_t)__os_size__; #else payload.section_size = text_and_rodata_section_size + compressed_data_section_size; #endif @@ -2439,7 +2441,7 @@ void __attribute__((noreturn)) AppMain(void) { SpinDelay(100); BigBuf_initialize(); - for (uint32_t *p = (uint32_t *)_stack_start; p < (uint32_t *)_stack_end - 0x200; ++p) { + for (uint32_t *p = _stack_start; p < _stack_end - 0x200; ++p) { *p = 0xdeadbeef; } @@ -2500,8 +2502,8 @@ void __attribute__((noreturn)) AppMain(void) { for (;;) { WDT_HIT(); - if (*((uint32_t *)_stack_start) != 0xdeadbeef) { - Dbprintf("Stack overflow detected! Please increase stack size, currently %d bytes", _stack_end - _stack_start); + if (*_stack_start != 0xdeadbeef) { + Dbprintf("Stack overflow detected! Please increase stack size, currently %d bytes", (uint32_t)_stack_end - (uint32_t)_stack_start); Dbprintf("Unplug your device now."); while (1); } diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index 67974c4c7..511958470 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -34,7 +34,7 @@ typedef lz4_stream *lz4_streamp; static int downloaded_bitstream = 0; // this is where the bitstreams are located in memory: -extern char _binary_obj_fpga_all_bit_z_start[], _binary_obj_fpga_all_bit_z_end[]; +extern uint32_t _binary_obj_fpga_all_bit_z_start[], _binary_obj_fpga_all_bit_z_end[]; static uint8_t *fpga_image_ptr = NULL; static uint32_t uncompressed_bytes_cnt; @@ -235,8 +235,8 @@ static bool reset_fpga_stream(int bitstream_version, lz4_streamp compressed_fpga uncompressed_bytes_cnt = 0; // initialize z_stream structure for inflate: - compressed_fpga_stream->next_in = _binary_obj_fpga_all_bit_z_start; - compressed_fpga_stream->avail_in = _binary_obj_fpga_all_bit_z_end - _binary_obj_fpga_all_bit_z_start; + compressed_fpga_stream->next_in = (char *)_binary_obj_fpga_all_bit_z_start; + compressed_fpga_stream->avail_in = (uint32_t)_binary_obj_fpga_all_bit_z_end - (uint32_t)_binary_obj_fpga_all_bit_z_start; int res = LZ4_setStreamDecode(compressed_fpga_stream->lz4StreamDecode, NULL, 0); if (res == 0) diff --git a/armsrc/start.c b/armsrc/start.c index f6a3fd1de..65d24ff5d 100644 --- a/armsrc/start.c +++ b/armsrc/start.c @@ -21,16 +21,16 @@ #include "string.h" extern struct common_area common_area; -extern char __data_src_start__[], __data_start__[], __data_end__[], __bss_start__[], __bss_end__[]; +extern uint32_t __data_src_start__[], __data_start__[], __data_end__[], __bss_start__[], __bss_end__[]; #ifndef WITH_NO_COMPRESSION static void uncompress_data_section(void) { int avail_in; memcpy(&avail_in, __data_src_start__, sizeof(int)); - int avail_out = __data_end__ - __data_start__; // uncompressed size. Correct. + int avail_out = (uint32_t)__data_end__ - (uint32_t)__data_start__; // uncompressed size. Correct. // uncompress data segment to RAM - char *p = __data_src_start__; - int res = LZ4_decompress_safe(p + 4, __data_start__, avail_in, avail_out); + char *p = (char *)__data_src_start__; + int res = LZ4_decompress_safe(p + 4, (char *)__data_start__, avail_in, avail_out); if (res < 0) return; @@ -53,15 +53,15 @@ void Vector(void) { /* Set up data segment: Copy from flash to ram */ #ifdef WITH_NO_COMPRESSION - char *data_src = __data_src_start__; - char *data_dst = __data_start__; + uint32_t *data_src = __data_src_start__; + uint32_t *data_dst = __data_start__; while (data_dst < __data_end__) *data_dst++ = *data_src++; #else uncompress_data_section(); #endif /* Set up (that is: clear) BSS. */ - char *bss_dst = __bss_start__; + uint32_t *bss_dst = __bss_start__; while (bss_dst < __bss_end__) *bss_dst++ = 0; AppMain(); diff --git a/bootrom/bootrom.c b/bootrom/bootrom.c index 0aa34c0d1..0cf135fa0 100644 --- a/bootrom/bootrom.c +++ b/bootrom/bootrom.c @@ -15,7 +15,7 @@ struct common_area common_area __attribute__((section(".commonarea"))); uint32_t start_addr, end_addr; bool bootrom_unlocked; -extern char _bootrom_start[], _bootrom_end[], _flash_start[], _flash_end[], _osimage_entry[]; +extern uint32_t _bootrom_start[], _bootrom_end[], _flash_start[], _flash_end[], _osimage_entry[]; static int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) { PacketResponseOLD txcmd; @@ -116,7 +116,7 @@ static void UsbPacketReceived(uint8_t *packet) { uint32_t flash_address = arg0 + (0x100 * j); AT91PS_EFC efc_bank = AT91C_BASE_EFC0; int offset = 0; - uint32_t page_n = (flash_address - ((uint32_t)_flash_start)) / AT91C_IFLASH_PAGE_SIZE; + uint32_t page_n = (flash_address - (uint32_t)_flash_start) / AT91C_IFLASH_PAGE_SIZE; if (page_n >= AT91C_IFLASH_NB_OF_PAGES / 2) { page_n -= AT91C_IFLASH_NB_OF_PAGES / 2; efc_bank = AT91C_BASE_EFC1; @@ -124,7 +124,7 @@ static void UsbPacketReceived(uint8_t *packet) { offset = (AT91C_IFLASH_NB_OF_PAGES / 2) * AT91C_IFLASH_PAGE_SIZE / sizeof(uint32_t); } for (int i = 0 + (64 * j); i < 64 + (64 * j); i++) { - ((uint32_t *)_flash_start)[offset + i] = c->d.asDwords[i]; + _flash_start[offset + i] = c->d.asDwords[i]; } /* Check that the address that we are supposed to write to is within our allowed region */ @@ -319,7 +319,7 @@ void BootROM(void) { if ((common_area.command == COMMON_AREA_COMMAND_ENTER_FLASH_MODE) || (!common_area.flags.button_pressed && BUTTON_PRESS()) || - (*(uint32_t *)_osimage_entry == 0xffffffffU)) { + (*_osimage_entry == 0xffffffffU)) { flash_mode(); } else { // clear button status, even if button still pressed