openocd-spi icon indicating copy to clipboard operation
openocd-spi copied to clipboard

Multiple compilation errors with GCC 10.2.1-1+rpi1 : fix discussion

Open Zorvalt opened this issue 2 years ago • 3 comments

There are compilation issues when using the latest gcc version on raspbian (currently 10.2.1-1+rpi1). To fix those errors, I was able to cherry-pick different commits but I had to fix the first one by hand because I got into a chain of emerging error due to dependency on older commits (see first error below).

I pushed everything on a fork, here : https://github.com/Zorvalt/openocd-spi/tree/fix-multiple-gcc-10-errors

I'd like to know if I should create a PR or not ? Maybe rebasing this repository on openocd-org/openocd would be better as the more time passes, the more it is likely that cherry-picking will be hard...


To explain what I changed, here is the list of errors I fixed without any special order :

‘status’ may be used uninitialized in this function

In file included from ./src/flash/common.h:21,
                 from src/flash/nor/core.h:25,
                 from src/flash/nor/imp.h:22,
                 from src/flash/nor/jtagspi.c:22:
src/flash/nor/jtagspi.c: In function ‘jtagspi_write_enable’:
./src/helper/log.h:133:2: error: ‘status’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  133 |  log_printf_lf(LOG_LVL_ERROR, __FILE__, __LINE__, __func__, expr)
      |  ^~~~~~~~~~~~~
src/flash/nor/jtagspi.c:262:11: note: ‘status’ was declared here
  262 |  uint32_t status;
      |           ^~~~~~
src/flash/nor/jtagspi.c: In function ‘jtagspi_wait’:
src/flash/nor/jtagspi.c:249:15: error: ‘status’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  249 |   if ((status & SPIFLASH_BSY_BIT) == 0) {
      |       ~~~~~~~~^~~~~~~~~~~~~~~~~~~

I fixed those by initializing status with (uint32_t)-1 like they did upstream : https://github.com/openocd-org/openocd/commit/be57b0ab847e8246b354ca9203024737cdec403b I did not cherry-pick the commit because it changes a lot more than needed and I do not have the time to fully review how it impacts the whole project.

Commit fixing this error : https://github.com/openocd-org/openocd/commit/be57b0ab847e8246b354ca9203024737cdec403b Applying it breaks some types comparisons like sector < bank->num_sectors in https://github.com/openocd-org/openocd/commit/be57b0ab847e8246b354ca9203024737cdec403b#diff-5e2e3ea9c2f7e815c40a02619a32e1f45d1dd8e3254bb380740f2f9097220f4aR283 This can in turn be fixed with https://github.com/openocd-org/openocd/commit/ef14384b681af4f731f768bb866457832af6925f which breaks other parts again and I stopped my investigations there in favor of a simple two line commit.


accessing N bytes in a region of size 8

src/target/arm920t.c: In function 'arm920t_read_cp15_interpreted.constprop':
src/target/arm920t.c:255:9: error: 'arm9tdmi_write_core_regs' accessing 64 bytes in a region of size 8 [-Werror=stringop-overflow=]
  255 |         arm9tdmi_write_core_regs(target, 0x2, regs);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/target/arm920t.c:255:9: note: referencing argument 3 of type 'uint32_t *' {aka 'unsigned int *'}
In file included from src/target/arm920t.h:22,
                 from src/target/arm920t.c:24:
src/target/arm9tdmi.h:40:6: note: in a call to function 'arm9tdmi_write_core_regs'
   40 | void arm9tdmi_write_core_regs(struct target *target,
      |      ^~~~~~~~~~~~~~~~~~~~~~~~
src/target/arm920t.c:273:9: error: 'arm9tdmi_read_core_regs' accessing 128 bytes in a region of size 8 [-Werror=stringop-overflow=]
  273 |         arm9tdmi_read_core_regs(target, 0x1, regs_p);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/target/arm920t.c:273:9: note: referencing argument 3 of type 'uint32_t **' {aka 'unsigned int **'}
In file included from src/target/arm920t.h:22,
                 from src/target/arm920t.c:24:
src/target/arm9tdmi.h:38:6: note: in a call to function 'arm9tdmi_read_core_regs'
   38 | void arm9tdmi_read_core_regs(struct target *target,
      |      ^~~~~~~~~~~~~~~~~~~~~~~
src/target/arm920t.c: In function 'arm920t_write_cp15_interpreted':
src/target/arm920t.c:304:9: error: 'arm9tdmi_write_core_regs' accessing 64 bytes in a region of size 8 [-Werror=stringop-overflow=]
  304 |         arm9tdmi_write_core_regs(target, 0x3, regs);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/target/arm920t.c:304:9: note: referencing argument 3 of type 'uint32_t *' {aka 'unsigned int *'}
In file included from src/target/arm920t.h:22,
                 from src/target/arm920t.c:24:
src/target/arm9tdmi.h:40:6: note: in a call to function 'arm9tdmi_write_core_regs'
   40 | void arm9tdmi_write_core_regs(struct target *target,
      |      ^~~~~~~~~~~~~~~~~~~~~~~~

Fixed by cherry-picking https://github.com/openocd-org/openocd/commit/6db49eb8858023654084088c73d968e190aec491


'ftdi_usb_purge_buffers' is deprecated

src/jtag/drivers/presto.c: In function 'presto_open_libftdi':
src/jtag/drivers/presto.c:163:9: error: 'ftdi_usb_purge_buffers' is deprecated [-Werror=deprecated-declarations]
  163 |         if (ftdi_usb_purge_buffers(&presto->ftdic) < 0) {
      |         ^~
In file included from src/jtag/drivers/presto.c:37:
/usr/include/libftdi1/ftdi.h:566:20: note: declared here
  566 |     int DEPRECATED(ftdi_usb_purge_buffers(struct ftdi_context *ftdi));
      |                    ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/libftdi1/ftdi.h:247:55: note: in definition of macro 'DEPRECATED'
  247 | #define DEPRECATED(func) __attribute__ ((deprecated)) func
      |                                                       ^~~~
src/jtag/drivers/presto.c:177:17: error: 'ftdi_usb_purge_buffers' is deprecated [-Werror=deprecated-declarations]
  177 |                 if (ftdi_usb_purge_buffers(&presto->ftdic) < 0)
      |                 ^~
In file included from src/jtag/drivers/presto.c:37:
/usr/include/libftdi1/ftdi.h:566:20: note: declared here
  566 |     int DEPRECATED(ftdi_usb_purge_buffers(struct ftdi_context *ftdi));
      |                    ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/libftdi1/ftdi.h:247:55: note: in definition of macro 'DEPRECATED'
  247 | #define DEPRECATED(func) __attribute__ ((deprecated)) func
      |                                                       ^~~~
src/jtag/drivers/openjtag.c: In function 'openjtag_init_standard':
src/jtag/drivers/openjtag.c:441:9: error: 'ftdi_usb_purge_buffers' is deprecated [-Werror=deprecated-declarations]
  441 |         if (ftdi_usb_purge_buffers(&ftdic) < 0) {
      |         ^~
In file included from src/jtag/drivers/openjtag.c:85:
/usr/include/libftdi1/ftdi.h:566:20: note: declared here
  566 |     int DEPRECATED(ftdi_usb_purge_buffers(struct ftdi_context *ftdi));
      |                    ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/libftdi1/ftdi.h:247:55: note: in definition of macro 'DEPRECATED'
  247 | #define DEPRECATED(func) __attribute__ ((deprecated)) func
      |                                                       ^~~~

Fixed by cherry-picking https://github.com/openocd-org/openocd/commit/5bb0f6befb3c3f06903cee93f14bdd917abf21e7


'out' may be used uninitialized

In file included from ./src/jtag/jtag.h:25,
                 from src/target/riscv/riscv-011.c:18:
In function 'buf_set_u64',
    inlined from 'buf_set_u64' at ./src/helper/binarybuffer.h:69:20,
    inlined from 'dbus_scan' at src/target/riscv/riscv-011.c:434:2:
./src/helper/binarybuffer.h:93:47: error: 'out' may be used uninitialized [-Werror=maybe-uninitialized]
   93 |                                 buffer[i / 8] &= ~(1 << (i % 8));
      |                                               ^~
src/target/riscv/riscv-011.c: In function 'dbus_scan':
src/target/riscv/riscv-011.c:425:17: note: 'out' declared here
  425 |         uint8_t out[8];
      |                 ^~~

Fixed by cherry-picking https://github.com/openocd-org/openocd/commit/a2e822834df52efef5e1bbcb91a6eb1afbf102db

Zorvalt avatar Mar 01 '22 17:03 Zorvalt