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 failure on Arch Linux due to -Werror=format-security #1204

Open
awvwgk opened this issue Jan 9, 2022 · 3 comments
Open

Build failure on Arch Linux due to -Werror=format-security #1204

awvwgk opened this issue Jan 9, 2022 · 3 comments

Comments

@awvwgk
Copy link

awvwgk commented Jan 9, 2022

Trying to build the latest classic flang release (20211221) against LLVM 13 on Arch Linux leads to the following failure when compiling the classic flang driver:

[300/1624] Building CXX object tools/flang2/f...xe/CMakeFiles/flang2.dir/llassem_common.cpp.o
FAILED: tools/flang2/flang2exe/CMakeFiles/flang2.dir/llassem_common.cpp.o 
/usr/bin/clang++ -DGTEST_HAS_RTTI=0 -DIN_FLANG2 -DMMD -DNOVECTORIZE -DPGFLANG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/include -I/home/awvwgk/software/aur/classic-flang/src/build-flang-x86_64/include -I/home/awvwgk/software/aur/classic-flang/src/build-flang-x86_64/tools/flang2/include -I/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/shared -I/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/include/flang -I/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/lib/scutil -I/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe -I/home/awvwgk/software/aur/classic-flang/src/build-flang-x86_64/tools/flang2/flang2exe -I/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/x86_64 -I/home/awvwgk/software/aur/classic-flang/src/build-flang-x86_64/tools/flang2/utils/symtab -I/home/awvwgk/software/aur/classic-flang/src/build-flang-x86_64/tools/flang2/utils/ilitp -I/home/awvwgk/software/aur/classic-flang/src/build-flang-x86_64/tools/flang2/utils/ilmtp -I/home/awvwgk/software/aur/classic-flang/src/build-flang-x86_64/tools/flang2/utils/machar -I/home/awvwgk/software/aur/classic-flang/src/build-flang-x86_64/tools/flang2/utils/upper -I/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/shared/utils -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -std=c++11 -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -O3 -DNDEBUG  -fno-exceptions -fno-rtti -MD -MT tools/flang2/flang2exe/CMakeFiles/flang2.dir/llassem_common.cpp.o -MF tools/flang2/flang2exe/CMakeFiles/flang2.dir/llassem_common.cpp.o.d -o tools/flang2/flang2exe/CMakeFiles/flang2.dir/llassem_common.cpp.o -c /home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/llassem_common.cpp
In file included from /home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/llassem_common.cpp:13:
In file included from /home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/llassem_common.h:14:
/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/ll_structure.h:697:12: warning: flexible array members are a C99 feature [-Wc99-extensions]
  LL_MDRef elem[];
           ^
/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/llassem_common.cpp:124:23: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
      fprintf(ASMFIL, str);
                      ^~~
/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/llassem_common.cpp:124:23: note: treat the string as an argument to avoid this
      fprintf(ASMFIL, str);
                      ^
                      "%s", 
/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/llassem_common.cpp:131:25: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
        fprintf(ASMFIL, s);
                        ^
/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/llassem_common.cpp:131:25: note: treat the string as an argument to avoid this
        fprintf(ASMFIL, s);
                        ^
                        "%s", 
/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/llassem_common.cpp:164:7: warning: variable 'area' set but not used [-Wunused-but-set-variable]
  int area;
      ^
/home/awvwgk/software/aur/classic-flang/src/flang-flang_20211221/tools/flang2/flang2exe/llassem_common.cpp:742:7: warning: variable 'n' set but not used [-Wunused-but-set-variable]
  int n, bytes;
      ^
3 warnings and 2 errors generated.
ninja: build stopped: subcommand failed

Building with makepkg at the moment, this is the build hook:

build() {
  cd "${srcdir}"
  PREFIX=/usr

  case "${CARCH}" in
    i?86|armv7)
      # lld needs all the address space it can get.
      LDFLAGS+=" -Wl,--large-address-aware"
      ;;
  esac

  local -a extra_args

  if check_option "debug" "y"; then
    extra_args+=(-DCMAKE_BUILD_TYPE=Debug)
  else
    extra_args+=(-DCMAKE_BUILD_TYPE=Release)
  fi

  if [ "${_compiler}" == "clang" ]; then
    export CC='clang'
    export CXX='clang++'
    extra_args+=(-DLLVM_ENABLE_LLD=ON)
  fi

  [[ -d build-flang-${CARCH} ]] && rm -rf build-flang-${CARCH}
  mkdir build-flang-${CARCH} && pushd build-flang-${CARCH}

  cmake \
    -GNinja \
    -Wno-dev \
    -DCMAKE_INSTALL_PREFIX=$PREFIX \
    -DLLVM_CONFIG=$PREFIX/bin/llvm-config \
    -DCMAKE_CXX_COMPILER=$PREFIX/bin/clang++ \
    -DCMAKE_C_COMPILER=$PREFIX/bin/clang \
    -DCMAKE_Fortran_COMPILER=$PREFIX/bin/flang \
    -DCMAKE_Fortran_COMPILER_ID=Flang \
    -DLLVM_TARGETS_TO_BUILD=X86 \
    -DFLANG_LLVM_EXTENSIONS=ON \
    -DWITH_WERROR=OFF \
    ../flang-flang_${pkgver}

  cmake --build .
}

Any advice?

@awvwgk awvwgk changed the title Build failure on Arch Linux due to insecure format Build failure on Arch Linux due to -Werror=format-security Jan 9, 2022
@kiranchandramohan
Copy link
Collaborator

@bryanpkc has been trying to get the code to compile without warnings but we are still not there yet withformat-security.

Can you compile without Werror=format-security, or is that compulsory in Arch Linux?

@awvwgk
Copy link
Author

awvwgk commented Jan 9, 2022

I think this is injected by Arch Linux in all CMake builds done via makepkg, I could try to filter this flag out again by patching the CMake build files.

@kiranchandramohan
Copy link
Collaborator

In addition, you might have to rebase since I reverted a recent patch that was causing a build failure.

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