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

celt/speex fails to build with _FORTIFY_SOURCE=2 #13544

Closed
lazka opened this issue Oct 13, 2022 · 5 comments
Closed

celt/speex fails to build with _FORTIFY_SOURCE=2 #13544

lazka opened this issue Oct 13, 2022 · 5 comments

Comments

@lazka
Copy link
Member

lazka commented Oct 13, 2022

to clarify: celt builds fine for all envs without any modification. Forcing _FORTIFY_SOURCE results in this error:

Using:

diff --git a/mingw-w64-celt/PKGBUILD b/mingw-w64-celt/PKGBUILD
index a1e1c7d8e..6970acc67 100644
--- a/mingw-w64-celt/PKGBUILD
+++ b/mingw-w64-celt/PKGBUILD
@@ -24,6 +24,8 @@ prepare() {
 build() {
   export lt_cv_deplibs_check_method='pass_all'

+  export CFLAGS+=" -D_FORTIFY_SOURCE=2"
+
   [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
   mkdir -p "${srcdir}/build-${MINGW_CHOST}"
   cd "${srcdir}/build-${MINGW_CHOST}"
$ MINGW_ARCH=mingw64 makepkg-mingw -Csfr --noconfirm --nocheck
...
In file included from ../../celt-0.11.3/tools/celtdec.c:53:
C:/msys64/mingw64/include/io.h: In function '_open':
C:/msys64/mingw64/include/io.h:407:7: error: invalid use of '__builtin_va_arg_pack_len ()'
  407 |   if (__builtin_va_arg_pack_len() > 1)
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:408:12: error: invalid use of '__builtin_va_arg_pack ()'
  408 |     return __mingw_call__open_warn_toomany(__filename, __flags, __builtin_va_arg_pack());
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:413:10: error: invalid use of '__builtin_va_arg_pack ()'
  413 |   return __mingw_call__open(__filename, __flags, __builtin_va_arg_pack());
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h: In function '_sopen':
C:/msys64/mingw64/include/io.h:425:7: error: invalid use of '__builtin_va_arg_pack_len ()'
  425 |   if (__builtin_va_arg_pack_len() > 1)
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:426:12: error: invalid use of '__builtin_va_arg_pack ()'
  426 |     return __mingw_call__sopen_warn_toomany(__filename, __flags, __share, __builtin_va_arg_pack());
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:431:10: error: invalid use of '__builtin_va_arg_pack ()'
  431 |   return __mingw_call__sopen(__filename, __flags, __share, __builtin_va_arg_pack());
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h: In function '_wopen':
C:/msys64/mingw64/include/io.h:443:7: error: invalid use of '__builtin_va_arg_pack_len ()'
  443 |   if (__builtin_va_arg_pack_len() > 1)
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:444:12: error: invalid use of '__builtin_va_arg_pack ()'
  444 |     return __mingw_call__wopen_warn_toomany(__filename, __flags, __builtin_va_arg_pack());
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:449:10: error: invalid use of '__builtin_va_arg_pack ()'
  449 |   return __mingw_call__wopen(__filename, __flags, __builtin_va_arg_pack());
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h: In function '_wsopen':
C:/msys64/mingw64/include/io.h:461:7: error: invalid use of '__builtin_va_arg_pack_len ()'
  461 |   if (__builtin_va_arg_pack_len() > 1)
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:462:12: error: invalid use of '__builtin_va_arg_pack ()'
  462 |     return __mingw_call__wsopen_warn_toomany(__filename, __flags, __share, __builtin_va_arg_pack());
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:467:10: error: invalid use of '__builtin_va_arg_pack ()'
  467 |   return __mingw_call__wsopen(__filename, __flags, __share, __builtin_va_arg_pack());
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function '_open',
    inlined from 'open' at C:/msys64/mingw64/include/io.h:474:10:
C:/msys64/mingw64/include/io.h:407:7: error: invalid use of '__builtin_va_arg_pack_len ()'
  407 |   if (__builtin_va_arg_pack_len() > 1)
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:408:12: error: invalid use of '__builtin_va_arg_pack ()'
  408 |     return __mingw_call__open_warn_toomany(__filename, __flags, __builtin_va_arg_pack());
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:413:10: error: invalid use of '__builtin_va_arg_pack ()'
  413 |   return __mingw_call__open(__filename, __flags, __builtin_va_arg_pack());
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function '_sopen',
    inlined from 'sopen' at C:/msys64/mingw64/include/io.h:480:10:
C:/msys64/mingw64/include/io.h:425:7: error: invalid use of '__builtin_va_arg_pack_len ()'
  425 |   if (__builtin_va_arg_pack_len() > 1)
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:426:12: error: invalid use of '__builtin_va_arg_pack ()'
  426 |     return __mingw_call__sopen_warn_toomany(__filename, __flags, __share, __builtin_va_arg_pack());
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/io.h:431:10: error: invalid use of '__builtin_va_arg_pack ()'
  431 |   return __mingw_call__sopen(__filename, __flags, __share, __builtin_va_arg_pack());
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [Makefile:370: celtdec.o] Error 1
@lazka
Copy link
Member Author

lazka commented Oct 14, 2022

This comes down to:

// a.c
#include <io.h>
$ gcc -c a.c -D_FORTIFY_SOURCE=2 -O2
In file included from a.c:4:
C:/msys64/ucrt64/include/io.h: In function '_open':
C:/msys64/ucrt64/include/io.h:407:7: error: invalid use of '__builtin_va_arg_pack_len ()'
  407 |   if (__builtin_va_arg_pack_len() > 1)
...

@mstorsjo
Copy link
Contributor

This comes down to:

// a.c
#include <io.h>
$ gcc -c a.c -D_FORTIFY_SOURCE=2 -O2
In file included from a.c:4:
C:/msys64/ucrt64/include/io.h: In function '_open':
C:/msys64/ucrt64/include/io.h:407:7: error: invalid use of '__builtin_va_arg_pack_len ()'
  407 |   if (__builtin_va_arg_pack_len() > 1)
...

Now this is weird. I tried this in an UCRT64 environment (fully upgraded) and I don't get any error with this input file and this exact command. Is there perhaps some file that does get included optionally if it exists (and/or gets included before some other file, if some package is installed), changing how things behave in your case?

Can you get me the output of gcc a.c -D_FORTIFY_SOURCE=2 -O2 -E -dD? Then I can compare that with the output from my installation, and see what differs.

@lazka
Copy link
Member Author

lazka commented Oct 15, 2022

uh, you're right, I mixed things up somehow, sorry:

#define __attribute__(x)
#include <io.h>

which comes from https://gitlab.xiph.org/xiph/celt/-/blob/e18de7747fb1655e66bf8d291560587036bfe53c/tools/wave_out.h#L73
same for speex: https://gitlab.xiph.org/xiph/speex/-/blob/5b036b2ca5e27004502e67ee20490a16f5e68aa1/src/wave_out.h#L45

so that's kinda expected to fail I guess. Those files are only included under Windows, so the code was likely trying to port to MSVC via macro hackery without taking mingw into account.

I'll try to fix this upstream.

@lazka lazka closed this as completed Oct 15, 2022
@lazka lazka changed the title celt fails to build with _FORTIFY_SOURCE=2 celt/speex fails to build with _FORTIFY_SOURCE=2 Oct 15, 2022
@mstorsjo
Copy link
Contributor

uh, you're right, I mixed things up somehow, sorry:

#define __attribute__(x)
#include <io.h>

Oh - no wonder that will break, yeah. I think I've run into such code elsewhere at some other point too. By doing that, essentially all bets are off how things work - it's a wonder nothing else has broken so far.

so that's kinda expected to fail I guess. Those files are only included under Windows, so the code was likely trying to port to MSVC via macro hackery without taking mingw into account.

Yup, that sounds plausible. Thanks for fixing!

@lazka
Copy link
Member Author

lazka commented Oct 16, 2022

I've created two MRs upstream:

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