Commit Graph

88 Commits

Author SHA1 Message Date
Beniamino Galvani
6971d53901 docs,m4: remove paragraph about writing to FSF
The Free Software Foundation has changed addresses in the past, and
may do so again. NetworkManager already includes a copy of the
licenses.
2023-10-06 13:27:59 +02:00
Thomas Haller
68afa83c1c
build: enable "-Wcast-align" warning
It seems useful and might show something relevant.
2022-12-09 09:15:56 +01:00
Thomas Haller
abbacb1085
build: enable warnings "-Wint-conversion" and "-Wold-style-definition"
See https://lwn.net/Articles/913505/ .
2022-11-07 08:50:07 +01:00
Thomas Haller
4d2cb2d32b
build/autotools: add compiler warnings that we have in meson
Synchronize the compiler warnings for meson and autotools.
2022-11-07 08:50:07 +01:00
Thomas Haller
119d30145e
m4: add NM_COMPILER_WARNING_FLAG() macro
We used

  COMPILER_FLAG(LIBSYSTEMD_NM_CFLAGS, "-Wno-gnu-variable-sized-type-not-at-end")

to detect whether the flag is supported. However, that does not work with GCC since
version 4.4 due to https://gcc.gnu.org/wiki/FAQ#wnowarning.

Note that we already had NM_COMPILER_WARNING(), but that again does
something rather different.
2022-08-11 19:49:41 +02:00
Thomas Haller
bf86f51c9e
build: rework libreadline detection in autotools
- `m4/ax_lib_readline.m4` was already aware of "$with_readline".
  Move the entire handling of the parameter inside the AX_LIB_READLINE
  macro.
  This lets our fork of ax_lib_readline.m4 further deviate from upstream
  version, but it's already so different that this is no new problem.

- raise an error if the user requested --with-readline=libreadline|libedit
  but the library was not found.

- only allow yes|no for --with-nmcli argument. But still default to
  "yes", which will always require one libreadline library to be
  detected. In particular, don't automatically disable nmcli if
  libreadline is not available, because building without nmcli
  should be an explicit choice. That is like before.

- update the "$with_readline" variable for the "auto" case to reflect
  what was detected.
2021-07-19 09:08:06 +02:00
Lukasz Majewski
8ea9da85b3
m4: cli: Add support for --with-readline=auto|libreadline|libedit|none configuration options
This commit provides support for --with-readline=auto|libreadline|libedit|none option
for the configure script.

It allows building the NetworkManager's nmcli tool with libedit instead
of libreadline.

With --with-readline=auto the system looks for any eligible readline library
to use.

Moreover, in this commit all required defines are provided (e.g.
HAVE_EDITLINE_READLINE) to allow correct buil of the code.
2021-07-14 17:16:45 +02:00
Lukasz Majewski
0c5adc6938
m4: Check for history_set_history_state instead of add_history
The add_history function is available on both - libreadline and libedit.

The read difference between those two libraries is that for libedit the
history_set_history_state is missing.
On that basis one can assess if we do have history from libreadline or
from libedit.
2021-07-14 17:16:45 +02:00
Lukasz Majewski
552e00990d
m4: ax_lib_readline.m4: Use readline libraries when linking add_history test program
Up till now the AC_LANG_CALL() was just checking if program which
uses the add_history call can be correctly linked without passing
required libraries (e.g. -libreadline to LIBS variable).

This commit fixes this issue as now the add_history can be found as it
is now available in any of passed libs.
2021-07-14 17:16:45 +02:00
Beniamino Galvani
b9929b647b m4: fix readline macro
The macro always overwrites LIBS and the result is that every binary
links against libreadline.

Instead, save the library to READLINE_LIBS.

See also: 94274c6fcd ('build: fix wrongly linking against libreadline in all applications')

Fixes: af360238be ('m4/ax_lib_readline.m4: Update after running aclocal')
2021-04-27 10:33:59 +02:00
Javier Jardón
af360238be
m4/ax_lib_readline.m4: Update after running aclocal
See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/796
See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/807
2021-04-07 09:17:17 +02:00
orbea
3affccf29b
tests: fix undefined references to pthread
When building NetworkManger with --enable-tests or using 'make check'
and slibtool the build will fail in many places with undefined references
to pthreads.

This is because -lpthread is never explicitly added to the appropriate
variable, src_core_libNetworkManagerTest_la_LIBADD. When analyzing the
build log with GNU libtool it can be seen that it silently adds -pthread
on its own which hides the issue.

To solve this ax_pthread.m4 from the autoconf-archives project can be
used which provides the $(PTHREAD_LIBS) linker flag.

Source: https://github.com/autoconf-archive/autoconf-archive/blob/master/m4/ax_pthread.m4
See-also: https://www.gnu.org/software/autoconf-archive/ax_pthread.html

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/804
2021-04-07 08:29:50 +02:00
Thomas Haller
89f808efcb
build: add comment for disabling "-Wmaybe-uninitialized" with LTO
With LTO it's easy to get "-Wmaybe-uninitialized" false positives.
But the warning is useful, we we don't want to disable it altogether.

However, while investigating the problem it can be useful to patch
it temporarily. Add a code comment that suggests how to do that.
2021-01-08 12:36:55 +01:00
Thomas Haller
cd5792a2b3
Revert "build: set CFLAGS "-Wno-error=maybe-uninitialized" with LTO build"
This was not intended to be pushed to master. Sorry.

This reverts commit 1d63271a8d.
2021-01-08 12:36:23 +01:00
Thomas Haller
1d63271a8d
build: set CFLAGS "-Wno-error=maybe-uninitialized" with LTO build
With LTO builds we get "-Wmaybe-uninitialized" warnings, which break
the build.

These seem false positives to me, due to aggressive inlining. But also
suppressing them with a pragma does not work. So, make them non-fatal
altogether. That is unfortunate, because this warning would be useful
to catch bugs.

Interestingly, when building --with-more-asserts, then the build passes
without warning. Probably because then the inlining doesn't happen.

    libtool: link: gcc -Wall -Werror -Wno-stringop-overflow -Wextra -Wdeclaration-after-statement -Wfloat-equal -Wformat-nonliteral -Wformat-security -Wimplicit-function-declaration -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wpointer-arith -Wshadow -Wshift-negative-value -Wstrict-prototypes -Wundef -Wvla -Wno-duplicate-decl-specifier -Wno-format-truncation -Wno-format-y2k -Wno-missing-field-initializers -Wno-pragmas -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-parameter -Wno-array-bounds -Wunused-value -Wcast-function-type -Wimplicit-fallthrough -fno-strict-aliasing -fdata-sections -ffunction-sections -Wl,--gc-sections -flto -flto-partition=none -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Wl,-z -Wl,relro -Wl,--as-needed -Wl,-z -Wl,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -o src/platform/tests/test-platform-general src/platform/tests/test_platform_general-test-platform-general.o  src/.libs/libNetworkManagerTest.a -luuid -lgnutls -lsystemd -lndp -lselinux -L/lib64 -laudit -lpsl -lcurl -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -ludev -ldl -pthread
    src/platform/nm-linux-platform.c: In function 'ip_route_add':
    src/platform/nm-platform.c:4761:24: error: 'MEM[(struct NMPlatformIPRoute *)&obj + 24B].rt_source' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     4761 |     route->rt_source = nmp_utils_ip_config_source_round_trip_rtprot(route->rt_source);
          |                        ^
    src/platform/nm-platform.h:2139:25: error: 'BIT_FIELD_REF <MEM[(const struct NMPlatformIPRoute *)&obj + 24B], 8, 72>' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     2139 |     return r->table_any ? 254u /* RT_TABLE_MAIN */
          |                         ^
    lto1: all warnings being treated as errors
    lto-wrapper: fatal error: gcc returned 1 exit status
2021-01-08 12:17:58 +01:00
Thomas Haller
407a1f1e98
build: disable "-Wstringop-overflow" warning with LTO enabled
No amount of _Pragma was able to disable this warning.

    In function ‘strncpy’,
        inlined from ‘_nm_strndup_a_step’ at ./shared/nm-glib-aux/nm-macros-internal.h:1367:3,
        inlined from ‘nms_keyfile_nmmeta_check_filename’ at src/settings/plugins/keyfile/nms-keyfile-utils.c:61:0:
    /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
      106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
          |          ^
    src/settings/plugins/keyfile/nms-keyfile-utils.c: In function ‘nms_keyfile_nmmeta_check_filename’:
    src/settings/plugins/keyfile/nms-keyfile-utils.c:44: note: length computed here
       44 |  len = strlen (filename);
          |
    lto1: all warnings being treated as errors

Oddly enough, gcc is still emitting the warning even with "-Wno-stringop-overflow",
but at least it doesn't break the build.
2020-08-17 15:20:08 +02:00
Gilles Dartiguelongue
7b0130d5d7 build: remove subshells and fix invalid test syntax
Signed-off-by: Gilles Dartiguelongue <eva@gentoo.org>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/472
(cherry picked from commit e073491b9c)
2020-04-20 08:54:38 +02:00
Thomas Haller
86dfc4b099 build: disable -Wimplicit-fallthrough warning with clang
Seems clang 10 got support for -Wimplicit-fallthrough, but does
not honor the code comments to suppress the warning. What a
disaster.

Try to detect it.

See-also: https://github.com/ClangBuiltLinux/linux/issues/   #636
See-also: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e2079e93f562c7f7a030eb7642017ee5eabaaa10
2020-02-21 18:27:40 +01:00
Thomas Haller
4f9f228fed libnm: disable "-Wtautological-constant-out-of-range-compare" warning with clang
Seen on Debian 9, clang-3.8 (1:3.8.1-24):

    ../libnm-core/nm-setting-bond.c:596:49: error: comparison of constant 32 with expression of type 'NMBondMode' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
            nm_assert (_NM_INT_NOT_NEGATIVE (mode) && mode < 32);
                                                      ~~~~ ^ ~~

This warning is not useful. While it may be implementation defined how enum
values outside the defined ones are handled, we commonly rely on placing
special numeric values in enums (e.g. ((NMEnumType) -1)).

An enum is (with our compilers) just a glorified integer, and there is nothing
preventing it from being outside the enum values. The warning is not helpful
and outright wrong. Disable it.

See-also: https://bugs.llvm.org//show_bug.cgi?id=16154

Fixes: 957bb2e111 ('libnm: use binary search for _nm_setting_bond_option_supported() implementation')
2020-02-21 10:43:55 +01:00
Thomas Haller
c0e075c902 all: drop emacs file variables from source files
We no longer add these. If you use Emacs, configure it yourself.

Also, due to our "smart-tab" usage the editor anyway does a subpar
job handling our tabs. However, on the upside every user can choose
whatever tab-width he/she prefers. If "smart-tabs" are used properly
(like we do), every tab-width will work.

No manual changes, just ran commands:

    F=($(git grep -l -e '-\*-'))
    sed '1 { /\/\* *-\*-  *[mM]ode.*\*\/$/d }'     -i "${F[@]}"
    sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}"

Check remaining lines with:

    git grep -e '-\*-'

The ultimate purpose of this is to cleanup our files and eventually use
SPDX license identifiers. For that, first get rid of the boilerplate lines.
2019-06-11 10:04:00 +02:00
Thomas Haller
a307bd6ec4 build: disable "-Wunknown-pragmas" warning
clang on CentOS 7.6 (3.4.2-9.el7) warns:

      CC       clients/tui/newt/clients_tui_newt_libnmt_newt_a-nmt-newt-button.o
    In file included from ../clients/tui/newt/nmt-newt-button.c:26:
    In file included from ../shared/nm-default.h:280:
    ../shared/nm-glib-aux/nm-macros-internal.h:1617:2: error: unknown warning group -Wstringop-truncation, ignored [-Werror,-Wunknown-pragmas]
            NM_PRAGMA_WARNING_DISABLE ("-Wstringop-truncation");
            ^
    ../shared/nm-glib-aux/nm-macros-internal.h:419:9: note: expanded from macro NM_PRAGMA_WARNING_DISABLE
            _Pragma(_NM_PRAGMA_WARNING_DO(warning))
            ^
    <scratch space>:109:25: note: expanded from here
     GCC diagnostic ignored "-Wstringop-truncation"
                            ^

This warning totally defeats the purpose of why we use the pragma in the
first place.
2019-05-29 09:42:40 +02:00
Lubomir Rintel
ba461085a2 build: document defaults consistently
[default=meh] instead of (default is meh) or (default: meh).

https://github.com/NetworkManager/NetworkManager/pull/344
2019-04-16 15:57:20 +02:00
Thomas Haller
c537e5fd25 build: re-enable "-Wmissing-braces" warning
We should always get the nesting in struct initializers right.
Everyhing else is error-prone, and the warning is good.

Enable it.
2019-02-08 20:14:50 +01:00
Beniamino Galvani
e6cf4213a7 build: fix building with LTO
Building with link-time optimization requires some tricks explained
in [1].

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48200#c28
2019-02-04 10:55:25 +01:00
Beniamino Galvani
51776b297e build: don't change CFLAGS from configure.ac
If configure.ac automatically adds compiler flags to CFLAGS, it
becomes hard to override one of them for a specific target because
CFLAGS is added last. It is better to use AM_CFLAGS. See [1].

[1] https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html
2018-09-18 15:15:31 +02:00
Lubomir Rintel
e2071e92f0 build: set -Wall when probing extra warning options
Some warnings depends on others: -Wformat-security won't work without
-Wformat. With -Wall we're confident enough that we have important
warnings enabled and in any case we're going to enable it anyway.

https://github.com/NetworkManager/NetworkManager/pull/175
2018-08-07 16:58:36 +02:00
Lubomir Rintel
99b92fd992 build: check whether g-ir-scanner actually works
g-ir-scanner uses distutils that have an unfortunate misfeature of
inheriting the compiler flags it itself was built with.

This includes the hardening flags that don't work with without
redhat-rpm-build and break with clang every full moon.

A configure check makes it clear about what went wrong in case
introspection is desired, otherwise turns it off.

(Taken from network-manager commit 678890ed0347849990787e8893122a39f95cb708)
2018-08-07 10:06:44 +02:00
Thomas Haller
b9bc20f4da build: pass -std=gnu99 to compiler
With --enable-more-warnings, we already used -std=gnu99, see
commit ba2b2de3ad.

Compilation may behave differently depending on the selected
C standard that we choose. It seems wrong, with more-warnings,
to build against a C standard, while otherwise leaving it undefind.

Indeed, one might argue, that our build system should not use
such compiler specific options. At least, not without detecting
support for the compiler option during ./configure.

However:

- we already did this for --enable-more-warnings.

- we should not program against a theoretical compiler. In practice,
  only gcc and clang works to build NetworkManager. Both these compilers
  support this option, so there is no reason to not use it. If we ever
  come into the situation to support another compiler, adjusting -std=gnu99
  will be the smallest problem. Until that happens (and that's far from
  imminent), don't pretend to be portable to non-existing compilers and
  use the flag that in practice is available.

See-also: https://gcc.gnu.org/onlinedocs/gcc/Standards.html
2018-07-17 17:46:39 +02:00
Thomas Haller
cc12413c08 m4/trivial: fix indentation 2018-07-17 17:42:24 +02:00
Lubomir Rintel
0999ebdf6d m4: parametrize flags variable
Make it possible to add compiler options to a different variable than
CFLAGS. This is useful to conditionally disable a compiler warning for a
subpart of a tree.
2018-02-16 16:06:59 +01:00
Lubomir Rintel
422e87ec0d m4/trivial: add a bug link to a compiler warning check 2018-02-08 17:11:46 +01:00
Thomas Haller
e4839accf5 all: replace non-leading tabs with spaces
We commonly only allow tabs at the beginning of a line, not
afterwards. The reason for this style is so that the code
looks formated right with tabstop=4 and tabstop=8.
2018-02-07 13:32:04 +01:00
Lubomir Rintel
631982a796 m4: disable -Wcast-function-type
This fixes the GCC 8 build. It disables the warning conditionally so that we
get the warning back if glib gets fixed.
2018-02-07 11:46:56 +01:00
Lubomir Rintel
e912b36d95 build: enable unused-but-set warning
It was disabled for shady reasons (not checking write() return value)
that are long gone. Worse even, it hid some real bugs.
2017-12-18 13:29:32 +01:00
Thomas Haller
9c3402aa1e build: add "-Wvla" to warn about uses of variable-length arrays
We don't use them, so add a compiler warning about their use.
I think they are annoying, because sizeof(x) and typeof(x) might
evaluate at runtime. Especially the typeof() extension is useful
for macros, but behaves badly with variable-length arrays due to
running code at runtime.

But the worst is, G_STATIC_ASSERT() is implemented by declaring
an array of negative length. Usually, the checked condition should
be a compile time constant, but with VLAs the compiler would not evaluate
the static-assert at compile time and instead accept it silently. It's easy
to mess up static asserts to wrongly have a non-constant condition,
especially when the static-assert is used inside a macro.

Just say no.
2017-12-15 11:48:38 +01:00
Beniamino Galvani
b3b9b2bf38 build: disable lcov version check
Ideally we should switch to the standard macro AX_CODE_COVERAGE for
code coverage, but infortunately it's not supported on older distros
(e.g. on Travis).

Keep using the current macro, but remove the lcov version check as
it's not clear why it's needed in the first place (see [1]). The
latest version of lcov is now 1.13.

[1] http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=commit;h=dedd290bdb647704d74c13992bd04275d9cb648e
2017-10-20 17:16:22 +02:00
Thomas Haller
41e7fca597 build: enable -Wlogical-op and -Wshift-negative-value compiler warning 2017-05-18 18:21:27 +02:00
Lubomir Rintel
928d68d04a m4: disable -Wmissing-braces for newer clang
src/NetworkManagerUtils.c:347:18: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
          NMIPAddr a1 = { 0 }, a2 = { 0 };
                          ^
                          {}

Should we initialize unions this way? I think it's all right -- the initializer
works well and { { { 0 } } } is probably not what we'd like to see.

(cherry picked from commit 43012156a3)
2017-04-18 09:44:45 +02:00
Thomas Haller
923c52ffbb build: test for support of -flto compiler flag
... and prepend the $ld_gc_flags instead of appending to the $CFLAGS.
2017-02-10 12:53:32 +01:00
Thomas Haller
a981c6c355 build: add m4 macros for --enable-lto and --enable-ld-gc 2017-02-10 12:11:21 +01:00
Thomas Haller
4a72c121ed build: reorder flags in "m4/compiler_options.m4"
Mostly sort alphabetically, but
  - keep -Wextra first
  - move "-Wno-*" flags to the end
2017-02-06 19:27:21 +01:00
Thomas Haller
5120205f98 build: enable -Wextra warning 2017-02-06 19:27:21 +01:00
Thomas Haller
705e63a292 build: disable -Wformat-truncation warning
The warning seems questionable and overly strict.
For now, just disable it to allow building with gcc7.

    src/systemd/src/basic/time-util.c: In function ‘format_timespan’:
    src/systemd/src/basic/time-util.c:509:46: error: ‘%0*lu’ directive output between 1 and 2147483648 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-truncation=]
                                                  "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                                  ^~~~
    src/systemd/src/basic/time-util.c:509:60: note: format string is defined here
                                                  "%s"USEC_FMT".%0*"PRI_USEC"%s",
    src/systemd/src/basic/time-util.c:509:46: note: directive argument in the range [0, 18446744073709551614]
                                                  "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                                  ^~~~

https://mail.gnome.org/archives/networkmanager-list/2017-February/msg00001.html
2017-02-06 16:53:37 +01:00
Thomas Haller
4b9cebd8ad build: enable -Wimplicit-fallthrough warning from gcc7 2017-02-06 16:45:20 +01:00
Thomas Haller
6bd9f5361f m4/compiler_options.m4: add line breaks for compiler options to check
No change in behavior.
2017-02-06 14:24:28 +01:00
Lubomir Rintel
fd47a9a762 build: move the --enable-more-warning option from m4/ to configure.ac
It will make it easier to policy the default.

(cherry picked from commit 8647be3717)
2017-01-19 16:15:30 +01:00
Thomas Haller
ba2b2de3ad build: allow using GCC C99 dialect instead of C89
We already use several GCC extenions, like typeof() and
__attribute__((cleanup)). They are too convinient to miss
and every supported compiler must support these.
Currently, gcc and clang does. Maybe other compilers would
support that too, but who knows, nobody seems to test that.

We also already use stdbool.h (C99) and the imported systemd
code is mostly gnu99 too (it's not clear to me, because I don't
find it precisely documented. Certainly it makes use of C99 features
too).

C99/gnu99 has some nice improvements that we no longer should miss
out. For example "flexible array members" or "variable declaration
in init-part of for loop".

It doesn't mean we have to use every obscure (badly supported?)
feature, it means we don't have to forgo features that are well
supported. C99 is 17 years old, I mean, really...

If somebody comes along and ports NM to non-gcc/clang, we can address
bugs about unsupported language features as they surface.
But let's not restrict us to some hypothetical compiler (or language
specification).

Also, NetworkManager is not ported on environment beside Linux.
We don't have to be so considerate about the required build environment.
Gcc is probably the most portable compiler out there. I doubt porting
NetworkManager to *BSD fails due to missing gnu99 features. And if that
causes issues, we should fix them after they happen in practice.
2016-11-10 09:34:39 +01:00
Thomas Haller
b33aacbc91 build: move detection of NM_GIT_SHA to separate "m4/git-sha-record.m4"
We want to embed the current commit-id in the ./configure script.
That way the generated ./configure file in the source tarball
references the commit-id from which the tarball was created.

Then, in a second step, a script can check ./configure to find
the parent commit. This is for example done by the 'makerepo.sh'
script.

This is generally useful, and also done by network-manager-applet
and libnl3 projects. Move the function to a separate m4 macro
to reuse it. It should also be re-used in NetworkManager's VPN plugins.
2016-09-14 14:11:07 +02:00
Thomas Haller
b8b68e212d build: disable warning "-Wformat-y2k"
https://bugzilla.gnome.org/show_bug.cgi?id=767207
2016-06-06 14:07:23 +02:00
Beniamino Galvani
b5daaf43bc build: configure.ac: always set -fno-strict-aliasing
We break the aliasing rules in the code, and thus the flag should
always be enabled to prevent wrong optimizations, even without
--enable-more-warnings.
2016-06-03 22:19:37 +02:00