Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error with tinydir inlining #838

Open
reinerh opened this issue Feb 17, 2024 · 7 comments
Open

Build error with tinydir inlining #838

reinerh opened this issue Feb 17, 2024 · 7 comments

Comments

@reinerh
Copy link
Contributor

reinerh commented Feb 17, 2024

On Ubuntu build servers the build fails with this error:

[ 32%] Building C object src/cdogs/CMakeFiles/cdogs.dir/campaigns.c.o
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src/cdogs && /usr/bin/cc -DSTATIC -I/<<PKGBUILDDIR>>/src -I/<<PKGBUILDDIR>>/src/cdogs -I/<<PKGBUILDDIR>>/src/. -I/<<PKGBUILDDIR>>/src/proto/nanopb -I/<<PKGBUILDDIR>>/src/cdogs/.. -isystem /usr/include/SDL2 -g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/<<PKGBUILDDIR>>=/usr/src/cdogs-sdl-1.5.0+dfsg-1 -Wdate-time -D_FORTIFY_SOURCE=3 -I/usr/include/nanopb -g   -fsigned-char -Wall -W -Wstrict-prototypes -Wpointer-arith -Wcast-qual -g -freg-struct-return -std=gnu99 -Wshadow -Wimplicit-fallthrough=0 -Wno-error=format-overflow -Winline -Werror -MD -MT src/cdogs/CMakeFiles/cdogs.dir/campaigns.c.o -MF CMakeFiles/cdogs.dir/campaigns.c.o.d -o CMakeFiles/cdogs.dir/campaigns.c.o -c /<<PKGBUILDDIR>>/src/cdogs/campaigns.c
In file included from /<<PKGBUILDDIR>>/src/cdogs/campaigns.c:33:
In function ‘tinydir_open_sorted’,
    inlined from ‘LoadCampaignsFromFolder’ at /<<PKGBUILDDIR>>/src/cdogs/campaigns.c:248:6:
/<<PKGBUILDDIR>>/src/tinydir/tinydir.h:265:5: error: inlining failed in call to ‘tinydir_open’: --param max-inline-insns-single limit reached [-Werror=inline]
  265 | int tinydir_open(tinydir_dir *dir, const _tinydir_char_t *path)
      |     ^~~~~~~~~~~~
/<<PKGBUILDDIR>>/src/tinydir/tinydir.h:360:13: note: called from here
  360 |         if (tinydir_open(dir, path) == -1)
      |             ^~~~~~~~~~~~~~~~~~~~~~~
/<<PKGBUILDDIR>>/src/tinydir/tinydir.h:265:5: error: inlining failed in call to ‘tinydir_open’: --param max-inline-insns-single limit reached [-Werror=inline]
  265 | int tinydir_open(tinydir_dir *dir, const _tinydir_char_t *path)
      |     ^~~~~~~~~~~~
/<<PKGBUILDDIR>>/src/tinydir/tinydir.h:374:29: note: called from here
  374 |         if (n_files == 0 || tinydir_open(dir, path) == -1)
      |                             ^~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[3]: *** [src/cdogs/CMakeFiles/cdogs.dir/build.make:331: src/cdogs/CMakeFiles/cdogs.dir/campaigns.c.o] Error 1

In CMakeLists.txt -Werror and -Winline are set:

add_definitions(-Winline -Werror)

tinydir_open is declared as:

_TINYDIR_FUNC
int tinydir_open(tinydir_dir *dir, const _tinydir_char_t *path);

where _TINYDIR_FUNC is:

# define _TINYDIR_FUNC static inline

I'm not sure why it fails on Ubuntu, but succeeds on Debian builds (and also on CI builds here on Github). (maybe related to --param max-inline-insns-single limit reached that could be different?)

Is there a reason why the build explicitely sets -Winline and upgrades these warnings to errors?

@cxong
Copy link
Owner

cxong commented Feb 18, 2024

we enable most warnings and set as error in order to be more strict. Is this something that can be fixed upstream in tinydir? Are its functions too big to inline?

@reinerh
Copy link
Contributor Author

reinerh commented Feb 18, 2024

I just compared the build flags between Debian and Ubuntu and found that the difference that causes the problem is -D_FORTIFY_SOURCE=. In Debian that is set to 2 and in Ubuntu to 3.
When I change it in the Debian build to 3, I get the same error.
I guess that with a better fortification the code is also getting a bit larger and it reaches the inlining instructions limit.
It probably should be addressed in tinydir upstream. For the cdogs-sdl package, I'll check if I can raise the limit.

@reinerh
Copy link
Contributor Author

reinerh commented Feb 18, 2024

When I raise the inlining limit (-finline-limit=1000), the build continues but fails later with:

src/cdogs/utils.c: In function ‘RelPathFromCWD’:
src/cdogs/utils.c:152:17: error: ‘__builtin___strncat_chk’ output may be truncated copying 4095 bytes from a string of length 4095 [-Werror=stringop-truncation]
  152 |                 strncat(srcBuf, src, CDOGS_PATH_MAX - 1);
      |                 ^
src/cdogs/utils.c: In function ‘GetDataFilePath’:
src/cdogs/utils.c:152:17: error: ‘__builtin___strncat_chk’ output may be truncated copying 4095 bytes from a string of length 4095 [-Werror=stringop-truncation]

(this check also seems to come from -D_FORTIFY_SOURCE=3)

When I ignore that with -Wno-stringop-truncation the build succeeds.

@cxong
Copy link
Owner

cxong commented Feb 25, 2024

which version of ubuntu/gcc runs into this error?

  • from build logs, it's ubuntu 20.04 gcc GNU 13.2.0

@reinerh
Copy link
Contributor Author

reinerh commented Feb 25, 2024

Yes, 13.2.0, same on Debian unstable.

@reinerh
Copy link
Contributor Author

reinerh commented Feb 26, 2024

After increasing the inline limit and ignoring stringop-truncation errors in the 2.0.0 Debian package, it also successfully built in Ubuntu and it made it just in time before the freeze for 24.04 LTS. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants