lnav icon indicating copy to clipboard operation
lnav copied to clipboard

lnav uses alloca(), specifies -std=c++14 but should instead use -std=gnu++14

Open he32 opened this issue 2 years ago • 0 comments

lnav version v0.11.1

Describe the bug The alloca() function is used several places in lnav. To quote from the NetBSD man page for alloca():

CAVEATS
     Few limitations can be mentioned:

     o   The alloca() function is not part of any C standard and its use is
         not portable.

     o   The alloca() function should be supplied by the compiler because the
         compiler is allowed to make assumptions about the stack and frame
         pointers.  The libc alloca() implementation cannot account for those
         assumptions.  While there is a machine dependent implementation of
         alloca() in libc, its use is discouraged and in most cases it will
         not work.  Using this implementation will produce linker warnings.

     o   The alloca() function is unsafe because it cannot ensure that the
         pointer returned points to a valid and usable block of memory.  The
         allocation made may exceed the bounds of the stack, or even go
         further into other objects in memory, and alloca() cannot determine
         such an error.  For that all alloca() allocations should be bounded
         and limited to a small size.

     o   Since alloca() modifies the stack at runtime and the stack usage of
         each function frame cannot be predicted, it makes many compiler
         security features (such as cc(1) -fstack-protector) useless for the
         calling function.  See security(7) for a discussion.

On NetBSD/amd64 and NetBSD/i386 there exists an alloca() in the C library which papers over the consequence of people using alloca() and building with e.g. -std=c++14, as in that case gcc will not supply alloca() itself.
However, on NetBSD/powerpc, the C library does not have this implementation, so there it becomes neccessary to supply the correct -std= value, and to get alloca() defined, one needs the GNU extensions, so instead of -std=c++14 one needs to use -std=gnu++14.

To Reproduce Try to build lnav on NetBSD/macppc (a powerpc port), and watch it fail to link due to no compiler-supplied alloca().

he32 avatar May 24 '23 22:05 he32