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

Bug: Lua's ltests.c doesn't compile #1226

Open
michaellenaghan opened this issue Jun 16, 2024 · 0 comments
Open

Bug: Lua's ltests.c doesn't compile #1226

michaellenaghan opened this issue Jun 16, 2024 · 0 comments
Labels
low severity Used to report low severity bugs (e.g. cosmetic issues, non critical UI glitches)

Comments

@michaellenaghan
Copy link
Contributor

michaellenaghan commented Jun 16, 2024

What happened?

Lua can be compiled with extra API-checking support. From Lua's makefile:

# The following options help detect "undefined behavior"s that seldom
# create problems; some are only available in newer gcc versions. To
# use some of them, we also have to define an environment variable
# ASAN_OPTIONS="detect_invalid_pointer_pairs=2".
# -fsanitize=undefined
# -fsanitize=pointer-subtract -fsanitize=address -fsanitize=pointer-compare
# TESTS= -DLUA_USER_H='"ltests.h"' -O0 -g

Defining LUA_USER_H ends up #includeing the #defined value:

#if defined(LUA_USER_H)
#include LUA_USER_H
#endif

In this case, that's ltests.h.

#includeing ltests.h #defines LUA_DEBUG:

#define LUA_DEBUG

That in turns causes the code in ltests.c to get compiled:

/*
** The whole module only makes sense with LUA_DEBUG on
*/
#if defined(LUA_DEBUG)

Compiling ltests.c produces many, many errors — mostly related to missing system-level #includes.

On the one hand, not being able to compile lua with this extra support probably isn't a big problem. On the other hand, it's a problem that could, maybe, be fixed with a couple of lines.

Version

Cosmopolitan v3.4.0

What operating system are you seeing the problem on?

Mac

Relevant log output

$ build/bootstrap/make MODE=aarch64 o/aarch64/third_party/lua/lua
...
third_party/lua/ltests.c: In function ‘badexit’:
third_party/lua/ltests.c:83:3: error: implicit declaration of function ‘exit’ [-Werror=implicit-function-declaration]
   83 |   exit(EXIT_FAILURE);
      |   ^~~~
third_party/lua/ltests.c:47:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
   46 | #include "third_party/lua/lualib.h"
  +++ |+#include <stdlib.h>
   47 | __static_yoink("lua_notice");
third_party/lua/ltests.c:83:8: error: ‘EXIT_FAILURE’ undeclared (first use in this function)
   83 |   exit(EXIT_FAILURE);
      |        ^~~~~~~~~~~~
third_party/lua/ltests.c:83:8: note: ‘EXIT_FAILURE’ is defined in header ‘<stdlib.h>; did you forget to ‘#include <stdlib.h>’?
third_party/lua/ltests.c:83:8: note: each undeclared identifier is reported only once for each function it appears in
third_party/lua/ltests.c: In function ‘warnf’:
third_party/lua/ltests.c:115:9: error: implicit declaration of function ‘strcmp’ [-Werror=implicit-function-declaration]
  115 |     if (strcmp(msg, "@off") == 0)
      |         ^~~~~~
third_party/lua/ltests.c:47:1: note: include ‘<string.h>’ or provide a declaration of ‘strcmp’
   46 | #include "third_party/lua/lualib.h"
  +++ |+#include <string.h>
   47 | __static_yoink("lua_notice");
third_party/lua/ltests.c:131:7: error: implicit declaration of function ‘strlen’ [-Werror=implicit-function-declaration]
  131 |   if (strlen(msg) >= sizeof(buff) - strlen(buff))
      |       ^~~~~~
third_party/lua/ltests.c:131:7: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
third_party/lua/ltests.c:133:3: error: implicit declaration of function ‘strcat’ [-Werror=implicit-function-declaration]
  133 |   strcat(buff, msg);  /* add new message to current warning */
      |   ^~~~~~
third_party/lua/ltests.c:133:3: note: include ‘<string.h>’ or provide a declaration of ‘strcat’
third_party/lua/ltests.c: In function ‘freeblock’:
third_party/lua/ltests.c:191:33: error: implicit declaration of function ‘memset’ [-Werror=implicit-function-declaration]
  191 | #define fillmem(mem,size)       memset(mem, -MARK, size)
      |                                 ^~~~~~
third_party/lua/ltests.c:214:5: note: in expansion of macro ‘fillmem’
  214 |     fillmem(block, sizeof(Header) + size + MARKSIZE);  /* erase block */
      |     ^~~~~~~
third_party/lua/ltests.c:191:33: note: include ‘<string.h>’ or provide a declaration of ‘memset’
  191 | #define fillmem(mem,size)       memset(mem, -MARK, size)
      |                                 ^~~~~~
third_party/lua/ltests.c:214:5: note: in expansion of macro ‘fillmem’
  214 |     fillmem(block, sizeof(Header) + size + MARKSIZE);  /* erase block */
      |     ^~~~~~~
third_party/lua/ltests.c:215:5: error: implicit declaration of function ‘free’ [-Werror=implicit-function-declaration]
  215 |     free(block);  /* actually free block */
      |     ^~~~
third_party/lua/ltests.c:215:5: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
third_party/lua/ltests.c: In function ‘debug_realloc’:
third_party/lua/ltests.c:227:19: error: implicit declaration of function ‘getenv’ [-Werror=implicit-function-declaration]
  227 |     char *limit = getenv("MEMLIMIT");  /* initialize memory limit */
      |                   ^~~~~~
third_party/lua/ltests.c:227:19: note: ‘getenv’ is defined in header ‘<stdlib.h>; did you forget to ‘#include <stdlib.h>’?
third_party/lua/ltests.c:227:19: error: initialization of ‘char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
In file included from ./third_party/lua/lapi.h:4,
                 from third_party/lua/ltests.c:31:
third_party/lua/ltests.c:260:31: error: implicit declaration of function ‘malloc’ [-Werror=implicit-function-declaration]
  260 |     newblock = cast(Header *, malloc(realsize));  /* alloc a new block */
      |                               ^~~~~~
./third_party/lua/llimits.h:126:30: note: in definition of macro ‘cast’
  126 | #define cast(t, exp)    ((t)(exp))
      |                              ^~~
third_party/lua/ltests.c:260:31: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
  260 |     newblock = cast(Header *, malloc(realsize));  /* alloc a new block */
      |                               ^~~~~~
./third_party/lua/llimits.h:126:30: note: in definition of macro ‘cast’
  126 | #define cast(t, exp)    ((t)(exp))
      |                              ^~~
third_party/lua/ltests.c:264:7: error: implicit declaration of function ‘memcpy’ [-Werror=implicit-function-declaration]
  264 |       memcpy(newblock + 1, block + 1, commonsize);  /* copy old contents */
      |       ^~~~~~
third_party/lua/ltests.c:264:7: note: include ‘<string.h>’ or provide a declaration of ‘memcpy’
third_party/lua/ltests.c: In function ‘printobj’:
third_party/lua/ltests.c:327:12: error: implicit declaration of function ‘ttypename’; did you mean ‘ttyname’? [-Werror=implicit-function-declaration]
  327 |            ttypename(novariant(o->tt)), (void *)o,
      |            ^~~~~~~~~
      |            ttyname
third_party/lua/ltests.c: In function ‘mem_query’:
third_party/lua/ltests.c:867:21: error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast [-Werror=int-conversion]
  867 |       if (strcmp(t, ttypename(i)) == 0) {
      |                     ^~~~~~~~~~~~
      |                     |
      |                     int
third_party/lua/ltests.c:867:21: note: expected ‘const char *’ but argument is of type ‘int’
third_party/lua/ltests.c: At top level:
third_party/lua/ltests.c:1250:14: error: unknown type name ‘jmp_buf’
 1250 | struct Aux { jmp_buf jb; const char *paniccode; lua_State *L; };
      |              ^~~~~~~
third_party/lua/ltests.c: In function ‘panicback’:
third_party/lua/ltests.c:1262:3: error: implicit declaration of function ‘gclongjmp’ [-Werror=implicit-function-declaration]
 1262 |   gclongjmp(b->jb, 1);  // [jart]
      |   ^~~~~~~~~
third_party/lua/ltests.c: In function ‘checkpanic’:
third_party/lua/ltests.c:1282:7: error: implicit declaration of function ‘setjmp’ [-Werror=implicit-function-declaration]
 1282 |   if (setjmp(b.jb) == 0) {  /* set jump buffer */
      |       ^~~~~~
third_party/lua/ltests.c: In function ‘skip’:
third_party/lua/ltests.c:1310:25: error: implicit declaration of function ‘strchr’ [-Werror=implicit-function-declaration]
 1310 |     if (**pc != '\0' && strchr(delimits, **pc)) (*pc)++;
      |                         ^~~~~~
third_party/lua/ltests.c:1310:25: note: include ‘<string.h>’ or provide a declaration of strchr’
third_party/lua/ltests.c: In function ‘runC’:
third_party/lua/ltests.c:1723:7: error: implicit declaration of function ‘__die’ [-Werror=implicit-function-declaration]
 1723 |       __die();  // [jart]
      |       ^~~~~
third_party/lua/ltests.c: In function ‘luaB_opentests’:
third_party/lua/ltests.c:1981:3: error: implicit declaration of function ‘atexit’ [-Werror=implicit-function-declaration]
 1981 |   atexit(checkfinalmem);
      |   ^~~~~~
third_party/lua/ltests.c:1981:3: note: ‘atexit’ is defined in header ‘<stdlib.h>; did you forget to ‘#include <stdlib.h>’?
cc1: all warnings being treated as errors

`make MODE=aarch64 -j12 o/aarch64/third_party/lua/ltests.o` exited with 1:
.cosmocc/3.3.5/bin/aarch64-linux-cosmo-gcc -Wall -Werror -frecord-gcc-switches -O2 -fno-code-hoisting -fno-schedule-insns2 -fno-optimize-sibling-calls -mno-omit-leaf-frame-pointer -fpatchable-function-entry=7,6 -g -ggdb -Wa,-W -Wa,-I. -Wa,--noexecstack -D_COSMO_SOURCE -DMODE="aarch64" -Wno-prio-ctor-dtor -Wno-unknown-pragmas -nostdinc -iquote. -isystem libc/isystem -DSYSDEBUG -DFTRACE -include libc/integral/normalize.inc -fno-ident -fno-common -fno-gnu-unique -fstrict-aliasing -fstrict-overflow -fno-semantic-interposition -fno-dwarf2-cfi-asm -fno-unwind-tables -fno-asynchronous-unwind-tables -ffixed-x18 -ffixed-x28 -fsigned-char -mno-outline-atomics -std=gnu2x -ffunction-sections -fdata-sections -fno-inline-functions-called-once -c -o o/aarch64/third_party/lua/ltests.o third_party/lua/ltests.c -fdiagnostics-color=always -fno-omit-frame-pointer -D__FNO_OMIT_FRAME_POINTER__
consumed 34,962µs wall time
ballooned to 39,872kb in size
needed 32,649us cpu (24% kernel)
caused 3,535 page faults (99% memcpy)
11 context switches (18% consensual)
@michaellenaghan michaellenaghan added the low severity Used to report low severity bugs (e.g. cosmetic issues, non critical UI glitches) label Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low severity Used to report low severity bugs (e.g. cosmetic issues, non critical UI glitches)
Projects
None yet
Development

No branches or pull requests

1 participant