Advertisement
illwieckz

macos compiler fix

Mar 29th, 2024 (edited)
1,329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.56 KB | None | 0 0
  1. diff --git a/libs/uniquenames.h b/libs/uniquenames.h
  2. index 9f89ba455..cd327a7cf 100644
  3. --- a/libs/uniquenames.h
  4. +++ b/libs/uniquenames.h
  5. @@ -106,14 +106,46 @@ inline void name_write( char* buffer, name_t name ){
  6.  
  7.  inline name_t name_read( const char* name ){
  8.     const char* end = name + strlen( name );
  9. +
  10. +#if GDEF_OS_MACOS
  11. +   /* HACK: Apple shipped a clang built for macOS with an optimization enabled
  12. +   that is not available on macOS. This error may then be faced:
  13. +
  14. +     ld: Undefined symbols:
  15. +       _memrchr, referenced from:
  16. +           name_read(char const*) in map.cpp.o
  17. +           name_read(char const*) in map.cpp.o
  18. +
  19. +   This is a compiler error:
  20. +
  21. +   > On Mac OSX (macOS version 12.4, sdk version 12.1) llvm can replace call
  22. +   > to strrchr() with call to memrchr() when string length is known at
  23. +   > compile time. This results in link error, because memrchr is not present
  24. +   > in libSystem.
  25. +   > -- https://github.com/llvm/llvm-project/issues/62254
  26. +
  27. +   We workaround this by making the string length not known at build time
  28. +   to avoid triggering the unavailable optimization. */
  29. +
  30. +   char *numbers;
  31. +   numbers = (char*) malloc( 11 * sizeof( char ) );
  32. +   strcpy( numbers, "1234567890" );
  33. +#else
  34. +   const char *numbers = "1234567890";
  35. +#endif
  36. +
  37.     for ( const char* p = end; end != name; --p )
  38.     {
  39. -       if ( strrchr( "1234567890", *p ) == NULL ) {
  40. +       if ( strrchr( numbers, *p ) == NULL ) {
  41.             break;
  42.         }
  43.         end = p;
  44.     }
  45.  
  46. +#if GDEF_OS_MACOS
  47. +   free( numbers );
  48. +#endif
  49. +
  50.     return name_t( CopiedString( StringRange( name, end ) ), Postfix( end ) );
  51.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement