gatlinnewhouse / linux

Linux kernel source tree
Other
0 stars 0 forks source link

Enable -Wrestrict #1

Closed gatlinnewhouse closed 7 months ago

gatlinnewhouse commented 7 months ago

Running into some errors when building on gcc in Ubuntu containers, however some older gcc versions have actionable errors to address.

gatlinnewhouse commented 7 months ago

One resolution: run make -C tool/objtool/ all in order to compile a new fixdep with the container's glibc version. Run apt build-dep linux after uncommenting deb-src lines in /etc/apt/sources.list. Also need to install various packages I wrote down in the local build_containers.bash

They should all be working now without manual remediation: https://github.com/gatlinnewhouse/kernel-build-containers

gatlinnewhouse commented 7 months ago

Patch is possibly developed. Need to finish compatibility with gcc versions >= 5.1. KSPP/linux/issues/134

Confirmed working versions (with patch on v6.9-rc3):

gatlinnewhouse commented 7 months ago

gcc-7.5, is occurring even without patch applied.

In file included from <command-line>:0:0:
In function '__guc_context_policy_add_preemption_timeout.isra.52',
    inlined from '__guc_context_set_preemption_timeout' at drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:3182:3:
././include/linux/compiler_types.h:449:38: error: call to '__compiletime_assert_2020' declared with attribute error: FIELD_PREP: mask is not constant
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
                                      ^
././include/linux/compiler_types.h:430:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^~~~~~
././include/linux/compiler_types.h:449:2: note: in expansion of macro '_compiletime_assert'
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
  ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^~~~~~~~~~~~~~~~~~
./include/linux/bitfield.h:65:3: note: in expansion of macro 'BUILD_BUG_ON_MSG'
   BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask),  \
   ^~~~~~~~~~~~~~~~
./include/linux/bitfield.h:115:3: note: in expansion of macro '__BF_FIELD_CHECK'
   __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
   ^~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2638:3: note: in expansion of macro 'FIELD_PREP'
   FIELD_PREP(GUC_KLV_0_KEY, GUC_CONTEXT_POLICIES_KLV_ID_##id) | \
   ^~~~~~~~~~
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2645:1: note: in expansion of macro 'MAKE_CONTEXT_POLICY_ADD'
 MAKE_CONTEXT_POLICY_ADD(preemption_timeout, PREEMPTION_TIMEOUT)
 ^~~~~~~~~~~~~~~~~~~~~~~
In function '__guc_context_policy_add_priority.isra.49',
    inlined from '__guc_context_set_prio.isra.50' at drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:3559:3,
    inlined from 'guc_context_set_prio' at drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:3587:2:
././include/linux/compiler_types.h:449:38: error: call to '__compiletime_assert_2030' declared with attribute error: FIELD_PREP: mask is not constant
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
                                      ^
././include/linux/compiler_types.h:430:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^~~~~~
././include/linux/compiler_types.h:449:2: note: in expansion of macro '_compiletime_assert'
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
  ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^~~~~~~~~~~~~~~~~~
./include/linux/bitfield.h:65:3: note: in expansion of macro 'BUILD_BUG_ON_MSG'
   BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask),  \
   ^~~~~~~~~~~~~~~~
./include/linux/bitfield.h:115:3: note: in expansion of macro '__BF_FIELD_CHECK'
   __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
   ^~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2638:3: note: in expansion of macro 'FIELD_PREP'
   FIELD_PREP(GUC_KLV_0_KEY, GUC_CONTEXT_POLICIES_KLV_ID_##id) | \
   ^~~~~~~~~~
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2646:1: note: in expansion of macro 'MAKE_CONTEXT_POLICY_ADD'
 MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY)
 ^~~~~~~~~~~~~~~~~~~~~~~
In function '__guc_context_policy_add_priority.isra.49',
    inlined from '__guc_add_request' at drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2680:2:
././include/linux/compiler_types.h:449:38: error: call to '__compiletime_assert_2030' declared with attribute error: FIELD_PREP: mask is not constant
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
                                      ^
././include/linux/compiler_types.h:430:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^~~~~~
././include/linux/compiler_types.h:449:2: note: in expansion of macro '_compiletime_assert'
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
  ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^~~~~~~~~~~~~~~~~~
./include/linux/bitfield.h:65:3: note: in expansion of macro 'BUILD_BUG_ON_MSG'
   BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask),  \
   ^~~~~~~~~~~~~~~~
./include/linux/bitfield.h:115:3: note: in expansion of macro '__BF_FIELD_CHECK'
   __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
   ^~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2638:3: note: in expansion of macro 'FIELD_PREP'
   FIELD_PREP(GUC_KLV_0_KEY, GUC_CONTEXT_POLICIES_KLV_ID_##id) | \
   ^~~~~~~~~~
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2646:1: note: in expansion of macro 'MAKE_CONTEXT_POLICY_ADD'
 MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY)
 ^~~~~~~~~~~~~~~~~~~~~~~
In function '__guc_context_policy_add_priority.isra.49',
    inlined from 'register_context' at drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2680:2:
././include/linux/compiler_types.h:449:38: error: call to '__compiletime_assert_2030' declared with attribute error: FIELD_PREP: mask is not constant
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
                                      ^
././include/linux/compiler_types.h:430:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^~~~~~
././include/linux/compiler_types.h:449:2: note: in expansion of macro '_compiletime_assert'
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
  ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^~~~~~~~~~~~~~~~~~
./include/linux/bitfield.h:65:3: note: in expansion of macro 'BUILD_BUG_ON_MSG'
   BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask),  \
   ^~~~~~~~~~~~~~~~
./include/linux/bitfield.h:115:3: note: in expansion of macro '__BF_FIELD_CHECK'
   __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
   ^~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2638:3: note: in expansion of macro 'FIELD_PREP'
   FIELD_PREP(GUC_KLV_0_KEY, GUC_CONTEXT_POLICIES_KLV_ID_##id) | \
   ^~~~~~~~~~
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:2646:1: note: in expansion of macro 'MAKE_CONTEXT_POLICY_ADD'
 MAKE_CONTEXT_POLICY_ADD(priority, SCHEDULING_PRIORITY)
 ^~~~~~~~~~~~~~~~~~~~~~~
In function '__guc_scheduling_policy_add_klv.isra.57',
    inlined from 'guc_init_global_schedule_policy' at drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:4676:3,
    inlined from 'intel_guc_submission_enable' at drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:4717:6:
././include/linux/compiler_types.h:449:38: error: call to '__compiletime_assert_2109' declared with attribute error: FIELD_PREP: mask is not constant
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
                                      ^
././include/linux/compiler_types.h:430:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^~~~~~
././include/linux/compiler_types.h:449:2: note: in expansion of macro '_compiletime_assert'
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
  ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^~~~~~~~~~~~~~~~~~
./include/linux/bitfield.h:65:3: note: in expansion of macro 'BUILD_BUG_ON_MSG'
   BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask),  \
   ^~~~~~~~~~~~~~~~
./include/linux/bitfield.h:115:3: note: in expansion of macro '__BF_FIELD_CHECK'
   __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
   ^~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:4628:17: note: in expansion of macro 'FIELD_PREP'
  *(klv_ptr++) = FIELD_PREP(GUC_KLV_0_KEY, action) |
                 ^~~~~~~~~~
gatlinnewhouse commented 7 months ago

gcc-6.5, not this exact error but similar errors on v6.9-rc3 build without the patch

gcc: error: unrecognized command line option '-Wrestrict'
scripts/Makefile.build:244: recipe for target 'scripts/mod/empty.o' failed
make[2]: *** [scripts/mod/empty.o] Error 1
make[2]: *** Waiting for unfinished jobs....
gcc: error: unrecognized command line option '-Wrestrict'
scripts/Makefile.build:117: recipe for target 'scripts/mod/devicetable-offsets.s' failed
make[2]: *** [scripts/mod/devicetable-offsets.s] Error 1
/home/gtn/src/Makefile:1196: recipe for target 'prepare0' failed
make[1]: *** [prepare0] Error 2
make[1]: *** Waiting for unfinished jobs....
Makefile:240: recipe for target '__sub-make' failed
make: *** [__sub-make] Error 2
gatlinnewhouse commented 7 months ago

gcc-5.4, same error in clean v6.9-rc3 tree

In file included from scripts/gcc-plugins/gcc-common.h:74:0,
                 from scripts/gcc-plugins/latent_entropy_plugin.c:78:
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:22: error: field 'call_used' has incomplete type 'pt_solution'
   struct pt_solution call_used;
                      ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:10: note: forward declaration of 'struct pt_solution'
   struct pt_solution call_used;
          ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:284:22: error: field 'call_clobbered' has incomplete type 'pt_solution'
   struct pt_solution call_clobbered;
                      ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:10: note: forward declaration of 'struct pt_solution'
   struct pt_solution call_used;
          ^
In file included from scripts/gcc-plugins/gcc-common.h:74:0,
                 from scripts/gcc-plugins/latent_entropy_plugin.c:78:
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h: In function 'bool gimple_store_p(const_gimple)':
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:2556:36: error: 'is_gimple_reg' was not declared in this scope
   return lhs && !is_gimple_reg (lhs);
                                    ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h: In function 'tree_node* gimple_call_fndecl(const_gimple)':
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:2790:54: error: 'gimple_call_addr_fndecl' was not declared in this scope
   return gimple_call_addr_fndecl (gimple_call_fn (gs));
                                                      ^
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-format-diag'
scripts/gcc-plugins/Makefile:54: recipe for target 'scripts/gcc-plugins/latent_entropy_plugin.so' failed
make[3]: *** [scripts/gcc-plugins/latent_entropy_plugin.so] Error 1
make[3]: *** Waiting for unfinished jobs....
In file included from scripts/gcc-plugins/gcc-common.h:74:0,
                 from scripts/gcc-plugins/structleak_plugin.c:32:
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:22: error: field 'call_used' has incomplete type 'pt_solution'
   struct pt_solution call_used;
                      ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:10: note: forward declaration of 'struct pt_solution'
   struct pt_solution call_used;
          ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:284:22: error: field 'call_clobbered' has incomplete type 'pt_solution'
   struct pt_solution call_clobbered;
                      ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:10: note: forward declaration of 'struct pt_solution'
   struct pt_solution call_used;
          ^
In file included from scripts/gcc-plugins/gcc-common.h:74:0,
                 from scripts/gcc-plugins/structleak_plugin.c:32:
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h: In function 'bool gimple_store_p(const_gimple)':
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:2556:36: error: 'is_gimple_reg' was not declared in this scope
   return lhs && !is_gimple_reg (lhs);
                                    ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h: In function 'tree_node* gimple_call_fndecl(const_gimple)':
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:2790:54: error: 'gimple_call_addr_fndecl' was not declared in this scope
   return gimple_call_addr_fndecl (gimple_call_fn (gs));
                                                      ^
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-format-diag'
scripts/gcc-plugins/Makefile:54: recipe for target 'scripts/gcc-plugins/structleak_plugin.so' failed
make[3]: *** [scripts/gcc-plugins/structleak_plugin.so] Error 1
In file included from scripts/gcc-plugins/gcc-common.h:74:0,
                 from scripts/gcc-plugins/stackleak_plugin.c:30:
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:22: error: field 'call_used' has incomplete type 'pt_solution'
   struct pt_solution call_used;
                      ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:10: note: forward declaration of 'struct pt_solution'
   struct pt_solution call_used;
          ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:284:22: error: field 'call_clobbered' has incomplete type 'pt_solution'
   struct pt_solution call_clobbered;
                      ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:10: note: forward declaration of 'struct pt_solution'
   struct pt_solution call_used;
          ^
In file included from scripts/gcc-plugins/gcc-common.h:74:0,
                 from scripts/gcc-plugins/stackleak_plugin.c:30:
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h: In function 'bool gimple_store_p(const_gimple)':
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:2556:36: error: 'is_gimple_reg' was not declared in this scope
   return lhs && !is_gimple_reg (lhs);
                                    ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h: In function 'tree_node* gimple_call_fndecl(const_gimple)':
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:2790:54: error: 'gimple_call_addr_fndecl' was not declared in this scope
   return gimple_call_addr_fndecl (gimple_call_fn (gs));
                                                      ^
In file included from scripts/gcc-plugins/gcc-common.h:74:0,
                 from scripts/gcc-plugins/sancov_plugin.c:22:
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:22: error: field 'call_used' has incomplete type 'pt_solution'
   struct pt_solution call_used;
                      ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:10: note: forward declaration of 'struct pt_solution'
   struct pt_solution call_used;
          ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:284:22: error: field 'call_clobbered' has incomplete type 'pt_solution'
   struct pt_solution call_clobbered;
                      ^
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:283:10: note: forward declaration of 'struct pt_solution'
   struct pt_solution call_used;
          ^
In file included from scripts/gcc-plugins/gcc-common.h:74:0,
                 from scripts/gcc-plugins/sancov_plugin.c:22:
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h: In function 'bool gimple_store_p(const_gimple)':
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:2556:36: error: 'is_gimple_reg' was not declared in this scope
   return lhs && !is_gimple_reg (lhs);
                                    ^
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-format-diag'
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h: In function 'tree_node* gimple_call_fndecl(const_gimple)':
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gimple.h:2790:54: error: 'gimple_call_addr_fndecl' was not declared in this scope
   return gimple_call_addr_fndecl (gimple_call_fn (gs));
                                                      ^
scripts/gcc-plugins/Makefile:54: recipe for target 'scripts/gcc-plugins/stackleak_plugin.so' failed
make[3]: *** [scripts/gcc-plugins/stackleak_plugin.so] Error 1
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-format-diag'
scripts/gcc-plugins/Makefile:54: recipe for target 'scripts/gcc-plugins/sancov_plugin.so' failed
make[3]: *** [scripts/gcc-plugins/sancov_plugin.so] Error 1
scripts/Makefile.build:485: recipe for target 'scripts/gcc-plugins' failed
make[2]: *** [scripts/gcc-plugins] Error 2
/home/gtn/src/Makefile:1181: recipe for target 'scripts' failed
make[1]: *** [scripts] Error 2
make[1]: *** Waiting for unfinished jobs....
Makefile:240: recipe for target '__sub-make' failed
make: *** [__sub-make] Error 2
gatlinnewhouse commented 7 months ago

https://lore.kernel.org/lkml/20240415122037.1983124-4-arnd@kernel.org/