auerswal / ssocr

Seven Segment Optical Character Recognition
https://www.unix-ag.uni-kl.de/~auerswal/ssocr/index.html
GNU General Public License v3.0
202 stars 38 forks source link

Fails to build on Arm #15

Closed niczero closed 2 years ago

niczero commented 3 years ago

Upon invoking build, get the following error:

cc -D_FORTIFY_SOURCE=2 -Wall -W -Wextra -pedantic -Werror -pedantic-errors -fstack-protector-all  -O3   -c -o ssocr.o ssocr.c
In file included from /usr/include/string.h:495,
                 from ssocr.c:29:
In function ‘strncat’,
    inlined from ‘tmp_imgfile’ at ssocr.c:79:12,
    inlined from ‘main’ at ssocr.c:529:15:
/usr/include/arm-linux-gnueabihf/bits/string_fortified.h:136:10: error: ‘__builtin_strncat’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  136 |   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ssocr.c: In function ‘main’:
ssocr.c:67:19: note: length computed here
   67 |     pattern_len = strlen(dir) + strlen(DIR_SEP TMP_FILE_PATTERN) + 1;
      |                   ^~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [<builtin>: ssocr.o] Error 1

This is Debian v11.1 on Linux 5.10.63+ on armv61.

auerswal commented 3 years ago

Hi Nic,

as a quick update:

You should be able to work around this by removing the gcc hardening options. You can look at the "C Compiler Problems" section in INSTALL for a short description of this.

You should be able to work around this by commenting out the default CFLAGS definition and removing the comment sign in front of the minimal CFLAGS definition in the Makefile.

One simple way is to use sed:

sed -i '2s/^#//;4s/^/#/' Makefile

I plan to look into this some more to find a sensible solution.

The problem for this build error is that gcc warns that it cannot determine if the buffer size has been computed correctly.

See, e.g.: https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8#forming_truncated_strings_with_strncat

I'll most likely remove some of the hardening options from CFLAGS in the future to accomodate that gcc change.

Thanks, Erik

On Sun, Oct 24, 2021 at 02:43:53PM -0700, Nic Sandfield wrote:

Upon invoking build, get the following error:

cc -D_FORTIFY_SOURCE=2 -Wall -W -Wextra -pedantic -Werror -pedantic-errors -fstack-protector-all  -O3   -c -o ssocr.o ssocr.c
In file included from /usr/include/string.h:495,
                 from ssocr.c:29:
In function ‘strncat’,
    inlined from ‘tmp_imgfile’ at ssocr.c:79:12,
    inlined from ‘main’ at ssocr.c:529:15:
/usr/include/arm-linux-gnueabihf/bits/string_fortified.h:136:10: error: ‘__builtin_strncat’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  136 |   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ssocr.c: In function ‘main’:
ssocr.c:67:19: note: length computed here
   67 |     pattern_len = strlen(dir) + strlen(DIR_SEP TMP_FILE_PATTERN) + 1;
      |                   ^~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [<builtin>: ssocr.o] Error 1

This is Debian v11.1 on Linux 5.10.63+ on armv61.

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/auerswal/ssocr/issues/15

auerswal commented 3 years ago

I have just pushed a Makefile adjustment to enable building on an x86_64 Debian Bullseye (11) GNU/Linux system (in the git commit messages I call this Buster, my fault, I always meant Bullseye).

The fix is just to continue the build even though the compiler generated warnings.

In the past, fixing all compiler warnings did help me find and fix a few bugs. Those times are over, now. :-(

@niczero: Please let me know if this works on ARM, too, since I do not have an ARM test system readily available.

Thanks!

auerswal commented 3 years ago

I have just pushed some changes that include replacing strncat() with memcpy(). This compiles warning free on the x86_64 Debian 11 test system with GCC 10.

@niczero: Please let me know if this works on ARM, too, and if it produces any warnings there. Thanks!

I'll probably keep the removal of -Werror and -pedantic-errors, because I do not use or test the latest compilers, and do not want to cause unnecessary compilation failures due to dubious compiler warnings that I am in no position to "fix."

auerswal commented 2 years ago

I have just created a version 2.22.0 release that includes the GCC 10 compilation fix, tested on Debian 11.1.

I plan to close this issue soon, unless it turns out that there are additional problems on armv61.

auerswal commented 2 years ago

I am closing this issue now, because I have addressed the reported compilation problem and did not hear about further problems.

If there are still problems compiling ssocr on Debian v11.1 on armv61, please open a new issue.

Thanks!