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

systemd seems to be failing to compile with gcc-10, -O3 and -flto #16224

Closed
evverx opened this issue Jun 19, 2020 · 6 comments · Fixed by #16235
Closed

systemd seems to be failing to compile with gcc-10, -O3 and -flto #16224

evverx opened this issue Jun 19, 2020 · 6 comments · Fixed by #16235
Labels
bug 🐛 Programming errors, that need preferential fixing network
Milestone

Comments

@evverx
Copy link
Member

evverx commented Jun 19, 2020

I'm not sure why it hasn't been caught by the "build test" workflow (where systemd is built with gcc-10, -O3 and -flto)

$ gcc --version
gcc (GCC) 10.1.1 20200507 (Red Hat 10.1.1-1)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ CFLAGS='-Wall -Werror' meson   --optimization=3 -Db_lto=true   build

$ ninja ./build
...
[1050/1636] Linking target systemd-networkd
FAILED: systemd-networkd
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 -Wall -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/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: error: writing 8 bytes into a region of size 0 [-Werror=stringop-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);
      |                ^
lto1: all warnings being treated as errors
lto-wrapper: fatal error: cc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
[1052/1636] Linking target test-network
FAILED: test-network
cc  -o test-network 'test-network@exe/src_network_test-network.c.o' -flto -Wl,--as-needed -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -fstack-protector -Wl,--gc-sections -Wall -Werror -Wl,--start-group src/network/libnetworkd-core.a src/shared/libsystemd-shared-245.so src/udev/libudev_static.a src/udev/libudev-basic.a src/libsystemd-network/libsystemd-network.a -Wl,--end-group -pthread '-Wl,-rpath,$ORIGIN/src/network:$ORIGIN/src/shared:$ORIGIN/src/udev:$ORIGIN/src/libsystemd-network' -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/udev -Wl,-rpath-link,/home/vagrant/systemd/build/src/libsystemd-network
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: error: writing 8 bytes into a region of size 0 [-Werror=stringop-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);
      |                ^
lto1: all warnings being treated as errors
lto-wrapper: fatal error: cc returned 1 exit status
compilation terminated.
evverx added a commit to evverx/systemd that referenced this issue Jun 19, 2020
Judging by systemd#16224, it seems
`--werror` doesn't work with `-Db_lto=true`
@evverx
Copy link
Member Author

evverx commented Jun 19, 2020

FWIW apparently this issue was also reported by Coverity three days ago:

Hi,

Please find the latest report on new defect(s) introduced to systemd/systemd found with Coverity Scan.

2 new defect(s) introduced to systemd/systemd found with Coverity Scan.


New defect(s) Reported-by: Coverity Scan
Showing 2 of 2 defect(s)


** CID 1429928:  Memory - corruptions  (OVERRUN)
/src/network/networkd-dhcp6.c: 1068 in dhcp6_assign_delegated_prefix()


________________________________________________________________________________________________________
*** CID 1429928:  Memory - corruptions  (OVERRUN)
/src/network/networkd-dhcp6.c: 1068 in dhcp6_assign_delegated_prefix()
1062             if (r < 0)
1063                     return log_link_error_errno(link, r, "Failed to allocate address for DHCPv6 delegated prefix: %m");
1064     
1065             address->in_addr.in6 = *prefix;
1066     
1067             if (!in_addr_is_null(AF_INET6, &link->network->dhcp6_delegation_prefix_token))

     CID 1429928:  Memory - corruptions  (OVERRUN)
     Overrunning buffer pointed to by "&address->in_addr.in6.__in6_u.__u6_addr8 + 8" of 16 bytes by passing it to a function which accesses it at byte offset 135 using argument "8UL".
1068                     memcpy(&address->in_addr.in6.s6_addr + 8, &link->network->dhcp6_delegation_prefix_token.in6.s6_addr + 8, 8);
1069             else {
1070                     r = generate_ipv6_eui_64_address(link, &address->in_addr.in6);
1071                     if (r < 0)
1072                             return log_link_warning_errno(link, r, "Failed to generate EUI64 address for acquired DHCPv6 delegated prefix: %m");
1073             }

** CID 1429927:  Memory - corruptions  (OVERRUN)
/src/network/networkd-dhcp6.c: 1068 in dhcp6_assign_delegated_prefix()


________________________________________________________________________________________________________
*** CID 1429927:  Memory - corruptions  (OVERRUN)
/src/network/networkd-dhcp6.c: 1068 in dhcp6_assign_delegated_prefix()
1062             if (r < 0)
1063                     return log_link_error_errno(link, r, "Failed to allocate address for DHCPv6 delegated prefix: %m");
1064     
1065             address->in_addr.in6 = *prefix;
1066     
1067             if (!in_addr_is_null(AF_INET6, &link->network->dhcp6_delegation_prefix_token))

Показать цитату целикомПоказать всю переписку
1068                     memcpy(&address->in_addr.in6.s6_addr + 8, &link->network->dhcp6_delegation_prefix_token.in6.s6_addr + 8, 8);
1069             else {
1070                     r = generate_ipv6_eui_64_address(link, &address->in_addr.in6);
1071                     if (r < 0)
1072                             return log_link_warning_errno(link, r, "Failed to generate EUI64 address for acquired DHCPv6 delegated prefix: %m");
1073             }

@evverx
Copy link
Member Author

evverx commented Jun 19, 2020

Since both gcc and Coverity are complaining about this I'll go ahead and add the "bug" label and the "246" milestone.

cc @yuwata @ssahani

@evverx evverx added the bug 🐛 Programming errors, that need preferential fixing label Jun 19, 2020
@evverx evverx added this to the v246 milestone Jun 19, 2020
@ssahani
Copy link
Contributor

ssahani commented Jun 20, 2020

845d784
and a3d8161#diff-30d862b9251b785c8ee19db9d7a0321aR1068

here we need the casting

ssahani added a commit to ssahani/systemd that referenced this issue Jun 20, 2020
@ssahani
Copy link
Contributor

ssahani commented Jun 20, 2020

@evverx I hope #16227 will fix this.

@evverx
Copy link
Member Author

evverx commented Jun 20, 2020

@ssahani could you cherry-pick the commit from #16225 just to make sure gcc no longer complains?

ssahani pushed a commit to ssahani/systemd that referenced this issue Jun 20, 2020
Judging by systemd#16224, it seems
`--werror` doesn't work with `-Db_lto=true`
@ssahani
Copy link
Contributor

ssahani commented Jun 20, 2020

Ok done.

yuwata added a commit to yuwata/systemd that referenced this issue Jun 22, 2020
This confuses gcc-10 with -O3 -flto.

Closes systemd#16224.
yuwata pushed a commit to yuwata/systemd that referenced this issue Jun 22, 2020
Judging by systemd#16224, it seems
`--werror` doesn't work with `-Db_lto=true`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Programming errors, that need preferential fixing network
2 participants