Uniformize source code ref and fix gcc 11.1 warning

Using "extern char linker_symbol[]" notation
cf https://sourceware.org/binutils/docs/ld/Source-Code-Reference.html
This commit is contained in:
Philippe Teuwen 2021-05-13 22:15:06 +02:00
commit 13a9afa36d
5 changed files with 29 additions and 32 deletions

View file

@ -70,7 +70,7 @@
int DBGLEVEL = DBG_ERROR;
uint8_t g_trigger = 0;
bool g_hf_field_active = false;
extern uint32_t _stack_start, _stack_end;
extern char _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,10 +240,9 @@ static uint32_t MeasureAntennaTuningLfData(void) {
}
void print_stack_usage(void) {
// pointer arithmetic is times 4. (two shifts to the left)
for (uint32_t *p = &_stack_start; ; ++p) {
for (uint32_t *p = (uint32_t *)_stack_start; ; ++p) {
if (*p != 0xdeadbeef) {
Dbprintf(" Max stack usage......... %d / %d bytes", (&_stack_end - p) << 2, (&_stack_end - &_stack_start) << 2);
Dbprintf(" Max stack usage......... %d / %d bytes", _stack_end - (char *)p, _stack_end - _stack_start);
break;
}
}
@ -257,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 char _bootphase1_version_pointer[], _flash_start[], _flash_end[], __data_src_start__[];
#ifdef WITH_NO_COMPRESSION
extern char *_bootrom_end, _bootrom_start, __os_size__;
extern char _bootrom_end[], _bootrom_start[], __os_size__[];
#endif
static void SendVersion(void) {
char temp[PM3_CMD_DATA_SIZE - 12]; /* Limited data payload in USB packets */
@ -269,11 +268,11 @@ 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;
char *bootrom_version = *(char **)_bootphase1_version_pointer;
strncat(VersionString, " [ "_YELLOW_("ARM")" ]\n", sizeof(VersionString) - strlen(VersionString) - 1);
if (bootrom_version < &_flash_start || bootrom_version >= &_flash_end) {
if (bootrom_version < _flash_start || bootrom_version >= _flash_end) {
strcat(VersionString, "bootrom version information appears invalid\n");
} else {
FormatVersionInformation(temp, sizeof(temp), " bootrom: ", bootrom_version);
@ -301,7 +300,7 @@ static void SendVersion(void) {
}
#ifndef WITH_NO_COMPRESSION
// Send Chip ID and used flash memory
uint32_t text_and_rodata_section_size = (uint32_t)&__data_src_start__ - (uint32_t)&_flash_start;
uint32_t text_and_rodata_section_size = __data_src_start__ - _flash_start;
uint32_t compressed_data_section_size = common_area.arg1;
#endif
@ -315,7 +314,7 @@ static void SendVersion(void) {
struct p payload;
payload.id = *(AT91C_DBGU_CIDR);
#ifdef WITH_NO_COMPRESSION
payload.section_size = (uint32_t)&_bootrom_end - (uint32_t)&_bootrom_start + (uint32_t)&__os_size__;
payload.section_size = _bootrom_end - _bootrom_start + (uint32_t)__os_size__;
#else
payload.section_size = text_and_rodata_section_size + compressed_data_section_size;
#endif
@ -2440,7 +2439,7 @@ void __attribute__((noreturn)) AppMain(void) {
SpinDelay(100);
BigBuf_initialize();
for (uint32_t *p = &_stack_start; p < (uint32_t *)((uintptr_t)&_stack_end - 0x200); ++p) {
for (uint32_t *p = (uint32_t *)_stack_start; p < (uint32_t *)_stack_end - 0x200; ++p) {
*p = 0xdeadbeef;
}
@ -2501,8 +2500,8 @@ void __attribute__((noreturn)) AppMain(void) {
for (;;) {
WDT_HIT();
if (_stack_start != 0xdeadbeef) {
Dbprintf("Stack overflow detected! Please increase stack size, currently %d bytes", (&_stack_end - &_stack_start) << 2);
if (*((uint32_t *)_stack_start) != 0xdeadbeef) {
Dbprintf("Stack overflow detected! Please increase stack size, currently %d bytes", _stack_end - _stack_start);
Dbprintf("Unplug your device now.");
while (1);
}