On 22/02/2023 10:22 am, Jan Beulich wrote: > In COVERAGE=y but DEBUG=n builds (observed by randconfig testing) gcc12 > takes issue with the subtraction of 1 from __stop___pre_ex_table[], > considering this an out of bounds access. Not being able to know that > the symbol actually marks the end of an array, the compiler is kind of > right with this diagnosis. Move the subtraction into the function. > > Reported-by: Anthony PERARD <[email protected]> > Signed-off-by: Jan Beulich <[email protected]> > --- > To keep things simple, I'm merely calculating "last" as a local variable > now, rather than replacing its uses by suitable ones of "end". In the > longer run it may become necessary to actually go this 2nd step, as in > principle the compiler could inline the function and then still spot the > same issue. However, while the subtraction of 1 can likely be avoided by > suitable other adjustments, "last - first" cannot easily be. Yet that's > also an offense, in that it's calculating the difference between pointers > into distinct objects.
All of these bugs are ultimately because gcc doesn't know that these two labels are the bounds of a single array, and not separate objects. There is no possible at all to get rid of the "last - first" calculation - this is a binary search through an array. But it's also not going to actually stop working, because this is the common (and documented) way of getting linker symbols into C. For the patch, Acked-by: Andrew Cooper <[email protected]> but if it were me, I'd have gone one step further and made search_one_extable() into a more normal looking binary search.
