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

--werror doesn't work with -Db_lto=true #7360

Closed
evverx opened this issue Jun 19, 2020 · 2 comments · Fixed by #12750
Closed

--werror doesn't work with -Db_lto=true #7360

evverx opened this issue Jun 19, 2020 · 2 comments · Fixed by #12750
Labels

Comments

@evverx
Copy link

evverx commented Jun 19, 2020

It appears -Werror gets lost somewhere along the way when -Db_lto is used. For example, systemd/systemd#16224 was discovered by passing -Werror with CFLAGS directly.

Here's what the command line looks like with --werror:

[1053/1636] cc  -o systemd-networkd 'systemd-networkd@exe/src_network_networkd.c.o' -flto -Wl,--as-needed -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -fstack-protector -Wl,--gc-sections -Wl,--start-group src/network/libnetworkd-core.a src/shared/libsystemd-shared-245.so src/libsystemd-network/libsystemd-network.a src/udev/libudev_static.a src/udev/libudev-basic.a -Wl,--end-group -pthread '-Wl,-rpath,$ORIGIN/src/network:$ORIGIN/src/shared:$ORIGIN/src/libsystemd-network:$ORIGIN/src/udev' -Wl,-rpath-link,/home/vagrant/systemd/build/src/network -Wl,-rpath-link,/home/vagrant/systemd/build/src/shared -Wl,-rpath-link,/home/vagrant/systemd/build/src/libsystemd-network -Wl,-rpath-link,/home/vagrant/systemd/build/src/udev
In function ‘dhcp6_assign_delegated_prefix’,
    inlined from ‘dhcp6_pd_prefix_assign’ at ../src/network/networkd-dhcp6.c:203:21,
    inlined from ‘dhcp6_pd_prefix_distribute.isra’ at ../src/network/networkd-dhcp6.c:333:21:
../src/network/networkd-dhcp6.c:1068:17: warning: writing 8 bytes into a region of size 0 [-Wstringop-overflow=]
 1068 |                 memcpy(&address->in_addr.in6.s6_addr + 8, &link->network->dhcp6_delegation_prefix_token.in6.s6_addr + 8, 8);
      |                 ^
../src/network/networkd-dhcp6.c: In function ‘dhcp6_pd_prefix_distribute.isra’:
../src/basic/alloc-util.h:96:16: note: at offset 196 to an object with size 0 allocated by ‘malloc’ here
   96 |         return malloc(size * need ?: 1);
      |                ^
[1054/1636]

and with CFLAGS='-Werror'

2020-06-19T23:14:53.6541938Z gcc-10  -o systemd-networkd 'systemd-networkd@exe/src_network_networkd.c.o' -flto -Wl,--as-needed -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -fstack-protector -Wl,--gc-sections -Werror -Wl,--start-group src/network/libnetworkd-core.a src/shared/libsystemd-shared-245.so src/libsystemd-network/libsystemd-network.a src/udev/libudev_static.a src/udev/libudev-basic.a -Wl,--end-group -pthread '-Wl,-rpath,$ORIGIN/src/network:$ORIGIN/src/shared:$ORIGIN/src/libsystemd-network:$ORIGIN/src/udev' -Wl,-rpath-link,/home/runner/work/systemd/systemd/build/src/network -Wl,-rpath-link,/home/runner/work/systemd/systemd/build/src/shared -Wl,-rpath-link,/home/runner/work/systemd/systemd/build/src/libsystemd-network -Wl,-rpath-link,/home/runner/work/systemd/systemd/build/src/udev
2020-06-19T23:14:53.6542368Z In function ‘memcpy’,
2020-06-19T23:14:53.6542707Z     inlined from ‘dhcp6_assign_delegated_prefix’ at ../src/network/networkd-dhcp6.c:1068:17,
2020-06-19T23:14:53.6543056Z     inlined from ‘dhcp6_pd_prefix_assign’ at ../src/network/networkd-dhcp6.c:203:21,
2020-06-19T23:14:53.6543409Z     inlined from ‘dhcp6_pd_prefix_distribute.isra’ at ../src/network/networkd-dhcp6.c:333:21:
2020-06-19T23:14:53.6543809Z /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34:10: error: writing 8 bytes into a region of size 0 [-Werror=stringop-overflow=]
2020-06-19T23:14:53.6544264Z    34 |   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
2020-06-19T23:14:53.6544409Z       |          ^
2020-06-19T23:14:53.6544737Z ../src/network/networkd-dhcp6.c: In function ‘dhcp6_pd_prefix_distribute.isra’:
2020-06-19T23:14:53.6545096Z ../src/basic/alloc-util.h:96:16: note: at offset 196 to an object with size 0 allocated by ‘malloc’ here
2020-06-19T23:14:53.6545230Z    96 |         return malloc(size * need ?: 1);
2020-06-19T23:14:53.6545358Z       |                ^
2020-06-19T23:14:53.6545485Z lto1: all warnings being treated as errors
2020-06-19T23:14:53.6545771Z lto-wrapper: fatal error: gcc-10 returned 1 exit status
2020-06-19T23:14:53.6545904Z compilation terminated.
2020-06-19T23:14:53.6546164Z /usr/bin/ld: error: lto-wrapper failed
2020-06-19T23:14:53.6546295Z collect2: error: ld returned 1 exit status
@evverx
Copy link
Author

evverx commented Jun 19, 2020

Forgot to mention that it's reproducible with meson-0.54.3. And just in case the full log can be found at https://github.com/systemd/systemd/runs/789680623?check_suite_focus=true (where -Werror was passed with CFLAGS) and at https://github.com/systemd/systemd/runs/789365442?check_suite_focus=true (where --werror was used).

@evverx
Copy link
Author

evverx commented Feb 3, 2021

It appears there is no way to treat warnings as errors using meson. --werror doesn't always work. -Werror passed via CFLAGS or -Dc_args can break compiler checks leading to meson failing to find "deprecated" functions with cc.has_function: systemd/systemd#18439

thesamesam added a commit to thesamesam/meson that referenced this issue Jan 18, 2024
With LTO, the linker will re-execute the compiler and various warnings may
be emitted. We must therefore pass -Werror to the linker as well when -Werror
is enabled to capture these. This is only required / useful with LTO.

Closes: mesonbuild#7360
Signed-off-by: Sam James <[email protected]>
thesamesam added a commit to thesamesam/meson that referenced this issue Jan 18, 2024
With LTO, the linker will re-execute the compiler and various warnings may
be emitted. We must therefore pass -Werror to the linker as well when -Werror
is enabled to capture these. This is only required / useful with LTO.

Closes: mesonbuild#7360
Signed-off-by: Sam James <[email protected]>
gerioldman pushed a commit to gerioldman/meson that referenced this issue Jul 2, 2024
With LTO, the linker will re-execute the compiler and various warnings may
be emitted. We must therefore pass -Werror to the linker as well when -Werror
is enabled to capture these. This is only required / useful with LTO.

Closes: mesonbuild#7360
Signed-off-by: Sam James <[email protected]>
Signed-off-by: Eli Schwartz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants