riscv-collab / riscv-openocd

Fork of OpenOCD that has RISC-V support
Other
452 stars 328 forks source link

Error building riscv-openocd #771

Closed everetto89 closed 1 year ago

everetto89 commented 1 year ago

Hi,

when I try to build the riscv-openocd I get the following error:

src/jtag/drivers/arm-jtag-ew.c: In function ‘armjtagew_debug_buffer’:
src/jtag/drivers/arm-jtag-ew.c:796:22: error: ‘%04x’ directive output may be truncated writing between 4 and 8 bytes into a region of size 5 [-Werror=format-truncation=]
   snprintf(line, 5, "%04x", i);
                      ^~~~
src/jtag/drivers/arm-jtag-ew.c:796:21: note: directive argument in the range [0, 2147483632]
   snprintf(line, 5, "%04x", i);
                     ^~~~~~
In file included from /usr/include/stdio.h:862:0,
                 from ./jimtcl/jim.h:74,
                 from ./src/helper/jim-nvp.h:47,
                 from ./src/helper/command.h:28,
                 from ./src/helper/log.h:28,
                 from ./src/jtag/jtag.h:26,
                 from ./src/jtag/interface.h:28,
                 from src/jtag/drivers/arm-jtag-ew.c:23:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 5 and 9 bytes into a destination of size 5
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Makefile:3437: recipe for target 'src/jtag/drivers/src_jtag_drivers_libocdjtagdrivers_la-arm-jtag-ew.lo' failed
make[2]: *** [src/jtag/drivers/src_jtag_drivers_libocdjtagdrivers_la-arm-jtag-ew.lo] Error 1
make[2]: Leaving directory '/home/user/RISC_V/riscv-openocd'
Makefile:4577: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/user/RISC_V/riscv-openocd'
Makefile:1679: recipe for target 'all' failed
make: *** [all] Error 2

Can you please help here?

Best regards, Christian

TommyMurphyTM1234 commented 1 year ago

Please list the clone, configure, and make commands that you use, details of the platform and tools used, and the build log.

TommyMurphyTM1234 commented 1 year ago

Compiles fine for me on Zorin OS Lite 16.2 (Ubuntu 20.04 LTS derivative) with all current updates applied.

lsb_release -a
No LSB modules are available.
Distributor ID: Zorin
Description:    Zorin OS 16.2
Release:    16
Codename:   focal

gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

cd ~/Downloads
git clone --recursive https://github.com/riscv/riscv-openocd
cd riscv-openocd
sudo apt install libusb-1.0-0-dev
./bootstrap
./configure --prefix=`pwd`/installed-tools --enable-armjtagew

libjaylink configuration summary:
 - Package version ................ 0.2.0
 - Library version ................ 1:0:1
 - Installation prefix ............ /home/tommy/Downloads/riscv-openocd/installed-openocd
 - Building on .................... x86_64-pc-linux-gnu
 - Building for ................... x86_64-pc-linux-gnu

Enabled transports:
 - USB ............................ yes
 - TCP ............................ yes

OpenOCD configuration summary
--------------------------------------------------
MPSSE mode of FTDI based devices        yes (auto)
cJTAG (OScan1, JScan3) tunneled thru MPSSEyes (auto)
ST-Link Programmer                      yes (auto)
TI ICDI JTAG Programmer                 yes (auto)
Keil ULINK JTAG Programmer              yes (auto)
Altera USB-Blaster II Compatible        yes (auto)
Bitbang mode of FT232R based devices    yes (auto)
Versaloon-Link JTAG Programmer          yes (auto)
TI XDS110 Debug Probe                   yes (auto)
CMSIS-DAP v2 Compliant Debugger         yes (auto)
OSBDM (JTAG only) Programmer            yes (auto)
eStick/opendous JTAG Programmer         yes (auto)
Olimex ARM-JTAG-EW Programmer           yes
Raisonance RLink JTAG Programmer        yes (auto)
USBProg JTAG Programmer                 yes (auto)
Andes JTAG Programmer (deprecated)      no
CMSIS-DAP Compliant Debugger            no
Nu-Link Programmer                      no
Cypress KitProg Programmer              no
Altera USB-Blaster Compatible           no
ASIX Presto Adapter                     no
OpenJTAG Adapter                        no
Linux GPIO bitbang through libgpiod     no
SEGGER J-Link Programmer                yes (auto)
Bus Pirate                              yes (auto)
Use Capstone disassembly framework      yes (auto)

make install
...
make  install-data-hook
make[4]: Entering directory '/home/tommy/Downloads/riscv-openocd'
for i in $(find ./tcl -name '*.cfg' -o -name '*.tcl' -o -name '*.txt' | sed -e 's,^./tcl,,'); do \
    j="/home/tommy/Downloads/riscv-openocd/installed-openocd/share/openocd/scripts/$i" && \
    mkdir -p "$(dirname $j)" && \
    /usr/bin/install -c -m 644 ./tcl/$i $j; \
done
make[4]: Leaving directory '/home/tommy/Downloads/riscv-openocd'
make[3]: Leaving directory '/home/tommy/Downloads/riscv-openocd'
make[2]: Leaving directory '/home/tommy/Downloads/riscv-openocd'
make[1]: Leaving directory '/home/tommy/Downloads/riscv-openocd'
TommyMurphyTM1234 commented 1 year ago

Any update @everetto89?

TommyMurphyTM1234 commented 1 year ago

Candidate for closure - not reproducible?

everetto89 commented 1 year ago

Hi @TommyMurphyTM1234, here is my configuration:

./configure --enable-verbose --enable-dummy --enable-ftdi --enable-ftdi-cjtag --enable-stlink --enable-ulink --enable-usb-blaster-2 --enable-ft232r --enable-cmsis-dap-v2 --enable-usbprog --enable-cmsis-dap --enable-nulink --enable-usb-blaster --enable-openjtag --enable-jlink --enable-remote-bitbang

Which results in the following Configuration summary:

OpenOCD configuration summary
--------------------------------------------------
MPSSE mode of FTDI based devices        yes
cJTAG (OScan1, JScan3) tunneled thru MPSSEyes
ST-Link Programmer                      yes
TI ICDI JTAG Programmer                 yes (auto)
Keil ULINK JTAG Programmer              yes
Altera USB-Blaster II Compatible        yes
Bitbang mode of FT232R based devices    yes
Versaloon-Link JTAG Programmer          yes (auto)
TI XDS110 Debug Probe                   yes (auto)
CMSIS-DAP v2 Compliant Debugger         yes
OSBDM (JTAG only) Programmer            yes (auto)
eStick/opendous JTAG Programmer         yes (auto)
Olimex ARM-JTAG-EW Programmer           yes (auto)
Raisonance RLink JTAG Programmer        yes (auto)
USBProg JTAG Programmer                 yes
Andes JTAG Programmer (deprecated)      no
CMSIS-DAP Compliant Debugger            yes
Nu-Link Programmer                      yes
Cypress KitProg Programmer              yes (auto)
Altera USB-Blaster Compatible           yes
ASIX Presto Adapter                     yes (auto)
OpenJTAG Adapter                        yes
Linux GPIO bitbang through libgpiod     no
SEGGER J-Link Programmer                yes
Bus Pirate                              yes (auto)
Use Capstone disassembly framework      no

I'm using a fresh clone, git log shows me that I try to build on the following commit:

commit b337b0cfb4612c0474c109abeb511189bfd5559c (HEAD -> riscv, origin/riscv, origin/HEAD)
Author: Dolu1990 <charles.papon.90@gmail.com>
Date:   Fri Dec 2 18:38:40 2022 +0100

Can you help here?

TommyMurphyTM1234 commented 1 year ago

Hi @TommyMurphyTM1234, here is my configuration:

You haven't provided the other stuff that I mentioned above:

Please list the clone, configure, and make commands that you use, details of the platform and tools used, and the build log.

I will try your configuration on my Zorin OS machine later when I get a chance.

TommyMurphyTM1234 commented 1 year ago

OK - when I use your configure command I can reproduce it. But I can also reproduce it when I clone from the upstream OpenOCD repository:

https://openocd.org/pages/repos.html

So I think that it probably needs to be reported there since it's not a RISC-V specific issue relevant to the focus of this particular repo - namely, adding RISC-V support?

https://openocd.org/pages/bug-tracker.html

Edit: this OpenOCD-dev mailing list thread seems to be about the same issue but seems to have petered out with no conclusion or concrete action:

https://sourceforge.net/p/openocd/mailman/openocd-devel/thread/20200707144105.180F3819F79D%40turkos.aspodata.se/#msg37055434

TommyMurphyTM1234 commented 1 year ago

A workaround, unless you explicitly need these two specific debug interfaces, is to add the following to your configure command and then build: --disable-armjtagew --disable-opendous. Both Olimex ARM-JTAG-EW Programmer and eStick/opendous JTAG Programmer suffer from the same compilation error.

However, I don't understand why the error doesn't occur when when no --enable-<interface> options are passed to configure but support for these interfaces is enabled and compiled by default...

TommyMurphyTM1234 commented 1 year ago

It's very odd - whether I pass the various --enable-<interface> options to configure or pass none, the compilation commands for arm-jtag-ew.c seem to be identical and yet, in the former case we get the compilation error but in the latter we do not...

./configure --enable-verbose --enable-dummy --enable-ftdi --enable-ftdi-cjtag --enable-stlink --enable-ulink --enable-usb-blaster-2 --enable-ft232r --enable-cmsis-dap-v2 --enable-usbprog --enable-cmsis-dap --enable-nulink --enable-usb-blaster --enable-openjtag --enable-jlink --enable-remote-bitbang --prefix=`pwd`/installed-tools
make
...
/bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.   -I./src -I./src -DPKGDATADIR=\"/home/tommy/Downloads/riscv-openocd/installed-tools/share/openocd\" -DBINDIR=\"/home/tommy/Downloads/riscv-openocd/installed-tools/bin\" -DFD_SETSIZE=128 -I./jimtcl -I./jimtcl -isystem /usr/include/libusb-1.0 -I/usr/include/libftdi1 -I/usr/include/libusb-1.0  -I/usr/include/hidapi  -I./src/jtag/drivers/libjaylink/libjaylink -I./src/jtag/drivers/libjaylink  -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Wno-error=deprecated-declarations -Werror -DFD_SETSIZE=128 -g -O2 -MT src/jtag/drivers/libocdjtagdrivers_la-arm-jtag-ew.lo -MD -MP -MF src/jtag/drivers/.deps/libocdjtagdrivers_la-arm-jtag-ew.Tpo -c -o src/jtag/drivers/libocdjtagdrivers_la-arm-jtag-ew.lo `test -f 'src/jtag/drivers/arm-jtag-ew.c' || echo './'`src/jtag/drivers/arm-jtag-ew.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I./src -I./src -DPKGDATADIR=\"/home/tommy/Downloads/riscv-openocd/installed-tools/share/openocd\" -DBINDIR=\"/home/tommy/Downloads/riscv-openocd/installed-tools/bin\" -DFD_SETSIZE=128 -I./jimtcl -I./jimtcl -isystem /usr/include/libusb-1.0 -I/usr/include/libftdi1 -I/usr/include/libusb-1.0 -I/usr/include/hidapi -I./src/jtag/drivers/libjaylink/libjaylink -I./src/jtag/drivers/libjaylink -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Wno-error=deprecated-declarations -Werror -DFD_SETSIZE=128 -g -O2 -MT src/jtag/drivers/libocdjtagdrivers_la-arm-jtag-ew.lo -MD -MP -MF src/jtag/drivers/.deps/libocdjtagdrivers_la-arm-jtag-ew.Tpo -c src/jtag/drivers/arm-jtag-ew.c -o src/jtag/drivers/libocdjtagdrivers_la-arm-jtag-ew.o
src/jtag/drivers/arm-jtag-ew.c: In function ‘armjtagew_debug_buffer’:
src/jtag/drivers/arm-jtag-ew.c:796:22: error: ‘%04x’ directive output may be truncated writing between 4 and 8 bytes into a region of size 5 [-Werror=format-truncation=]
  796 |   snprintf(line, 5, "%04x", i);
      |                      ^~~~
src/jtag/drivers/arm-jtag-ew.c:796:21: note: directive argument in the range [0, 2147483632]
  796 |   snprintf(line, 5, "%04x", i);
      |                     ^~~~~~
In file included from /usr/include/stdio.h:867,
                 from ./jimtcl/jim.h:74,
                 from ./src/helper/jim-nvp.h:47,
                 from ./src/helper/command.h:28,
                 from ./src/helper/log.h:28,
                 from ./src/jtag/jtag.h:26,
                 from ./src/jtag/interface.h:28,
                 from src/jtag/drivers/arm-jtag-ew.c:23:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: ‘__builtin___snprintf_chk’ output between 5 and 9 bytes into a destination of size 5
   67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:3680: src/jtag/drivers/libocdjtagdrivers_la-arm-jtag-ew.lo] Error 1
make[2]: Leaving directory '/home/tommy/Downloads/riscv-openocd'
make[1]: *** [Makefile:4820: all-recursive] Error 1
make[1]: Leaving directory '/home/tommy/Downloads/riscv-openocd'
./configure --prefix=`pwd`/installed-tools
make
...
/bin/bash ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.   -I./src -I./src -DPKGDATADIR=\"/home/tommy/Downloads/riscv-openocd/installed-tools/share/openocd\" -DBINDIR=\"/home/tommy/Downloads/riscv-openocd/installed-tools/bin\" -DFD_SETSIZE=128 -I./jimtcl -I./jimtcl -isystem /usr/include/libusb-1.0 -I/usr/include/libftdi1 -I/usr/include/libusb-1.0  -I/usr/include/hidapi  -I./src/jtag/drivers/libjaylink/libjaylink -I./src/jtag/drivers/libjaylink  -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Wno-error=deprecated-declarations -Werror -DFD_SETSIZE=128 -g -O2 -MT src/jtag/drivers/libocdjtagdrivers_la-arm-jtag-ew.lo -MD -MP -MF src/jtag/drivers/.deps/libocdjtagdrivers_la-arm-jtag-ew.Tpo -c -o src/jtag/drivers/libocdjtagdrivers_la-arm-jtag-ew.lo `test -f 'src/jtag/drivers/arm-jtag-ew.c' || echo './'`src/jtag/drivers/arm-jtag-ew.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I./src -I./src -DPKGDATADIR=\"/home/tommy/Downloads/riscv-openocd/installed-tools/share/openocd\" -DBINDIR=\"/home/tommy/Downloads/riscv-openocd/installed-tools/bin\" -DFD_SETSIZE=128 -I./jimtcl -I./jimtcl -isystem /usr/include/libusb-1.0 -I/usr/include/libftdi1 -I/usr/include/libusb-1.0 -I/usr/include/hidapi -I./src/jtag/drivers/libjaylink/libjaylink -I./src/jtag/drivers/libjaylink -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Wno-error=deprecated-declarations -Werror -DFD_SETSIZE=128 -g -O2 -MT src/jtag/drivers/libocdjtagdrivers_la-arm-jtag-ew.lo -MD -MP -MF src/jtag/drivers/.deps/libocdjtagdrivers_la-arm-jtag-ew.Tpo -c src/jtag/drivers/arm-jtag-ew.c -o src/jtag/drivers/libocdjtagdrivers_la-arm-jtag-ew.o
mv -f src/jtag/drivers/.deps/libocdjtagdrivers_la-arm-jtag-ew.Tpo src/jtag/drivers/.deps/libocdjtagdrivers_la-arm-jtag-ew.Plo
TommyMurphyTM1234 commented 1 year ago

OK - the --enable-<interface> options are a red herring. The issue is that when --enable-verbose is specified to configure then code that triggers the compilation error is enabled in arm-jtag-ew.c and opendous.c.

TommyMurphyTM1234 commented 1 year ago

Changing the code in arm-jtag-ew.c and opendous.c as follows eliminates the compilation error but I'm not yet sure if it's the "correct" fix. I'll try to follow up on it upstream.

    char line[81];
    char s[4];
        /* int i; --> change this to uint16_t */
    uint16_t i;**
    int j;

    for (i = 0; i < length; i += BYTES_PER_LINE) {
        snprintf(line, 5, "%04x", i);
TommyMurphyTM1234 commented 1 year ago

I've logged an OpenOCD ticket upstream here: https://sourceforge.net/p/openocd/tickets/376/

borneoa commented 1 year ago

Please check https://review.openocd.org/7403/ @everetto89 I can add also you as Reported-by in the commit message, but I would need your email contact

TommyMurphyTM1234 commented 1 year ago

A workaround, unless you explicitly need these two specific debug interfaces, is to add the following to your configure command and then build: --disable-armjtagew --disable-opendous. Both Olimex ARM-JTAG-EW Programmer and eStick/opendous JTAG Programmer suffer from the same compilation error.

A simpler workaround is to omit --enable-verbose when invoking configure.

TommyMurphyTM1234 commented 1 year ago

Please check https://review.openocd.org/7403/ @everetto89 I can add also you as Reported-by in the commit message, but I would need your email contact

Thanks a lot @borneoa for the quick response - I've followed up over there.

TommyMurphyTM1234 commented 1 year ago

@borneoa's change to address this issue seems to have been merged upstream so I guess that this issue here can be closed and next time the RISC-V OpenOCD fork is sync'd with upstream OpenOCD the fix will appear here. In the meantime he change can be manually applied here if needed.

TommyMurphyTM1234 commented 1 year ago

Candidate for closure?