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

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

Open
he32 opened this issue May 24, 2023 · 0 comments
Open
Labels

Comments

@he32
Copy link
Contributor

he32 commented May 24, 2023

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 he32 added the bug label May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant