Skip to content

Commit

Permalink
Fix build with _map_libc defined
Browse files Browse the repository at this point in the history
Defining _map_libc (by passing -D_map_libc in CCFLAGS) causes
features/map.c to rename virtually all AST library functions with
an _ast_ prefix. But this type of build was broken becasue some
functions were renamed that weren't compiled in if they exist in
the system libraries, such as strlcpy.

If their C source file disables the function if a native version
exists, then the renaming of that function should be equally
disabled in features/map.c, otherwise we get linking errors.
  • Loading branch information
McDutchie committed Aug 25, 2024
1 parent f06dffd commit 4c39a97
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cmd/ksh93/data/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

#undef basename
#undef dirname
#undef mktemp /* undo possible map-libc mktemp => _ast_mktemp */

/*
* IMPORTANT: The order of these struct members must be synchronous
Expand Down Expand Up @@ -126,7 +127,6 @@ const struct shtable3 shtab_builtins[] =
"type", NV_BLTIN|BLT_ENV, bltin(whence),
"whence", NV_BLTIN|BLT_ENV, bltin(whence),
#ifdef SHOPT_CMDLIB_HDR
#undef mktemp /* undo possible map-libc mktemp => _ast_mktemp */
#include SHOPT_CMDLIB_HDR
#else
#if SHOPT_ALL_LIBCMD
Expand Down
29 changes: 26 additions & 3 deletions src/lib/libast/features/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
#define _map_libc 1
#endif

/*
* NOTE: for conditionally compiled AST functions, the preprocessor directives below
* must be kept in sync with the directives in the corresponding C source files, so
* that the rename is not done if the AST version of the function is not compiled
* in; otherwise a build with _map_libc defined will fail with linking errors.
*/

int
main(void)
{
Expand Down Expand Up @@ -110,8 +117,10 @@ main(void)
printf("#undef sigunblock\n");
printf("#define sigunblock _ast_sigunblock\n");
#if _map_libc
#if !_lib_memdup
printf("#undef memdup\n");
printf("#define memdup _ast_memdup\n");
#endif
printf("#undef memhash\n");
printf("#define memhash _ast_memhash\n");
printf("#undef memsum\n");
Expand Down Expand Up @@ -158,6 +167,8 @@ main(void)
printf("#define pathfind _ast_pathfind\n");
printf("#undef pathgetlink\n");
printf("#define pathgetlink _ast_pathgetlink\n");
printf("#undef pathicase\n");
printf("#define pathicase _ast_pathicase\n");
printf("#undef pathinclude\n");
printf("#define pathinclude _ast_pathinclude\n");
printf("#undef pathkey\n");
Expand Down Expand Up @@ -251,21 +262,27 @@ main(void)
printf("#undef regsubfree\n");
printf("#define regsubfree _ast_regsubfree\n");
#if _map_libc
#if !(_std_remove || !_lib_unlink)
printf("#undef remove\n");
printf("#define remove _ast_remove\n");
printf("extern int remove(const char*);\n");
#endif
printf("#undef resolvepath\n");
printf("#define resolvepath _ast_resolvepath\n");
printf("extern int resolvepath(const char*, char*, size_t);\n");
#if !_lib_setenv
printf("#undef setenv\n");
printf("#define setenv _ast_setenv\n");
printf("extern int setenv(const char*, const char*, int);\n");
#endif
printf("#undef setenviron\n");
printf("#define setenviron _ast_setenviron\n");
printf("#undef sigcritical\n");
printf("#define sigcritical _ast_sigcritical\n");
#if !_lib_stracmp
printf("#undef stracmp\n");
printf("#define stracmp _ast_stracmp\n");
#endif
printf("#undef strcopy\n");
printf("#define strcopy _ast_strcopy\n");
printf("#undef strelapsed\n");
Expand All @@ -288,12 +305,16 @@ main(void)
printf("#define strhash _ast_strhash\n");
printf("#undef strkey\n");
printf("#define strkey _ast_strkey\n");
#if !_lib_strlcat
printf("#undef strlcat\n");
printf("#define strlcat _ast_strlcat\n");
printf("extern size_t strlcat(char*, const char*, size_t);\n");
#endif
#if !_lib_strlcpy
printf("#undef strlcpy\n");
printf("#define strlcpy _ast_strlcpy\n");
printf("extern size_t strlcpy(char*, const char*, size_t);\n");
#endif
printf("#undef strlook\n");
printf("#define strlook _ast_strlook\n");
printf("#undef strmatch\n");
Expand All @@ -304,8 +325,10 @@ main(void)
printf("#define strmode _ast_strmode\n");
#endif
#if _map_libc
#if !_lib_strnacmp
printf("#undef strnacmp\n");
printf("#define strnacmp _ast_strnacmp\n");
#endif
printf("#undef strncopy\n");
printf("#define strncopy _ast_strncopy\n");
printf("#undef strntod\n");
Expand Down Expand Up @@ -365,8 +388,10 @@ main(void)
printf("#define wordexp _ast_wordexp\n");
printf("#undef wordfree\n");
printf("#define wordfree _ast_wordfree\n");
#if !_lib_unsetenv
printf("#undef unsetenv\n");
printf("#define unsetenv _ast_unsetenv\n");
#endif
#endif
/* we always use the libast strdup implementation */
printf("#undef strdup\n");
Expand Down Expand Up @@ -472,11 +497,9 @@ main(void)
do
{
for (s = t; *t && *t != ' '; t++);
printf("#define %-.*s _ast_%-.*s\n", t - s, s, t - s, s);
printf("#define %-.*s _ast_%-.*s\n", (int)(t - s), s, (int)(t - s), s);
} while (*t++);
}
#endif
printf("\n");
printf("#undef extern\n");
return 0;
}
2 changes: 1 addition & 1 deletion src/lib/libast/man/strperm.3
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ not 0 then
is set to point to the first unrecognized character in
.IR s .
.PP
A tape device specification is composed of one or more
A file permission expression is composed of one or more
.I who-op-permission
terms separated by
.BR , .
Expand Down

0 comments on commit 4c39a97

Please sign in to comment.