diff --git a/src/lib/libast/comp/getopt.c b/src/lib/libast/comp/getopt.c index 586947217..01a05202e 100644 --- a/src/lib/libast/comp/getopt.c +++ b/src/lib/libast/comp/getopt.c @@ -43,8 +43,12 @@ char* optarg = 0; static int lastoptind; +/* + * Avoid a null-test optimization bug caused by glibc's headers + * by naming this function '_ast_getopt' instead of 'getopt'. + */ extern int -getopt(int argc, char* const* argv, const char* optstring) +_ast_getopt(int argc, char* const* argv, const char* optstring) { int n; diff --git a/src/lib/libast/features/map.c b/src/lib/libast/features/map.c index 3d9e74c63..660d4d5cb 100644 --- a/src/lib/libast/features/map.c +++ b/src/lib/libast/features/map.c @@ -113,9 +113,12 @@ main() #endif printf("#undef getdate\n"); printf("#define getdate _ast_getdate\n"); -#if _lib_getopt || _lib_getsubopt || _lib_getopt_long || _lib_getopt_long_only +#endif + /* libast always provides its own getopt implementation */ printf("#undef getopt\n"); printf("#define getopt _ast_getopt\n"); +#if _map_libc +#if _lib_getopt || _lib_getsubopt || _lib_getopt_long || _lib_getopt_long_only printf("#undef getsubopt\n"); printf("#define getsubopt _ast_getsubopt\n"); printf("#undef getopt_long\n"); @@ -447,9 +450,6 @@ main() printf("#undef realloc\n"); printf("#define realloc _ast_realloc\n"); printf("extern void* realloc(void*, size_t);\n"); - printf("#undef strdup\n"); - printf("#define strdup _ast_strdup\n"); - printf("extern char* strdup(const char*);\n"); #if _lib_valloc printf("#undef valloc\n"); printf("#define valloc _ast_valloc\n"); @@ -457,6 +457,10 @@ main() #endif #endif #endif + /* we always use the libast strdup implementation */ + printf("#undef strdup\n"); + printf("#define strdup _ast_strdup\n"); + printf("extern char* strdup(const char*);\n"); /* * overriding strto*() is problematic to say the least diff --git a/src/lib/libast/string/strdup.c b/src/lib/libast/string/strdup.c index e2a8be5b6..7a17b45d2 100644 --- a/src/lib/libast/string/strdup.c +++ b/src/lib/libast/string/strdup.c @@ -51,19 +51,15 @@ __STDPP__directive pragma pp:nohide strdup #endif /* - * Work around a null-test optimization bug in GCC. + * Avoid a null-test optimization bug caused by glibc's headers + * by naming this function '_ast_strdup' instead of 'strdup'. * https://bugzilla.redhat.com/1221766 */ -#pragma GCC push_options -#pragma GCC optimize ("O0") - extern char* -strdup(register const char* s) +_ast_strdup(const char* s) { register char* t; register int n; return (s && (t = oldof(0, char, n = strlen(s) + 1, 0))) ? (char*)memcpy(t, s, n) : (char*)0; } - -#pragma GCC pop_options