Bug while building with -Os

62 views
Skip to first unread message

Giulio Benetti

unread,
Nov 23, 2023, 12:38:38 PM11/23/23
to swup...@googlegroups.com
Hello All,

I've experienced that SWUpdate, if built with -Os optimization, fails to
update
randomly and using installed-directly option it fails 100% of the times
on the
last chunk of memory written to eMMC.

This shows up on versions 2022.12, 2023.08 and master branch.

The program fails during gunzipping here:
https://github.com/sbabic/swupdate/blob/master/core/cpio_utils.c#L376
with -Z_DATA_ERROR

I work around the problem by building with -O3 and I'm going to send
a patch soon to Buildroot for this.

Best regards

--
Giulio Benetti
CEO&CTO@Benetti Engineering sas

Stefano Babic

unread,
Nov 23, 2023, 2:00:08 PM11/23/23
to Giulio Benetti, swup...@googlegroups.com
Hi Giulio,

On 23.11.23 18:38, Giulio Benetti wrote:
> Hello All,
>
> I've experienced that SWUpdate, if built with -Os optimization, fails to
> update
> randomly and using installed-directly option it fails 100% of the times
> on the
> last chunk of memory written to eMMC.
>
> This shows up on versions 2022.12, 2023.08 and master branch.
>
> The program fails during gunzipping here:
> https://github.com/sbabic/swupdate/blob/master/core/cpio_utils.c#L376
> with -Z_DATA_ERROR
>

It is not a lot to find out which is the reason. However, this lines
points to the return code of zlib. How can we know if the cuse is here
or inside the library ?

What I can see here is that the variable outlen is used to get the
remaining size. It should be better declared as size_t instead of int.
Which is the architecture you are using ?

> I work around the problem by building with -O3 and I'm going to send
> a patch soon to Buildroot for this.
>
> Best regards
>

Best regards,
Stefano Babic

Giulio Benetti

unread,
Nov 23, 2023, 2:44:57 PM11/23/23
to Stefano Babic, swup...@googlegroups.com
Hi Stefano,

On 23/11/23 20:00, Stefano Babic wrote:
> Hi Giulio,
>
> On 23.11.23 18:38, Giulio Benetti wrote:
>> Hello All,
>>
>> I've experienced that SWUpdate, if built with -Os optimization, fails
>> to update
>> randomly and using installed-directly option it fails 100% of the
>> times on the
>> last chunk of memory written to eMMC.
>>
>> This shows up on versions 2022.12, 2023.08 and master branch.
>>
>> The program fails during gunzipping here:
>> https://github.com/sbabic/swupdate/blob/master/core/cpio_utils.c#L376
>> with -Z_DATA_ERROR
>>
>
> It is not a lot to find out which is the reason.

You're right, pardon, I'm trying to reproduce it using qemu-arm on
buildroot so I can create a defconfig to create a rootfs that exhibits
the bug.

> However, this lines
> points to the return code of zlib. How can we know if the cuse is here
> or inside the library ?

That could be a cause too, right. But if building with -O3 only SWUpdate
the error is hidden, so I think it's more probable the problem is due
to SWUpdate instead of ZLib. Of course I can't be 100% sure.

> What I can see here is that the variable outlen is used to get the
> remaining size. It should be better declared as size_t instead of int.
> Which is the architecture you are using ?

I'm on i.MX6ULL, Cortex-A7, so it's ok to use size_t, but it's already
declared as int. So that should not be the cause of the bug.

Anyway I'm coming with a test-case for this hopefully.

Thanks for the fast response!
Best regards
--
Giulio Benetti
CEO&CTO@Benetti Engineering sas

>
Reply all
Reply to author
Forward
0 new messages