Page MenuHomeFreeBSD

pmc: avoid illegal flexible array member
ClosedPublic

Authored by rlibby on Thu, Sep 3, 8:00 PM.
Tags
Referenced Files
F170663761: D59355.id.diff
Sat, Sep 5, 9:46 PM
Unknown Object (File)
Sat, Sep 5, 6:59 AM
Unknown Object (File)
Fri, Sep 4, 11:19 AM
Unknown Object (File)
Fri, Sep 4, 1:03 AM
Unknown Object (File)
Fri, Sep 4, 12:53 AM
Unknown Object (File)
Thu, Sep 3, 10:35 PM
Unknown Object (File)
Thu, Sep 3, 9:50 PM
Unknown Object (File)
Thu, Sep 3, 9:23 PM
Subscribers

Details

Summary

Remove struct pmchdr_cpuidinfo which was just a wrapper around a
flexible array member of uint32_t. Flexible array members are
non-standard in C++, and even in C are not allowed as the only member
of a struct.

GCC errored out on pmchdr_cpuidinfo, but did not complain about
pmchdr_pmcinfo, so I left it alone here, though it is also non-standard.

Fixes: 93da997ef759 ("pmc: new pmc log processing framework")

Test Plan
# pkg install amd64-gcc14
$ env MAKEOBJDIRPREFIX=/usr/obj/gcc14 CROSS_TOOLCHAIN=amd64-gcc14 make buildworld

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

rlibby requested review of this revision.Thu, Sep 3, 8:00 PM

oh i see what's going on here. ugh. :-) I'm ok with this, but gosh we need a less cpu specific way of doing all of this!

oh i see what's going on here. ugh. :-) I'm ok with this, but gosh we need a less cpu specific way of doing all of this!

@adrian You asked me this in the review. CPUID is only for x86, because we will need to patch errata for IBS and eventually PEBS.
For other processors we currently don’t need much state and that’s just the cpuinfo.

Yes it’s non-standard but we already depend on a number of gnu extensions in our code. I think is just an error with the build flags, if you just set the length to 0 or 1 and it’s also accepted by gcc.

How do you build this with gcc so I can test my other patches? When I built it using my original repo I see a few more errors because of differences in our build flags.

usr.sbin/pmc/headers.hh
74

You may as well change this to 0 to be consistent.

79

Just changing this to cpuid[0] or cpuid[1] would eliminate this error in my out of tree build. See the comment.

This revision is now accepted and ready to land.Fri, Sep 4, 9:15 PM

Yes it’s non-standard but we already depend on a number of gnu extensions in our code. I think is just an error with the build flags, if you just set the length to 0 or 1 and it’s also accepted by gcc.

I'm not sure why gcc accepts the flexible array member in pmchdr_pmcinfo and not the one in pmchdr_cpuidinfo. It seems it should allow them both as language extensions, or not. Zero-length arrays are slightly different from flexible array members in C, though both are illegal in standard C++. I guess the zero-length array avoids the size and alignment ambiguity.

Anyway, I tried your suggestion but gcc only accepted it for pmchdr_cpuidinfo::cpuid. It issued a fatal warning when it was applied to pmchdr_pmcinfo::pmc, -Werror=stringop-overread. I do not know why it doesn't issue the same fatal warning for pmchdr_cpuidinfo::cpuid.

My only interest here is getting the build working, so if you want to do non-standard C++ things, I am not going to object. I would say though that I do not understand the advantage of the non-standard way over the standard way. Why go through the bother of C++ just to work around it for something fairly trivial?

How do you build this with gcc so I can test my other patches? When I built it using my original repo I see a few more errors because of differences in our build flags.

I'll update the testing section, but in short, I do

sudo pkg install amd64-gcc14
env MAKEOBJDIRPREFIX=/usr/obj/gcc14 CROSS_TOOLCHAIN=amd64-gcc14 make buildworld

CI does essentially the same:
https://github.com/freebsd/freebsd-ci/blob/main/jobs/FreeBSD-main-amd64-gcc14_build/build.sh

And that job has been tripping since this went in:
https://ci.freebsd.org/job/FreeBSD-main-amd64-gcc14_build/4343/

Yes it’s non-standard but we already depend on a number of gnu extensions in our code. I think is just an error with the build flags, if you just set the length to 0 or 1 and it’s also accepted by gcc.

I'm not sure why gcc accepts the flexible array member in pmchdr_pmcinfo and not the one in pmchdr_cpuidinfo. It seems it should allow them both as language extensions, or not. Zero-length arrays are slightly different from flexible array members in C, though both are illegal in standard C++. I guess the zero-length array avoids the size and alignment ambiguity.

Anyway, I tried your suggestion but gcc only accepted it for pmchdr_cpuidinfo::cpuid. It issued a fatal warning when it was applied to pmchdr_pmcinfo::pmc, -Werror=stringop-overread. I do not know why it doesn't issue the same fatal warning for pmchdr_cpuidinfo::cpuid.

My only interest here is getting the build working, so if you want to do non-standard C++ things, I am not going to object. I would say though that I do not understand the advantage of the non-standard way over the standard way. Why go through the bother of C++ just to work around it for something fairly trivial?

How do you build this with gcc so I can test my other patches? When I built it using my original repo I see a few more errors because of differences in our build flags.

I'll update the testing section, but in short, I do

sudo pkg install amd64-gcc14
env MAKEOBJDIRPREFIX=/usr/obj/gcc14 CROSS_TOOLCHAIN=amd64-gcc14 make buildworld

CI does essentially the same:
https://github.com/freebsd/freebsd-ci/blob/main/jobs/FreeBSD-main-amd64-gcc14_build/build.sh

And that job has been tripping since this went in:
https://ci.freebsd.org/job/FreeBSD-main-amd64-gcc14_build/4343/

Thanks for the pointers! I didn't realize we were still building with gcc. Seems like they just don't like a single memory that has variable size.

I'll test my outstanding patches to make sure there's no other breakages and refresh them.

rlibby edited the test plan for this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.